Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] How to create a generator for composed metamodels
[Acceleo] How to create a generator for composed metamodels [message #661383] Thu, 24 March 2011 13:38 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
I defined two metamodels in my project: one very basic metamodel which defines the "Type" EClass and another metamodel which is referencing this Type at several places.

So, my model will then contain elements from both metamodels, and my generator should access both metamodels too.

I created a mtl file for each metamodel and I call the "Type template" in my other template this way:

[generateTypeName(p.type)]


generateTypeName is a template defined in my other mtl file.

Unfortunately, this doesn't work since there is an error in the mtl editor saying:

Quote:
illegal operation signature: (generateTypeName(null))


So, my Type is not recognized here (instead of it, it is considered to be null). Of course, I imported my Type template:

[import generateTypes /]


I found an article that might perhaps fix my problem here: http://metaplop.blogspot.com/2010/06/how-to-create-acceleo-2 x-generator-for.html but there is a problem with the images and the explanations alone are not enough to understand what they are doing.
Re: [Acceleo] How to create a generator for composed metamodels [message #661403 is a reply to message #661383] Thu, 24 March 2011 14:36 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi Cedric,

First of all, the page that you are linking is about Acceleo 2. Acceleo 2 and Acceleo 3 do not share the same syntax and are thus incompatible.

Now for your problem, here is an example of a very simple Acceleo module with 2 metamodels GenModel.ecore and Ecore.ecore and GenModel.ecore is referencing elements from Ecore.ecore. You can create an Acceleo module with 1..n metamodels. The new wizards for Acceleo 3.1, that you can see here will make this more visible.

https://lh4.googleusercontent.com/_R0aPxLxg16E/TYtUw4gFYeI/AAAAAAAAAMc/c814BiEZttE/Multiple%20Metamodels.png

If you need more information, you can find a lot of material about Acceleo in the different websites mentioned in my signature.


Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Acceleo wiki: http://wiki.eclipse.org/Acceleo
Blogs: http://stephanebegaudeau.tumblr.com & http://sbegaudeau.tumblr.com
Re: [Acceleo] How to create a generator for composed metamodels [message #661426 is a reply to message #661403] Thu, 24 March 2011 15:54 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Thanks for your answer, however this doesn't seem to fix my problem.

I'll explain my problem on a very simple example. Suppose that you have a Type metamodel which looks like:

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="types"
    nsURI="http://types/1.0" nsPrefix="types">
  <eClassifiers xsi:type="ecore:EClass" name="Type">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="TypeManager">
    <eStructuralFeatures xsi:type="ecore:EReference" name="types" upperBound="-1"
        eType="#//Type" containment="true"/>
  </eClassifiers>
</ecore:EPackage>


And then the metamodel that uses it:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="orodsl"
    nsURI="http://org.orocos.dsl/1.0" nsPrefix="orodsl">
  <eClassifiers xsi:type="ecore:EClass" name="TaskContext">
    <eStructuralFeatures xsi:type="ecore:EReference" name="ports" upperBound="-1"
        eType="#//DataPort" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>

  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="DataPort">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="type" lowerBound="1" eType="ecore:EClass Types.ecore#//Type"/>
  </eClassifiers>
</ecore:EPackage>


So basically, we have a list of types contained in a TypeManager, and in our second model we have a TaskContext which contains DataPort of a certain Type (so, it is referencing the Type defined in the other metamodel).

For my code generation, I would like to write something like this:

[template public generate(arg : TaskContext)]
	
	[comment @main /]
	[file (arg.name + '.hpp', false, 'UTF-8')]
#include <rtt/Ports.hpp>
using namespace RTT;

class [arg.name/]
  : public TaskContext
{
  [for (p : DataPort | arg.ports)]
	  [genCppPortType(p)/]<[p.type.name/]> [p.name/];
  [/for]
...
...
...


Unfortunately, the editor flags an error at "p.type.name" saying "Unrecognizable variable: (name)". The code assist that pops-up when typing "p." shows that "type" is of type null.

I added the URIs of my two metamodels at the top of the template file.
Re: [Acceleo] How to create a generator for composed metamodels [message #661837 is a reply to message #661383] Mon, 28 March 2011 08:01 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi Cedric,

I have tested your metamodels with the example that you have provided and there indeed seems to have a bug here. The problem seems to appear only with dynamic metamodels (when the metamodel is in the workspace), you can deploy your metamodel as an Eclipse plugin in your development environment to prevent this problem from happening again.

I'll look into this problem to see where it is coming from but I believe that when the metamodel is in the workspace, we only take into account one resource and if you realize a Ctrl+click on one Type declared in orodsl.ecore, you would see that the second resource is not loaded and it creates a problem even for EMF.

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Acceleo wiki: http://wiki.eclipse.org/Acceleo
Blogs: http://stephanebegaudeau.tumblr.com & http://sbegaudeau.tumblr.com
Re: [Acceleo] How to create a generator for composed metamodels [message #661849 is a reply to message #661383] Mon, 28 March 2011 09:19 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Cedric,

I have looked into this problem a bit more and it appears that changing this:
- <eStructuralFeatures xsi:type="ecore:EReference" name="type" lowerBound="1" eType="ecore:EClass Types.ecore#//Type"/>

for that:
- <eStructuralFeatures xsi:type="ecore:EReference" name="type" lowerBound="1" eType="ecore:EClass /org.eclipse.acceleo.module.sample/model/Types.ecore#//Type"/ >

Solved the problem for me with dynamic metamodels. The problem is not coming from the way we are handling multiple metamodels in the workspace but the proxies cannot be resolved with a purely relative uri like "Type.ecore" while there are no problem with a workspace relative uri like "/org.eclipse.acceleo.module.sample/model/Type.ecore". I don't know why EMF shows a workspace relative uri in the sample ecore editor but serialize another uri in the file. I think that we can handle this with an uri converter, I'll keep you in touch.

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Acceleo wiki: http://wiki.eclipse.org/Acceleo
Blogs: http://stephanebegaudeau.tumblr.com & http://sbegaudeau.tumblr.com
Re: [Acceleo] How to create a generator for composed metamodels [message #661877 is a reply to message #661383] Mon, 28 March 2011 11:49 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Cedric,

So I've looked for a solution based on an uri converter but it won't be possible to use it since we don't have a resource set at the place which this problem appears. So for the moment, you would have two solutions:
1- deploy your metamodel
2- fix the uri to have a workspace relative uri

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Acceleo wiki: http://wiki.eclipse.org/Acceleo
Blogs: http://stephanebegaudeau.tumblr.com & http://sbegaudeau.tumblr.com
Re: [Acceleo] How to create a generator for composed metamodels [message #662303 is a reply to message #661383] Wed, 30 March 2011 08:08 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Stephane,

Thanks for your answer. Indeed, if I make the modification in my ecore model, then I don't have any errors in my generate.mtl file anymore.
However, this still doesn't seem to work fine at code generation. I test my bundle by launching a separate eclipse application (with all my workspace bundles), an there I create a new Types model and a new "OroDSL" model. Everything works fine, I can import my types model into my OroDSL model and reference existing types.

When I try to generate the code, I end up with something like this for the "port" features:
ReadDataPort<org.eclipse.emf.ecore.impl.DynamicEObjectImpl@439b01 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@7581aa (name: OclInvalid_Class) (instanceClassName: null) (abstract: false, interface: false))> MyDataPortA; 


(the part in error is inside < >). Furthermore, an exception is thrown in the console of my development Eclipse instance:
!ENTRY org.eclipse.ocl 4 10 2011-03-30 09:59:37.797
!MESSAGE Evaluation failed with an exception: (no message)
!STACK 0
java.lang.IllegalArgumentException
	at org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.navigateProperty(EcoreEvaluationEnvironment.java:226)
	at org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.navigateProperty(EcoreEvaluationEnvironment.java:1)
	at org.eclipse.ocl.EvaluationVisitorImpl.visitPropertyCallExp(EvaluationVisitorImpl.java:1925)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitPropertyCallExp(AcceleoEvaluationVisitor.java:1009)
	at org.eclipse.ocl.ecore.impl.PropertyCallExpImpl.accept(PropertyCallExpImpl.java:238)
	at org.eclipse.ocl.AbstractEvaluationVisitor.visitExpression(AbstractEvaluationVisitor.java:247)
	at org.eclipse.ocl.EvaluationVisitorDecorator.visitExpression(EvaluationVisitorDecorator.java:156)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1517)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:912)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoForBlock(AcceleoEvaluationVisitor.java:423)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1480)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:912)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoFileBlock(AcceleoEvaluationVisitor.java:316)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1487)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:912)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitAcceleoTemplate(AcceleoEvaluationVisitor.java:781)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.switchExpression(AcceleoEvaluationVisitor.java:1467)
	at org.eclipse.acceleo.engine.internal.evaluation.AcceleoEvaluationVisitor.visitExpression(AcceleoEvaluationVisitor.java:912)
	at org.eclipse.ocl.internal.evaluation.QueryImpl.evaluate(QueryImpl.java:152)
	at org.eclipse.ocl.ecore.QueryImpl.evaluate(QueryImpl.java:62)
	at org.eclipse.acceleo.engine.generation.AcceleoEngine.doEvaluate(AcceleoEngine.java:267)
	at org.eclipse.acceleo.engine.generation.AcceleoEngine.evaluate(AcceleoEngine.java:131)
	at org.eclipse.acceleo.engine.service.AcceleoService.doGenerateTemplate(AcceleoService.java:544)
	at org.eclipse.acceleo.engine.service.AcceleoService.doGenerate(AcceleoService.java:380)
	at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.generate(AbstractAcceleoGenerator.java:120)
	at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.doGenerate(AbstractAcceleoGenerator.java:99)
	at org.orocos.dsl.acceleo.files.Generate.doGenerate(Generate.java:157)
	at org.orocos.dsl.acceleo.ui.common.GenerateAll.doGenerate(GenerateAll.java:89)
	at org.orocos.dsl.acceleo.ui.popupMenus.AcceleoGenerateAcceleoAction$1.run(AcceleoGenerateAcceleoAction.java:76)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Re: [Acceleo] How to create a generator for composed metamodels [message #663789 is a reply to message #661383] Wed, 06 April 2011 14:01 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi Cedric,

The Acceleo Engine is also affected by a problem with dependencies between dynamic metamodels. We will look into it. In the mean time, I think that the safest solution is to deploy your metamodels.


Stephane Begaudeau, Obeo
--
Twitter: @sbegaudeau
Acceleo wiki: http://wiki.eclipse.org/Acceleo
Blogs: http://stephanebegaudeau.tumblr.com & http://sbegaudeau.tumblr.com
Re: [Acceleo] How to create a generator for composed metamodels [message #665155 is a reply to message #661383] Wed, 13 April 2011 13:22 Go to previous message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Cedric,

I have fixed the bug for the dependencies between dynamic metamodels and it should be fine now. We also fixed the problem, that I was referring to, in the Acceleo engine. You can see a screenshot of the result here:

https://lh5.googleusercontent.com/_R0aPxLxg16E/TaWiybT6r0I/AAAAAAAAAPQ/3PVq38MefA4/s640/DynamicMetamodelDependencies.png

The fix will be available in Acceleo 3.1.0M7 next month.

Stephane Begaudeau, Obeo
--
Twitter: @sbegaudeau
Acceleo wiki: http://wiki.eclipse.org/Acceleo
Blogs: http://stephanebegaudeau.tumblr.com & http://sbegaudeau.tumblr.com
Previous Topic:[JET] How to load a java file with a fully qualified name?
Next Topic:[JET] Can JET read the binding information of a AST node?
Goto Forum:
  


Current Time: Thu Apr 18 15:34:46 GMT 2024

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

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

Back to the top