Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [acceleo] @main & invoking generated Java class
[acceleo] @main & invoking generated Java class [message #730588] Wed, 28 September 2011 16:41 Go to next message
Marc Missing name is currently offline Marc Missing nameFriend
Messages: 38
Registered: March 2011
Member
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 Smile
Re: [acceleo] @main & invoking generated Java class [message #730799 is a reply to message #730588] Thu, 29 September 2011 07:58 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
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 #730824 is a reply to message #730799] Thu, 29 September 2011 09:25 Go to previous messageGo to next message
Marc Missing name is currently offline Marc Missing nameFriend
Messages: 38
Registered: March 2011
Member
Ok, thanks for the details. Your proposed solution works great in my case.

Is this "feature" documented somewhere ?
Re: [acceleo] @main & invoking generated Java class [message #730854 is a reply to message #730824] Thu, 29 September 2011 11:31 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Marc,

Stéphane has provided a great number of links on http://www.eclipse.org/forums/index.php/mv/msg/242514/730031/#msg_730031 (shamelessly reusing his post Razz). The one that is best looked at is the Acceleo User Guide, it should contain a description of the template syntax and, in turn, of the guards.

Laurent Goubet
Obeo
Re: [acceleo] @main & invoking generated Java class [message #730964 is a reply to message #730854] Thu, 29 September 2011 15:52 Go to previous messageGo to next message
Marc Missing name is currently offline Marc Missing nameFriend
Messages: 38
Registered: March 2011
Member
Thanks ! I already know about the guard, as I'm using them. I was trying to see where the @main behavior was detailed, because obviously, I skipped this documentation Smile
Re: [acceleo] @main & invoking generated Java class [message #731172 is a reply to message #730964] Fri, 30 September 2011 07:44 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Marc,

The "@main" annotation is documented in the user guide too, in the "Main Modules in Acceleo" section Smile.

Laurent Goubet
Obeo
Re: [acceleo] @main & invoking generated Java class [message #731196 is a reply to message #731172] Fri, 30 September 2011 08:41 Go to previous messageGo to next message
Marc Missing name is currently offline Marc Missing nameFriend
Messages: 38
Registered: March 2011
Member
Laurent,

Thanks again for helping me Smile 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 Smile

Marc
Re: [acceleo] @main & invoking generated Java class [message #733606 is a reply to message #731196] Wed, 05 October 2011 08:12 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
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
Previous Topic:org.eclipse.xtend.typesystem.uml2 as plugin-depency
Next Topic:[acceleo 3] OclInvalid_Class while trying to read an attribute in the model
Goto Forum:
  


Current Time: Tue Oct 15 03:34:27 GMT 2024

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

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

Back to the top