[acceleo] @main & invoking generated Java class [message #730588] |
Wed, 28 September 2011 16:41  |
Eclipse User |
|
|
|
I have a model that is a simple tree that describes a component tree (composite components can contain primitive components or other composite components, and so on).
My template should be applied to the top level component once.
But currently, when I call the java method ("generator.doGenerate(new BasicMonitor());"), giving the model element corresponding to the root of the tree, my template gets called for all nodes of the composite type in the tree, leading to bad generated code.
Is this the expected behavior ? If so, I guess the correct way to fix this is to wrap my tree inside a "packaging" model class and then apply my template to this unique wrapper.
But maybe this is a behavior that can be changed. I could not find documentation about the semantic of '@main' (I checked the acceleo doc for v3 and the MTL doc).
Any help very appreciated
|
|
|
Re: [acceleo] @main & invoking generated Java class [message #730799 is a reply to message #730588] |
Thu, 29 September 2011 07:58   |
Eclipse User |
|
|
|
Hi Marc,
If your tree's root type (let's call it "Component") is the same as its sub-nodes, and you define an Acceleo "template" with a parameter of type "Component", then this template will be called on each "Component" we can find. That is the normal behavior. That would give something like this :
[template generate(component : Component)]
[comment @main/]
However you can change your template so that it has a "guard" preventing it from being called on sub-nodes. Something like this :
[template generate(component : Component) ? (component.eContainer().oclIsUndefined())]
[comment @main/]
Laurent Goubet
Obeo
|
|
|
|
|
|
|
Re: [acceleo] @main & invoking generated Java class [message #731196 is a reply to message #731172] |
Fri, 30 September 2011 08:41   |
Eclipse User |
|
|
|
Laurent,
Thanks again for helping me The problem is that in this documentation (that I've read several times to see if I was misreading it in some way) I can't find the information saying "the main module will be applied to all objects of the type of the first parameter of the template". But again, maybe there's a sentence I simply don't understand as I should 
Marc
|
|
|
Re: [acceleo] @main & invoking generated Java class [message #733606 is a reply to message #731196] |
Wed, 05 October 2011 08:12  |
Eclipse User |
|
|
|
Marc,
This was indeed ill-explained in the documentation, we have added a proper documentation for the "main" behavior ... though the platform we're using is currently bugging. The page is located at http://www.obeonetwork.com/page/the-acceleo-main-modules ... If it still fails to load when you read this, here is the content of the part we've added there :
Quote:
Behavior
The main template will be called on all the elements of the model with the given type. The beginning of the execution of the main template initialized the generation. As such, if you have a main template defined on a UML Class, this template will be called for all your classes but it also mean that the generator will be initialized for each call to this main template so, for example, the cache of the queries will be cleared after each call. It is recommended to define the main module on the root of your metamodel and then to navigate manually in your model to call all the other templates. On a UML model, you would improve performances by defining your generator on the root concept Model instead of Class.
Laurent Goubet
Obeo
|
|
|
Powered by
FUDForum. Page generated in 0.04330 seconds