Home » Modeling » M2T (model-to-text transformation) » Template parameter altered by passing the result of a query
Template parameter altered by passing the result of a query [message #1737072] |
Tue, 05 July 2016 13:43 |
Elie Richa Messages: 72 Registered: February 2016 |
Member |
|
|
Hello,
I'm having a weird behavior in Acceleo 3.6.4.201605040614
The first parameter that I'm passing to a template is being modified by
the mere fact that I'm invoking a query to compute a second parameter.
Here's the reproducer.
[module main('http://www.eclipse.org/emf/2002/Ecore')]
[template public main(p : EPackage)]
[comment @main/]
[file (p.name + '.txt', false, 'UTF-8')]
[for (eOp : EOperation |
p.eClassifiers->selectByType(EClass).eOperations) separator('--\n')]
[eOp.genEOp(eOp.eContainingClass.eNamedElementQuery())/]
[/for]
[/file]
[/template]
[template public genEOp(eOp : EOperation, someParam : String)]
eOp is : [eOp/]
[if (not eOp.oclIsTypeOf(EOperation))]
huh?! eOp should have been an EOperation!
[/if]
someParam is: [someParam/]
[/template]
[query public eNamedElementQuery(el : ENamedElement) : String =
el.name /]
The resulting file is the following:
eOp is : org.eclipse.emf.ecore.impl.EClassImpl@25641d39 (name:
EClass1) (instanceClassName: null) (abstract: false, interface: false)
huh?! eOp should have been an EOperation!
someParam is: EClass1
Note how the first parameter which is supposed to be the EOperation, is
now an EClass somehow.
The problem disappears if I remove the query invocation and just read
the 'name' attribute. The result is this:
eOp is : org.eclipse.emf.ecore.impl.EOperationImpl@537f60bf (name:
EOp1) (ordered: true, unique: true, lowerBound: 0, upperBound: 1)
someParam is: EClass1
Another workaround was to store the result of the query invocation in a
local variable. When the variable is declared in a template this works,
however in my above reproducer, declaring the variable in the for-loop
as follows doesn't work:
[for (eOp : EOperation |
p.eClassifiers->selectByType(EClass).eOperations) separator('--\n') {
param : String = eOp.eContainingClass.eNamedElementQuery();
}
]
[eOp.genEOp(param)/]
[/for]
It gives the following exception at runtime:
org.eclipse.acceleo.engine.AcceleoEvaluationException: Undefined
argument eOp.eContainingClass of invocation at line 0 in Module main for
block eNamedElementQuery(eOp.eContainingClass). Last recorded value of
self was org.eclipse.emf.ecore.impl.EPackageImpl@4686afc2 (name: pkg)
(nsURI: null, nsPrefix: null). Problem found while generating the file
'/Users/richa/work/workspace-qgen/org.eclipse.acceleo.test.econtainingclass/out/pkg.txt'.
at main.main(EPackage)(main.mtl:0)
at main.main(EPackage)(main.mtl:8)
at main.main(EPackage)(main.mtl:7)
at main.main(EPackage)(main.mtl:5)
And the generated file is:
eOp is : org.eclipse.emf.ecore.impl.EOperationImpl@1a942c18 (name:
EOp1) (ordered: true, unique: true, lowerBound: 0, upperBound: 1)
someParam is:
Any idea what's going on?
Regards,
Elie Richa
Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
|
|
| |
Re: Template parameter altered by passing the result of a query [message #1737259 is a reply to message #1737172] |
Wed, 06 July 2016 16:47 |
Elie Richa Messages: 72 Registered: February 2016 |
Member |
|
|
Hi Laurent,
Thank you for your reply.
On 06/07/16 10:35, Laurent Goubet wrote:
> Hi,
>
> We've had weird behavior (scope fallthrough) for variables named the
> same as query parameters, but the case you describe here seems new to
> me. For now, could you try renaming one of your two "eOP" variables to
> something else to see if it works around the issue?
Renaming the variables did not solve the issue. In the following they
are called eOp1 and eOp2:
[template public main(p : EPackage)]
[comment @main/]
[file (p.name + '.txt', false, 'UTF-8')]
[for (eOp1 : EOperation |
p.eClassifiers->selectByType(EClass).eOperations) separator('--\n')]
[eOp1.genEOp(eOp1.eContainingClass.eNamedElementQuery())/]
[/for]
[/file]
[/template]
[template public genEOp(eOp2 : EOperation, someParam : String)]
eOp2 is : [eOp2/]
[if (not eOp2.oclIsTypeOf(EOperation))]
huh?! eOp2 should have been an EOperation!
[/if]
someParam is: [someParam/]
[/template]
[query public eNamedElementQuery(el : ENamedElement) : String =
el.name /]
and I still get the same erroneous output:
eOp2 is : org.eclipse.emf.ecore.impl.EClassImpl@25641d39 (name:
EClass1) (instanceClassName: null) (abstract: false, interface: false)
huh?! eOp2 should have been an EOperation!
someParam is: EClass1
--
Elie
Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
|
|
| | |
Goto Forum:
Current Time: Thu Oct 03 18:04:07 GMT 2024
Powered by FUDForum. Page generated in 0.24355 seconds
|