I have a simple DSL that should generate async code for expressions (this is the simplest example I could come up with to illustrate my point). I just added to the scripting example an new async
statement:
grammar org.xtext.scripting.Scripting with org.eclipse.xtext.xbase.Xbase
generate scripting "http://www.xtext.org/scripting/Scripting"
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
Script returns xbase::XBlockExpression:
{Script}
(expressions+=XExpressionOrVarDeclaration ';'?)*;
XExpression returns xbase::XExpression:
super | Async
;
Async:
'async' expression=XExpression
;
The idea would be that the async
code is executed in another thread.
My question is, how can I generate code for the Async.expression
using the ScriptingJvmModelInferrer
?
In the simplest case I would just wrap the code from the Async.expression
like this?
AsyncRunner.exec(new Runnable() {
@Override
public void run() {
// the Async.expression would end up here
}
})
Where is the hook to do that?
If you extend Xbase you ususally don't apapt the JvmModelInferrer for Compilation but you extend
XbaseTypeComputer
andXbaseCompiler.doInternalToJavaStatement/internalToConvertedExpression
(depending on what you actually introduce)