[SOLVED] Creating if-then expression on the fly in the JvmModelInferrer [message #1692696] |
Fri, 17 April 2015 11:26 |
|
Dear all,
In my DSL, I have defined a statement that enables to execute a code (the body) if a condition (the guard) becomes true:
on MyType [guard] { body }
I want to use the JvmModelInferrer for creating the corresponding Java code.
I have currently coded the inferrer for generating the following Java code:
private boolean _event_handler_guard_MyType(MyType occurrence) {
return condition_in_java;
}
private void _event_handler_body_MyType(MyType occurrence) {
code_in_java;
}
public void _event_handler_MyType(MyType occurrence) {
if (_event_handler_guard_MyType(occurrence)) {
_event_handler_body_MyType(occurrence);
}
}
Since I have two XExpression instances, I decided to put each of them in a separater Java function. And, create the if-then statement in a third Java operation.
But, I would prefer to generate the Java code:
public void _event_handler_MyType(MyType occurrence) {
if (condition_in_java) {
code_in_java;
}
}
Since I have two XExpression instances (guard and body), I did not find a way to create the if-then statement (through the XbaseFactory) without changing the container of the two original XExpressions:
XIfExpression ifExpr = XbaseFactory.eINSTANCE.createXIfExpression();
ifExpr.setIf(guard);
ifExpr.setThen(body);
JvmOperation operation = this.typesFactory.createJvmOperation();
operation.setBody(ifExpr);
...
What could be a better way to create the if-then statement on the fly in the Jvm model inferrer?
[Updated on: Fri, 17 April 2015 14:02] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03065 seconds