Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo 3.1.2][resolved] Custom code lost in some protected area(In certain circumstances, code inside protected area is systematically lost)
icon4.gif  [Acceleo 3.1.2][resolved] Custom code lost in some protected area [message #758166] Tue, 22 November 2011 03:37 Go to next message
Sébastien  atre is currently offline Sébastien atre
Messages: 4
Registered: November 2011
Junior Member
I've got into some trouble with protected area in Acceleo 3.1.2 in some circumstances.

The goal of this post is to confirm that I really run into an Acceleo bug before posting it to the bug tracker.

See the attached file protectedAreaInTemplateArgumentKo.mtl as I cannot output it there (the forum is saying that "You cannot use links until you have posted more than 5 messages.")

In this file, the main template calls another template having the file tag and this template is getting an input parameter containing a protected area.
The protected area contained in this parameter is correctly output to the file but any custom code contained in it will systematically be lost.
A .lost file is generated with lost custom code.

The example is provided in attachment and can be run with any model (does not use model information).

[Updated on: Wed, 23 November 2011 09:12]

Report message to a moderator

Re: [Acceleo 3.1.2] Custom code lost in some protected area [message #758413 is a reply to message #758166] Wed, 23 November 2011 02:54 Go to previous messageGo to next message
Sébastien  atre is currently offline Sébastien atre
Messages: 4
Registered: November 2011
Junior Member
Can anyone confirm that this is really a bug and not a bad use ?
Re: [Acceleo 3.1.2] Custom code lost in some protected area [message #758430 is a reply to message #758413] Wed, 23 November 2011 04:31 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
Hi Sebastien,

This is not a bug, rather a bad use... though this might not be obvious.

The protected area must be contained by a file block : in order to determine whether there is existing code in that particular area, we need to load the previous version of the file and check all "protected areas" markers. This is done internally when Acceleo enters the [file] block evaluation. These protected contents will then be retrieved whenever Acceleo enters the [protected] evaluation if possible.

In your case, the "protected" block is out of any "file" scope; thus we cannot match its ID to any existing one (what if you were to call this "protected" block twice for two different files?).

Basically, the calls to any [protected] block must be nested somewhere "under" a [file] block as the two are deeply tied. You will have to change the logic of your generators to cope with that.

Another option, if you are generating Java code, is to make use of "@generated" tags : those do not suffer from the same limitations as they are evaluated as a post-processing of the file generation and not on-the fly.

Laurent Goubet
Obeo
Re: [Acceleo 3.1.2] Custom code lost in some protected area [message #758511 is a reply to message #758430] Wed, 23 November 2011 09:09 Go to previous messageGo to next message
Sébastien  atre is currently offline Sébastien atre
Messages: 4
Registered: November 2011
Junior Member
Your answer is crystal clear !
It's quite sad but I understand the point of view.
(This particular use was there to centralize template code and avoid duplication.)

So I have changed my templates to put the file block at a top level and now it's working.

Thanks for your help !
Re: [Acceleo 3.1.2] Custom code lost in some protected area [message #758673 is a reply to message #758511] Thu, 24 November 2011 03:07 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1625
Registered: July 2009
Senior Member
Sebastien,

Quote:
This particular use was there to centralize template code and avoid duplication.


Yes, I can fully understand how (and why) you stumbled on this Razz. The issue at hand are the innards of Acceleo. We only evaluate "protected" areas once, when we enter the evaluation of the protected block. Once that is done all that remains is a plain String, and we won't check whether this String contains a protected area every time we need to write it on disk.

It would be too error-prone to try and have protected areas that would not be tied to a specific file. We don't want protected code from file A to find its way into file B only because the marker is the same Smile.

Laurent Goubet
Obeo
Previous Topic:[acceleo] debug java code in "Acceleo Plug-in Application"
Next Topic:[acceleo 3.2.X & Java & Maven] Tutorial for developpers [solved]
Goto Forum:
  


Current Time: Thu Aug 28 01:36:48 EDT 2014

Powered by FUDForum. Page generated in 0.35921 seconds