[acceleo] Strange behavior when accessing name field [message #640683] |
Mon, 22 November 2010 14:48  |
Eclipse User |
|
|
|
I'm a bit of a newbie with acceleo as you probably have read. I have around 100 lines of functional acceleo code in my project. I recently ran into this strange problem.
I have an Eclass, call it "child class" that is derived from another in a second ecore meta-model. The parent class has a name field.
In my mtl file, I access the child class's name via [childclass.name/].
In the output file, this is what I get instead of the name:
org.eclipse.emf.ecore.impl.DynamicEObjectImpl@7f3ca730 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@67048192 (name: Invalid_Class) (instanceClassName: null) (abstract: false, interface: false))
Has anyone seen anything like this? Other fields in the same mtl file work fine.
Thanks!
Jeff
|
|
|
|
|
Re: [acceleo] Strange behavior when accessing name field [message #640786 is a reply to message #640691] |
Tue, 23 November 2010 02:54   |
Eclipse User |
|
|
|
Hi Jeff,
We define an implicit "i" variable that olds the iteration count for each of our "for" loops. If you define your "for" loop with the iteration named "i", then "i" inside the for will have the value contained in the Sequence :
[for (i : String | Sequence{'a', 'b', 'c'}][i/][/for]
will generate "abc".
If your iteration variable has another name, then "i" will be the iteration count :
[for (s : String | Sequence{'a', 'b', 'c'}][i/][/for]
will generate "123".
With that said, you are in the second case : your iteration variable is not named "i", so we override it for the iteration count, and "integer.name" yield an invalid result (which is what got generated in your case).
Change the name of your template argument for a meaningful name, and you will not have this error anymore :
[template public ChildClass(class : ChildClass)]
as the problem exists only with the "i" variable.
Laurent Goubet
Obeo
[Updated on: Tue, 23 November 2010 02:56] by Moderator
|
|
|
Re: [acceleo] Strange behavior when accessing name field [message #640952 is a reply to message #640786] |
Tue, 23 November 2010 11:33  |
Eclipse User |
|
|
|
Thanks very much for explaining this Laurent. The choice of the variable name "i" was, interestingly enough, created from the auto-generated template Acceleo itself created based upon the template name "Item." As I'm sure you know, Acceleo when chooses by default for a parameter name a single lower-case letter variable name that corresponds to the first letter in the name of the template.
I think I will submit an enhancement request to change this syntax to something unique like i$. It seems almost without modern precedent and is most unexpected for a programming language to hard code a valid variable name to have special meaning. I recognize that this might cause some backwards incompatibility, but you could optionally issue a warning when using the ambiguous variable "i."
|
|
|
Powered by
FUDForum. Page generated in 0.03253 seconds