Manipulating / Creating XExpressions before code generation [message #1693866] |
Tue, 28 April 2015 22:35 |
Dominik W. 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:
- visit the XExpression tree and decide which new expressions to generate (for the ensureCondition method) (as XExpressions or as Java/Xbase code).
- parse/link the resulting code resp. XExpressions.
- 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03051 seconds