|[Acceleo] eClass().name comparison not working .. [message #677567]
||Wed, 08 June 2011 16:32
Registered: April 2011
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)]
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
[Updated on: Wed, 08 June 2011 16:38]
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
Registered: July 2009
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.
Powered by FUDForum
. Page generated in 0.04486 seconds