| [Acceleo] eClass().name comparison not working .. [message #677567] |
Wed, 08 June 2011 16:32  |
the_ch40s Messages: 14 Registered: April 2011 |
Junior Member |
|
|
Hello,
me again^^.
I have some unexpected behaviour:
I got two names of eClasses, which show up exactly the same in the generated code, but their comparison always returns false. This is the code-example:
[for vhdlEnt : VHDLEntity | module.eContents(VHDLEntity) )]
[for (port: ModulePort | module.eContents(ModulePort) )]
[if (port.eClass().name = vhdlEnt.eClass().name)]
true
[/if]
[port.eClass().name/]
[vhdlEnt.eClass().name/]
[/for]
[/for]
As stated above, the two expressions below the if-block return the exact same string( AKFixedPoint), but the if-block itself just doesn't evaluate to true.
What am i missing?
Thanks in advance 
greetz
[Updated on: Wed, 08 June 2011 16:38] Report message to a moderator
|
|
|
|
| Re: [Acceleo] eClass().name comparison not working .. [message #677599 is a reply to message #677594] |
Wed, 08 June 2011 18:19   |
the_ch40s Messages: 14 Registered: April 2011 |
Junior Member |
|
|
Sorry, i edited the post a bit later.
The code is not exactly like that, but it sums it up. Here is the corrected version
[for (vhdlEnt : VHDLEntity | module.eContents(VHDLEntity) )]
[for (port: ModulePort | module.eContents(ModulePort) )]
[if (port.eClass().name = vhdlEnt.eClass().name)]
true
[/if]
[port.eClass().name/]
[vhdlEnt.eClass().name/]
[/for]
[/for]
Anyways, i found a solution:
If i change the if-block to
...
if( port.eClass().name.toString() = vhdlEnt.eClass.name.toString()
...
it works as expected, what surprises me a bit, since eClass().name returns an EString, and i was under the impression that i could use the equal operator on it.
Would be nice if someone could clear this up 
Thanks for the help.
[Updated on: Wed, 08 June 2011 18:19] Report message to a moderator
|
|
|
|
|
|
|
| Re: [Acceleo] eClass().name comparison not working .. [message #677779 is a reply to message #677746] |
Thu, 09 June 2011 07:27   |
Laurent Goubet Messages: 1548 Registered: July 2009 |
Senior Member |
|
|
As I Thought : you're not comparing "String"s, but a Sequence with a String. Acceleo has its own pretty printer for Collections so that we do not print the starting "[", the "," separator and the trailing "]" of the "normal" collection.toString(). That is why you have things that "seem" equals when printed, even though they are not. As for why it works with ".toString()", I won't enter in the details, but that, too, should fail. It works because of a parser shortcoming that's been highlighted in Acceleo 3.1 (i.e : in 3.1, you'd have at least two warnings with this module).
The problem is that we did not check for the validity of Queries return types. You could have a query returning a boolean value, yet declared as "[query public query() : String = true]". Your "getAKType(ModulePort)" query really returns a Sequence of Strings, not a String. "eInverse" returns a Sequence; all subsequent calls are implicit collect operations. You should rewrite it like this :
[query public getAKType(port : ModulePort) : String
= port.eInverse(Channel)->first().akType.oclAsType(AKTypeLiteral).value.eClass().name /]
On the contrary, "getAKType(port : VHDLPort)" properly returns a single String.
Laurent Goubet
Obeo
|
|
|
|
Powered by
FUDForum. Page generated in 0.01820 seconds