Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Manipulating / Creating XExpressions before code generation
Manipulating / Creating XExpressions before code generation [message #1693866] Tue, 28 April 2015 22:35 Go to next message
Dominik W. is currently offline Dominik W.Friend
Messages: 2
Registered: April 2015
Junior Member
Hi,

I am working on a language that includes the definition of conditions on Java classes with Xbase. One feature I am particularly interested in and on which I am currently stumped is the manipulation / creation of XExpressions during the building of the user input.

Here's a concrete (minimal) example for what I am trying to accomplish (note that the focus of this question is not which code should be created for which kind of XExpression or the like, but only how to implement this in Xtext).

Xtext grammar:
Model: block=XBlockExpression;


User input:
{ parameter.name == "ABC" }


Generated Java code:
class Result {
  public static boolean checkCondition(ClassWithName parameter) {
    return (parameter.getName().equals("ABC"));
  }

  public static void ensureCondition(ClassWithName parameter) {
    parameter.setName("ABC");
  }
}


The class and the first method (checkCondition) are of course very easy to generate with the appropriate JvmModelInferrer. For the second method (ensureCondition), I would have to:

  1. visit the XExpression tree and decide which new expressions to generate (for the ensureCondition method) (as XExpressions or as Java/Xbase code).
  2. parse/link the resulting code resp. XExpressions.
  3. include them in the inferred JVM class model (in a separate method).

The problem is now: when the JVMModelnferrer is called, the linking is of course not done yet (and can not possibly be, since the Xbase code can reference parameters defined during the model inference). Therefore I don't have enough information (types, called methods/features; also: unresolved proxies) about the code to decide which additional XExpressions/code to create. Is there a way to get the needed information here?

Would you recommend creating code or using the XbaseFactory.eINSTANCE.create... to build an XExpression-tree? When would be an appropriate phase/class to do that?
I'm considering the XbaseCompiler or the JvmModelGenerator (use linked XExpressions, create Java code programmatically and change the inferred model). Can I create methods/classes in the JvmModelGenerator similarily to creating them in the JvmModelInferrer?
Another (admittedly dirty) way of achieving what I need would be to use the parsed and linked XExpressions to create a new DSL file (programatically) which includes the manipulated statements (as text) and to feedback the resulting input into the building process (i.e. calling the whole process two times), but that seems like a really unstable dirty apporach.

Regards,
Dominik
Re: Manipulating / Creating XExpressions before code generation [message #1694125 is a reply to message #1693866] Thu, 30 April 2015 18:00 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Dominik,

it's not entirely clear to me from what information you derived the second method and its body, but I would go with a hybrid solution:
1) derive the methods signature in the model inferrer
2) generate its body in the JvmModelGenerator

You can assign a lambda as a body in the model inferrer, which will only be evaluated later during code generation. I.e. the types will be resolved by then.

hth,
sven

Re: Manipulating / Creating XExpressions before code generation [message #1694249 is a reply to message #1694125] Sun, 03 May 2015 19:24 Go to previous message
Dominik W. is currently offline Dominik W.Friend
Messages: 2
Registered: April 2015
Junior Member
Hi Sven,

thanks for the reply, we will definitely try that. The information that we want to use is the parsed and linked XExpression structure (including the information about which methods from which JVM types are called).
In the example we want to find all calls to .equals and getters and try to find appropriate setter methods. This will only work for a very small set of expressions but that is enough for our first approach.

Regards and thank you very much,
Dominik
Previous Topic:Xtext Formatting
Next Topic:edit Teneo-saved EMF Model in XText editor in RCP
Goto Forum:
  


Current Time: Fri Apr 23 03:07:12 GMT 2021

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

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

Back to the top