|
Re: [acceleo] Strange behavior when accessing name field [message #640685 is a reply to message #640683] |
Mon, 22 November 2010 20:06 |
Glenview Jeff Messages: 79 Registered: September 2010 |
Member |
|
|
Another bit of quite useful troubleshooting information is that the name is accessed successfully to generate the output filename. The problem occurs in the middle of a for loop that is accessing another field of the class.
Specifically, i.name in the [file] line works fine as below:
[template public ChildClass(i : ChildClass)]
[file ('/path/to/folder/'.concat(i.name.concat('.java')), false, 'Cp1252')]
But later in the same mtl file, the i.name in this code is where i get the strange output. anItem.name works fine.
[for (anItem : Item | i.list.items)]
[i.name/]_[anItem.name/]:
[/for]
[Updated on: Mon, 22 November 2010 20:13] Report message to a moderator
|
|
|
Re: [acceleo] Strange behavior when accessing name field [message #640691 is a reply to message #640685] |
Mon, 22 November 2010 20:12 |
Glenview Jeff Messages: 79 Registered: September 2010 |
Member |
|
|
I worked around this by surrounding the for loop with a [let] where I accessed the member as follows:
[let myName : String = i.name]
[for (anItem : Item | i.list.items)]
[myName/]_[anItem.name/]:
[/for]
[/let]
Is this a bug or a feature that I have to do this? Also, please note that the missing slash in the previous post was only a typo in the message, not in the actual code.
[Updated on: Mon, 22 November 2010 20:13] Report message to a moderator
|
|
|
Re: [acceleo] Strange behavior when accessing name field [message #640786 is a reply to message #640691] |
Tue, 23 November 2010 07:54 |
|
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 07:56] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03311 seconds