[ACCELEO] wrong parameter value [message #1785552] |
Mon, 16 April 2018 14:51 |
Nicola Serreli Messages: 26 Registered: July 2009 |
Junior Member |
|
|
Hi,
sometimes, I find that the value of an acceleo template parameter is not the one I expected.
Here is an example:
[template public main(....)]
[''.test()/]
[/template]
[template public test(arg : String)]
[print(sub('abc'.a(2)), sub('cde'.a(3)))/]
[print(sub('abc'.a(2)), c())/]
[print(c(), sub('abc'.a(2)))/]
[/template]
[template public print(arg1 : String, arg2 : String)]
[file ('stdout', false, 'UTF-8')]
TEST ... [if (arg1.oclIsUndefined() or arg1='')]FAILED[/if]
arg1 [arg1/] [arg1.oclIsUndefined()/]
arg2 [arg2/] [arg2.oclIsUndefined()/]
[/file]
[/template]
[template public sub(arg : String)]([arg/])[/template]
[template public a(arg1 : String, index : Integer)][arg1 + ' - ' + index/][/template]
[query public c(any: OclAny) : String = '.ui' /]
The result is:
TEST ...
arg1 (abc - 2) false
arg2 (cde - 3) false
TEST ... FAILED
arg1 false
arg2 .ui false
TEST ...
arg1 .ui false
arg2 (abc - 2) false
Currently, I'm using acceleo 3.6.4.201605040614
Someone can help me to understand if I'm doing something wrong?
Bye,
Nicola
|
|
|
|
Re: [ACCELEO] wrong parameter value [message #1785558 is a reply to message #1785555] |
Mon, 16 April 2018 16:13 |
Nicola Serreli Messages: 26 Registered: July 2009 |
Junior Member |
|
|
Hi,
I tried to use java debugger to follow the acceleo execution.
For what I see, inside AcceleoEvaluationVisitor.prepareInvocation, it tries to prepare the list of all parameters needed to invoke a template.
If a parameter is computed during the preparation of the invocation, it has a name like temporaryInvocationVariable$0
In my test, the actual value of this variable is retrieved as "the last value computed for a variable with that name". All computed values are stored using a stack, to provide the correct value when the execution returns from a query/template (I think).
Unfortunately, sometimes, the correct value is not the last one but the second to last (or even elder).
I'm not sure, but it looks like, the computation of template/query inside a template invocation adds a new value to the "values stack", but forget to remove it.
Regards,
Nicola
|
|
|
Powered by
FUDForum. Page generated in 0.03605 seconds