Question

I have created an Ecore metamodel and generated an editor through EMF. To generate my output code I parse the resource set (XMI) when a diagram is created and then map these resources to my own Java classes. These Java classes are responsible for generating my output which is some javascript files based on few template files (.stg). Everything works fine but my question is where do technologies such as Xtend/Acceleo come in? Do I need any of them? I know that they are template based but since I have my own templates that are rendered through my Java classes why would I need to use Xtend for example? I am totally confused.

Thank you so much

Was it helpful?

Solution

Xtend is a general purpose language. You could call it a "better Java". This is especially true for templating, because Xtend has nice template expressions. So if you want your generator code to be more readable, you could replace some Java classes with Xtend classes. You don't need to rewrite everything, Xtend interoperates seamlessly with Java. Just rewrite the parts that benefit most from Xtend's rich language features.

OTHER TIPS

You are using the eclipse Enterprise Modelling Framework (EMF). This provides you with the ECore meta modell and can generate basic dialog based editors. Basically EMF brings your diagrams from the XMI file format to a standardized object model, similar to a DOM.

Probably you also use the Graphical Editor Framework (GEF) to visualize your diagrams. It takes your DOM and renders it to a graphical representation. Usually you can also modify the graphics using graphical user interface, which will then also change the contents of your DOM.

Parallel to the GEF there also exists a textual editor framework called xText. It brings your DOM to a textual representation. You can then use a text editor to change the textual representation. xText can parse this changed text and change the DOM accordingly. Additionally it generates a nice Eclipse editor with syntax high lightning, code folding, code completion and possibilities for extensions for custom code completion and refactoring.

xText can be augmented by XBase. XBase is a basic programming language that runs on the Java VM. You can then provide a mapping from your ECore artefacts to XBase concepts (e.g. which ECore object represents an if statement or a loop). XBase can then generate Java bytecode and hence convert your ECore model to runnable code.

XTend is a general purpose language. It is often used as a very advanced template engine to to convert your ECore model to text. In contrast to xText there is no way back to convert the generated text back to the ECore DOM. Of course you can use any template engine or even xText/xbase to generate your runnable code according to your needs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top