Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Elie Richa is currently offline Elie RichaFriend
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 #1737172 is a reply to message #1737072] Wed, 06 July 2016 08:35 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
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?

Laurent Goubet
Obeo
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 Go to previous messageGo to next message
Elie Richa is currently offline Elie RichaFriend
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
Re: Template parameter altered by passing the result of a query [message #1737307 is a reply to message #1737259] Thu, 07 July 2016 08:16 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

This is a bug on the variable scoping. Basically, having multiple invocations (templates or query) on the same line as parameters of each other would fail.

It will be fixed in the next maintenance version, but for now your only workaround is to use a let to store the variable before using it or inline the query.

Laurent Goubet
Obeo
Re: Template parameter altered by passing the result of a query [message #1737314 is a reply to message #1737307] Thu, 07 July 2016 08:53 Go to previous message
Elie Richa is currently offline Elie RichaFriend
Messages: 72
Registered: February 2016
Member
Hi Laurent,

On 07/07/16 10:16, Laurent Goubet wrote:
> Hi,
>
> This is a https://bugs.eclipse.org/bugs/show_bug.cgi?id=497457.
> Basically, having multiple invocations (templates or query) on the same
> line as parameters of each other would fail.
>
> It will be fixed in the next maintenance version, but for now your only
> workaround is to use a let to store the variable before using it or
> inline the query.

Thank you for your reply. That workaround seems reasonable for me at the
moment.

I see that there's already a Gerrit patch in the pipeline so looking
forward for the next maintenance version :)

Cheers,

--
Elie


Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
Previous Topic:UML metamodel not found in createing Acceleo project
Next Topic:query with multiple parameters
Goto Forum:
  


Current Time: Thu Oct 03 18:04:07 GMT 2024

Powered by FUDForum. Page generated in 0.24355 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top