Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [SOLVED] Creating if-then expression on the fly in the JvmModelInferrer
[SOLVED] Creating if-then expression on the fly in the JvmModelInferrer [message #1692696] Fri, 17 April 2015 11:26 Go to next message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
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

Re: Creating if-then expression on the fly in the JvmModelInferrer [message #1692741 is a reply to message #1692696] Fri, 17 April 2015 13:43 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
That's currently not possible but we have plans to allow that in the future.

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: Creating if-then expression on the fly in the JvmModelInferrer [message #1692747 is a reply to message #1692741] Fri, 17 April 2015 14:03 Go to previous message
Stéphane Galland is currently offline Stéphane GallandFriend
Messages: 123
Registered: July 2014
Location: Belfort, France
Senior Member
Thank you for the update.

All the best,
Stéphane.
Previous Topic:multiple decisions warning
Next Topic:customize error "Cannot use this in a static context"
Goto Forum:
  


Current Time: Thu Apr 25 21:57:30 GMT 2024

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

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

Back to the top