[Acceleo] protected bloc [message #507603] |
Thu, 14 January 2010 03:11 |
Andre Messages: 29 Registered: November 2009 Location: Brazil |
Junior Member |
|
|
Hi
I've wrote the code below on Acceleo to generate a Java operation:
[if (o.name.strcmp(n)<>0)]
[if (o.return.oclIsUndefined())]
public void [o.name/]([writeParameters(o)/]) [writeExceptions(o)/]{
[else]
public [o.return.name/][if (o.returnArray)]['[]'/][/if] [o.name/]([writeParameters(o)/]) [writeExceptions(o)/]{
[/if]
// [protected ('usercode')]
// [/protected]
}
[/if]
The problem is that when i edit the code between the protected block on the generated java file, this code is erased after a regeneration.
Is this protected block correct?
thanks,
Andre Silva
Natal-RN
Brazil
|
|
|
Re: [Acceleo] protected bloc [message #507658 is a reply to message #507603] |
Thu, 14 January 2010 09:49 |
|
This is a multi-part message in MIME format.
--------------080509070506020608050006
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Andre,
Your protected block seems fine to me. You're sure your editing
_between_ the protected markers in the generated text?
for example :
----------8<----------
some text here
// [protected ('marquee')]
This can be edited at will
// [/protected]
and some text by there
---------->8----------
will generate a file containing
----------8<----------
some text here
// Start of user code marquee
This can be edited at will
// End of user code
and some text by there
---------->8----------
In there, you mustn't edit the two lines containing comments (start and
end of user code) as they are our references to find the text to merge.
Yet you can alter the line in-between, "This can be edited at will" and
add as many new lines as you want in there, so long that you leave the
"end of user code" marker untouched.
Is that how you're working?
Laurent Goubet
Obeo
Andre wrote:
> Hi
>
> I've wrote the code below on Acceleo to generate a Java operation:
>
> [if (o.name.strcmp(n)<>0)]
> [if (o.return.oclIsUndefined())]
> public void [o.name/]([writeParameters(o)/]) [writeExceptions(o)/]{
> [else]
> public [o.return.name/][if (o.returnArray)]['[]'/][/if]
> [o.name/]([writeParameters(o)/]) [writeExceptions(o)/]{
> [/if]
> // [protected ('usercode')]
>
> // [/protected]
> }
> [/if]
>
> The problem is that when i edit the code between the protected block on
> the generated java file, this code is erased after a regeneration.
>
> Is this protected block correct?
>
> thanks,
>
--------------080509070506020608050006
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"
YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------080509070506020608050006--
|
|
|
|
Re: [Acceleo] protected bloc [message #507939 is a reply to message #507805] |
Fri, 15 January 2010 09:17 |
|
This is a multi-part message in MIME format.
--------------090100020607040901070808
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Andre,
Protected area markers must be unique in a given file. You cannot use a
static String as marker in a for loop as that would mean multiple
protected areas with the same marker.
Change the markers to include a variable bit and make them unique, and
the text you manually inserted between two generation should be
protected as required.
Something like
----------8<----------
// [protected ('operationCode'.concat(o.name))]
// [/protected]
---------->8----------
should do the trick.
Laurent Goubet
Obeo
Andre wrote:
> Hi Laurent
>
> I call these two templates on the same file bloc, each containing a
> protected block:
>
> Operation generation:
> [template public writeOperation(o: Operation, n: String)]
> [if (o.name.strcmp(n)<>0)]
> [if (o.return.oclIsUndefined())]
> public void [o.name/]([writeParameters(o)/]) [writeExceptions(o)/]{
> [else]
> public [o.return.name/][if (o.returnArray)]['[]'/][/if]
> [o.name/]([writeParameters(o)/]) [writeExceptions(o)/]{
> [/if]
> // [protected ('operationCode')]
>
> // [/protected]
> }
> [/if]
> [/template]
>
> Constructor generation:
> [template writeConstructors(m: MetaComponent)]
> [for (o : Operation | m.operations)]
> [if (o.name.strcmp(m.name)=0)]
> public [o.name/]([writeParameters(o)/]) [writeExceptions(o)/]{
> [for (p : Parameter | o.parameters)]
> this.[p.name/] = [p.name/]; [/for]
> // [protected ('constructorCode')]
>
> // [/protected]
> }
> [/if][/for]
> [/template]
>
> When i generate the java file, one of the generated operations is this:
> public boolean setMetadata(String metadata) {
> // Start of user code operationCode
>
> // End of user code
> }
>
> This operation has an error because it is not returning a value, so i
> alter it including a 'return false' statement:
> public boolean setMetadata(String metadata) {
> // Start of user code operationCode
> return false;
> // End of user code
> }
>
> The error dissapear, but when i execute the .mlt file again, the 'return
> false' is erased:
> public boolean setMetadata(String metadata) {
> // Start of user code operationCode
>
> // End of user code
> }
>
> What am i doing wrong?
>
> thanks
>
--------------090100020607040901070808
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"
YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------090100020607040901070808--
|
|
|
|
Re: [Acceleo] protected bloc [message #507996 is a reply to message #507989] |
Fri, 15 January 2010 13:22 |
|
This is a multi-part message in MIME format.
--------------030502090508090009090804
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Hi Andre,
Glad to know this now works as expected.
If you are referring to "chains" as in "the old Acceleo's .chain files"
then no, we have no substitute. Launching generations is now done
through launching a Java class, launching the generation of more than
one template is done through modifying this Java class to suit your needs.
Laurent Goubet
Obeo
Andre wrote:
> Laurent
>
> It's working now. Thanks once again. My template now is:
> [template writeConstructors(m: MetaComponent)]
> [for (o : Operation | m.operations)]
> [if (o.name.strcmp(m.name)=0)]
> public [o.name/]([writeParameters(o)/]) [writeExceptions(o)/]{
> [for (p : Parameter | o.parameters)]
> this.[p.name/] = [p.name/]; [/for]
> // [protected
> ('constructorCode.'.concat(o.name).concat('.').concat(writeP arametersTypes(o)))]
>
>
> // [/protected]
> }
> [/if][/for]
> [/template]
>
> Another question: is there any substitute for the execution chains on
> the 'new' acceleo?
--------------030502090508090009090804
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"
YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------030502090508090009090804--
|
|
|
Powered by
FUDForum. Page generated in 0.03958 seconds