4

I have a transformation sequence of models that eventually outputs an EMF model, instance of some EMF Meta model (the meta model I defined myself).

I am looking for a good way to generate code from this. Of course, there is XPand, I used to use that for other projects, but I wonder if XText or XTend is a suitable alternative (since it's so actively developed).

In other words, I have an EMF model, don't need an editor for it (so don't need XText for THAT purpose), but I DO need to build a code generator. Could I use XText for only that part?

And would it be advisable over XPand or Acceleo?

Any advice would be great.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
Marten Sytema
  • 1,906
  • 3
  • 21
  • 29

2 Answers2

3

I try to do a fair comparison between the tools, but it is really hard.

Xtext has nothing to do with code generation - it is for creating editors and parsers.

Xtend2 is designed as a successor of Xpand with a similar syntax - however, it is not tailored specifically to code generation but as a general purpose language that is nicely usable for code generation as well. The main difference between other generation engines is that you work on the source code level (basically, Xtend2 translates to Java), and you have to provide your own engine that drives the generation - although of course it is possible to use Modeling Workflow Engine for this reason - just as in case of Xpand.

Acceleo is more tailored for simple code generation. It's syntax is based on an OMG specification for code generation, and provides a full-featured IDE for developing code generation. However, if you need complex control structure during code generation, it might be not the best solution.

About M2T-JET, as Chris suggested, I would vote against, except for very specific needs. It's development support is much weaker (e.g. it's editor), and is more based on the idea of having a single template for output opposed to a higher level, rule based approach of Xpand/Xtend/Acceleo. This results in somewhat better performance during code generation, however, it often results in harder to understand templates. Ignore this paragraph because it is too negative.

Alltogether, if you are using only EMF models, both Acceleo and Xtend can be a nice choice for code generation, and you should choose between them based on your (or your teams) expertise and your more specific needs. If you need to support both EMF models and other data sources, then Acceleo is not the best choice; however, neither JET nor Xtend builds on the fact that your input is an EMF model, but provides easy way to call any Java code available.

Zoltán Ujhelyi
  • 13,788
  • 2
  • 32
  • 37
  • Ok, you are right - I am sorry. I did not want to be that negative about JET. Its capabilities are there, it only feels for me more cumbersome to use. I marked that paragraph as removed. – Zoltán Ujhelyi Sep 06 '12 at 08:15
  • will try xtend, as sven efftinge also just suggested to me on Twitter. I know i need to do some work to get the model as an input, but in the grand scheme of things, this probably is not a lot of work. I read somewhere that XTend executes much faster than XPand as well – Marten Sytema Sep 06 '12 at 08:28
  • @ChrisGerken I used Acceleo for generating Swing editors (and even CRUDS), ESB mediation, and Spring/JPA/Flex apps. The fact that JET is more complicated than Acceleo/XTend does not conflict with the fact that JET is as complete as possible. – Tcharl Aug 27 '14 at 15:02
-1

I recommend M2T-JET. It's a text template based transform that uses multiple templates to generate projects, folders and files from a single input model. The model can be EMF and the templates let you navigate through and iterate over the model to produce the Eclipse resources you have in mind.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
  • That just proves you don't understand JET. Please don't comment on technologies you don't understand, especially when you have such an obvious bias. – Chris Gerken Aug 27 '14 at 15:14