vendredi 25 juin 2010

How to create an Acceleo 2.x generator for composed metamodels

Imagine you have a metamodel that reference other metamodels and you want to create a generator for this metamodel. Let's take an example :

The first metamodel contains an EClass named Object that have a reference package of type EPackage. That create a reference to the ECore metamodel.

First we have to create a template for the first metamodel :

<%
metamodel http://www.obeo.fr/first

import manymetamodels.ecore
%>

<%script type="first.Object" name="default" file="test.txt"%>
Object <%name%> :

<%package.default%>

Then we need to create the template manymetamodels.ecore.mt :

<%
metamodel http://www.eclipse.org/emf/2002/Ecore
%>

<%script type="ecore.EPackage" name="default"%>
EPackage <%name%>.


And that's all. So you just need to create at least one template per metamodel and then inport them according to the way you navigate your metamodels.