Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Generate equivalent Java statement from XBlockExpression using IGenerator(How to generate code for a function entered in my dsl using MyDslGenerator)
Generate equivalent Java statement from XBlockExpression using IGenerator [message #1070547] Thu, 18 July 2013 03:33 Go to next message
Priya Sabut is currently offline Priya Sabut
Messages: 41
Registered: September 2012
Member
Hi All,

I am new to Xtext. I am using Xtext to understand my dsl language and from the DSL entered I will be generating code(java) based on the input dsl entered.

In the same dsl along with my own customized language I am using functions to apply conditions on some elements, where function body is of XBlockExpression type.

Function:
{Function}
'function' name=QualifiedName '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')'
':' type = JvmTypeReference
body=XBlockExpression
;
I can get the java equivalent of the function using MyDslJvmModelInferrer.xtend, but whatever code I am generating is not a typical JavaBean type class where I have getters, setters etc, rather I have to write other different stuffs. For that I have to write textual content into the template.

For the above reason I am using MyDslGenerator.xtend to generate java file which supports textual file templating and I am successfully generation my code. But when I process my function I get the body as XEpression object and not finding a way get java equivalent of the function body inside my generator Sad .

Is there a way to extract the java equivalent from a XBlockExpression inside MyDslGenerator.xtend ?

Looking for your help.

Thanks in advance.
Re: Generate equivalent Java statement from XBlockExpression using IGenerator [message #1070571 is a reply to message #1070547] Thu, 18 July 2013 04:32 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander Nittka
Messages: 1149
Registered: July 2009
Senior Member
Hi,

how about injecting the XbaseCompiler and let it do the work.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Generate equivalent Java statement from XBlockExpression using IGenerator [message #1070576 is a reply to message #1070571] Thu, 18 July 2013 04:41 Go to previous messageGo to next message
Priya Sabut is currently offline Priya Sabut
Messages: 41
Registered: September 2012
Member
Hi Alex,
I did try that. I injected XbaseCompiler and I see there are two methods: toJavaStatement() and toJavaExpression but they need ITreeAppendable as argument. How can I construct that.

def compileFunction(Function funct)'''
«xbaseCompiler.toJavaExpression(funct.body, ITreeAppendable)»
'''

OR
def compileFunction(Function funct)'''
«xbaseCompiler.toJavaStatement(funct.body, ITreeAppendable, boolean isReferenced)»
'''
I am stuck at ITreeAppendable. How Can I construct a object of TreeAppendable ana pass it to the xbaseCompiler ?
Re: Generate equivalent Java statement from XBlockExpression using IGenerator [message #1070580 is a reply to message #1070576] Thu, 18 July 2013 04:49 Go to previous messageGo to next message
Priya Sabut is currently offline Priya Sabut
Messages: 41
Registered: September 2012
Member
Is there a different API that can get me equivalent java statements from XExpression ?

A code snippet will be helpful.
Re: Generate equivalent Java statement from XBlockExpression using IGenerator [message #1070730 is a reply to message #1070580] Thu, 18 July 2013 10:54 Go to previous messageGo to next message
Priya Sabut is currently offline Priya Sabut
Messages: 41
Registered: September 2012
Member
Any help please ?

Thanks in advance.
Priya

[Updated on: Thu, 18 July 2013 10:55]

Report message to a moderator

Re: Generate equivalent Java statement from XBlockExpression using IGenerator [message #1070731 is a reply to message #1070730] Thu, 18 July 2013 10:55 Go to previous messageGo to next message
Priya Sabut is currently offline Priya Sabut
Messages: 41
Registered: September 2012
Member
No Message Body
Re: Generate equivalent Java statement from XBlockExpression using IGenerator [message #1071169 is a reply to message #1070731] Fri, 19 July 2013 09:41 Go to previous message
Ian McDevitt is currently offline Ian McDevitt
Messages: 65
Registered: December 2012
Location: Belfast
Member
Don't construct one, I expect the code is already inside a closure with one, like the body assignment:

body = [ append('''Hello''') ]

is short for

body = [ it.append('''Hello''') ]

and 'it' is your ITreeAppendable.
Previous Topic:Error resolving Extension with xtext tycho build after 2.4 upgrade
Next Topic:Optimize code generation IO?
Goto Forum:
  


Current Time: Thu Apr 17 14:33:17 EDT 2014

Powered by FUDForum. Page generated in 0.01834 seconds