[Acceleo 3.1.2][resolved] Custom code lost in some protected area [message #758166] |
Tue, 22 November 2011 08:37 |
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 14:12] Report message to a moderator
|
|
|
|
Re: [Acceleo 3.1.2] Custom code lost in some protected area [message #758430 is a reply to message #758413] |
Wed, 23 November 2011 09:31 |
|
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 #758673 is a reply to message #758511] |
Thu, 24 November 2011 08:07 |
|
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 . 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 .
Laurent Goubet
Obeo
|
|
|
Powered by
FUDForum. Page generated in 0.03576 seconds