Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top