Appending string AND XEpression to body of method [message #1082449] |
Thu, 08 August 2013 15:22 |
Thomas Goossens Messages: 32 Registered: August 2013 |
Member |
|
|
I want to generate the body of a method.
val ofunctionMethod = function.toMethod(name, returntype) [
body = op.body //op comes from somewhere above and op.body is an XExpression
]
What I want to do is
generate a method with in its body:
1) some fixed code: "String example = 2"
2) op.body (XExpression)
I've looked at examples that create a CompilationStrategy
body = [it.append("String example = 2")]
But even when looking at the java files of this piece of code (eg: I know the code is expanded to Procedure1<ITreeIterator> etc>
I can't figure out how to append my XExpression to the body (if I first append the fixed code)
Any hints are appreciated
Update: Currently I'm looking at NodeModelUtils to convert my XExpression to a string
and then append it.
Update: Which is of course completely useless to my because it the code from the parse tree. (I need the compiled files (to java))
Update: I am thinking of using XBaseCompiler to compile my XExpression to a string and then append it
Cheers
[Updated on: Thu, 08 August 2013 15:46] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Appending string AND XEpression to body of method [message #1085082 is a reply to message #1084952] |
Mon, 12 August 2013 12:30 |
|
On 12/08/2013 10:53, Thomas Goossens wrote:
> It works great! I implemented my own extension to XBaseCompiler as you
> said and generated. I must say that I don't quite understand yet *why*
> it works..
>
>
> nevertheless thanks!
glad to know it works :)
from what I understand, with the new type system of 2.4 (which is rather
cool! :), the typing of expressions is dealt with by the framework when
you give an Xbase expression a logical container. That is why you must
do something like
body = o.body
in the inferrer.
If you don't do that, the Xbase expressions will not be typed.
So if you need to customize the compilation of Xbase expressions you
must provide a custom XbaseCompiler, and not manually use the
XbaseCompiler in a compilation strategy...
At least, that's how I understand it :)
cheers
Lorenzo
--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Powered by
FUDForum. Page generated in 0.03556 seconds