Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using a custom Xbase-compiler
Using a custom Xbase-compiler [message #1690298] Thu, 26 March 2015 12:35 Go to next message
Fenris Wolf is currently offline Fenris WolfFriend
Messages: 10
Registered: March 2015
Junior Member
Hy

How can i make my JVMModelInferrer (org.xtext.example.foobar.jvmmodelinferrer.FoobarJvmModelInferrer.xtend) use a different Xbase-compiler? My own compiler (org.xtext.example.foobar.helpers.MyXBaseCompiler.java) is just a subclass of XbaseCompiler, with some additional methods.

Is there a way to call the compiler explicitely, e.g. in my model-inferrer-code "new MyXbaseCompiler().toJavaExpression(expression)" or something like that?

Greetings,
Fenris

[Updated on: Thu, 26 March 2015 14:52]

Report message to a moderator

Re: Using a custom Xbase-compiler [message #1690303 is a reply to message #1690298] Thu, 26 March 2015 13:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
You usually dont do that. Simply subclass jvmmodelgenerator and hook into the method you want

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using a custom Xbase-compiler [message #1690374 is a reply to message #1690303] Fri, 27 March 2015 00:58 Go to previous messageGo to next message
Fenris Wolf is currently offline Fenris WolfFriend
Messages: 10
Registered: March 2015
Junior Member
That sounds like a good solution, but how to do that? Do i have to adjust the *StandaloneSetup.java or the *RuntimeModule.java?
Re: Using a custom Xbase-compiler [message #1690393 is a reply to message #1690374] Fri, 27 March 2015 06:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
Hi,

the guice for xbase is the same as for the rest. if you have a look at the XXXRuntimeModule that indirectly inherits from DefaultXbaseRuntimeModule.
there you can find

	public Class<? extends IGenerator> bindIGenerator() {
		return JvmModelGenerator.class;
	}


simply override this method

        @Override
	public Class<? extends IGenerator> bindIGenerator() {
		return YourJvmModelGenerator.class;
	}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using a custom Xbase-compiler [message #1690577 is a reply to message #1690393] Sun, 29 March 2015 10:01 Go to previous messageGo to next message
Fenris Wolf is currently offline Fenris WolfFriend
Messages: 10
Registered: March 2015
Junior Member
Hy again. The problem is related to what i've written here in the first paragraph.

For the approach with JvmModelGenerator: If i understand correctly, i'll need a mapping from XInputLiteral.java (generated by Xtext for my Rule XInputLiteral) to a Jvm*-object so that MyJvmModelGenerator.java (my generator) can handle it via its _toJavaLiteral-method or something similar. Is that correct? If yes: How to do that? If no: What is the way to go then?

[Updated on: Sun, 29 March 2015 10:02]

Report message to a moderator

Re: Using a custom Xbase-compiler [message #1690578 is a reply to message #1690577] Sun, 29 March 2015 10:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13885
Registered: July 2009
Senior Member
No,

simply add compile rules for XInputLiteral. hook into XbaseCompiler (subclassing) and add a else if into toJavaStatement / toJavaExpression + add a new binding for XbaseCompiler


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using a custom Xbase-compiler [message #1690594 is a reply to message #1690578] Sun, 29 March 2015 18:02 Go to previous message
Fenris Wolf is currently offline Fenris WolfFriend
Messages: 10
Registered: March 2015
Junior Member
Ah, i got it working now. Thanks!
For protocoll, here's what i did:

To the RuntimeModule-Code (e.g. FoobarRuntimeModule.java) i added the following lines:
public Class<? extends ITypeComputer> bindITypeComputer() {return MyXbaseTypeComputer.class;}
public Class<? extends XbaseCompiler> bindXbaseCompiler() {return MyXbaseCompiler.class;}


In my MyXbaseTypeComputer.java i provided a _computeTypes-implementation for my additional Literal and overrode computeTypes for XExpression (so that it uses my _computeTypes-method for my Literal and the superclass-implementation else).

In MyXbaseTypeComputer.java i had to override _toJavaExpression/_toJavaStatement for XExpression similarly (instead of toJavaExpression/toJavaStatement) and i had to check for the generated implementation of my Literal (i.e. MyLiteralImp instead of MyLiteral).

Thanks again,
Fenris
Previous Topic:Question about content assist
Next Topic:Chaining of code generators
Goto Forum:
  


Current Time: Mon Apr 19 01:05:47 GMT 2021

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

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

Back to the top