Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Maven code generation
Maven code generation [message #1814566] Fri, 13 September 2019 10:12 Go to next message
Heiko Tappe is currently offline Heiko TappeFriend
Messages: 18
Registered: March 2010
Junior Member
I still fail in generating code via maven. I don't need any Eclipse integration!
What I got so far is:
I've got a project with my grammar and it's generating a bunch of classes like all the model classes defined by my grammar and a few others.

Now I'd like to have another project defining a specific model using my grammar above and several templates used to generate files at different locations. This project should be executed (via maven only) to generate the code.

I already had a look at several examples but I still wasn't able yet to make it work.

Any help is appreciated

--Heiko
Re: Maven code generation [message #1814573 is a reply to message #1814566] Fri, 13 September 2019 12:01 Go to previous messageGo to next message
Heiko Tappe is currently offline Heiko TappeFriend
Messages: 18
Registered: March 2010
Junior Member
Some progress... I think managed to let the code generator generate a main class I can use in my source code generator project (though I'd prefer working with an mwe2 file).
But it still doesn't generate any files yet. But that is probably because there aren't any templates yet!? But where do I have to put these (xtend files) to be picked up?
I can find some examples where the templates reside in the generator class. But using the main class approach I don't have a generator class.

--Heiko
Re: Maven code generation [message #1814574 is a reply to message #1814573] Fri, 13 September 2019 12:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
In the Main you ususally have Access to a injector which you can ask for a igenerator or igenerator2

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Maven code generation [message #1814575 is a reply to message #1814574] Fri, 13 September 2019 12:37 Go to previous messageGo to next message
Heiko Tappe is currently offline Heiko TappeFriend
Messages: 18
Registered: March 2010
Junior Member
Sorry. I don't get that.

Ok, I could do something like that in the main method:

Injector injector = new TestLanguageStandaloneSetup().createInjectorAndDoEMFRegistration();
Main main = injector.getInstance(Main.class);
IGenerator2 generator = injector.getInstance(IGenerator2.class); // <==
main.runGenerator(emfResource);

And then? How would I use the generator to define the templates to use for the code generation?

--Heiko
Re: Maven code generation [message #1814585 is a reply to message #1814575] Fri, 13 September 2019 14:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I don't get this question
The generator implements the generation
You simply call doGenerate


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Maven code generation [message #1814638 is a reply to message #1814566] Sun, 15 September 2019 10:31 Go to previous messageGo to next message
Heiko Tappe is currently offline Heiko TappeFriend
Messages: 18
Registered: March 2010
Junior Member
The problem is not to start the generator but where to put the xtend templates to be used by the generator.
Probably a stupid question because it's so easy and obvious!? Sorry for that!

--Heiko
Re: Maven code generation [message #1814641 is a reply to message #1814638] Sun, 15 September 2019 12:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I don't understand. Have you had a look at the generator part in the tutorial. The templates go into the MyDslGenerator class

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Maven code generation [message #1814653 is a reply to message #1814641] Mon, 16 September 2019 07:12 Go to previous messageGo to next message
Heiko Tappe is currently offline Heiko TappeFriend
Messages: 18
Registered: March 2010
Junior Member
It works now. Thanks a lot!
But to be honest, I have no idea why it didn't work in the first place.
Maybe part of my confusion bases on the fact that the templates reside in the generator class which is part of the grammar project.
How can I (if possible) move the stuff to my code generation project? And how can I split the templates into separate files?
Re: Maven code generation [message #1814661 is a reply to message #1814653] Mon, 16 September 2019 07:54 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i would not recommend to first thing to beginners. for splitting you can use the same methods as you would do with java e.g. delegate to multiple injected instances

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Build in eclipse ok, failing via maven with NoSuchMethodError
Next Topic:Exporting DSL as Xtext feature has cross reference problems
Goto Forum:
  


Current Time: Thu Apr 25 09:29:35 GMT 2024

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

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

Back to the top