Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Can I modify a java file using XTend?
Can I modify a java file using XTend? [message #1778009] Thu, 07 December 2017 17:13 Go to next message
Mia G is currently offline Mia GFriend
Messages: 1
Registered: December 2017
Junior Member
I am trying to parse a DSL and modify an existing java file with the changes.

For e.g., The user can enter the following in the XText editor:

sum = a + b
file path = "C:\file1.java"


If the user enters "sum = a+b" in the DSL and mention the java filepath in the DSL as "C:\file1.java"; I want to modify the file1.java and add a code snippet like:

sum = a+b;
(here a,b and sum are already defined in the file1.java file).

Before:

public class file1 {
public static void main (String[] args){
int a =1, b =4, sum=0, product=0;
product = a*b;
System.out.println("Product is :"+product);
} }

After:

public class file1 {
public static void main (String[] args){
int a =1, b =4, sum=0, product=0;
product = a*b;
sum = a + b;
System.out.println("Product is :"+product);
} }

Is there a way to do it using XText/XTend or any other tool?
Re: Can I modify a java file using XTend? [message #1778191 is a reply to message #1778009] Mon, 11 December 2017 16:05 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Hi Mia,

for me it just looks like you want to add some text to an existing file?
But how do you want to specify where your additional lines should be placed into the file?

I think for textual replacements, there will be tools available which do not need a pretty complicate grammar.

Uli
Previous Topic:Best place to store a derived model and to make it referable from the DSL
Next Topic:Generating code automatically on the basis of Xtext grammar
Goto Forum:
  


Current Time: Thu Apr 25 18:55:43 GMT 2024

Powered by FUDForum. Page generated in 0.03037 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top