[Acceleo] eClass().name comparison not working .. [message #677567] |
Wed, 08 June 2011 20: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 20:38] Report message to a moderator
|
|
|
|
|
|
Re: [Acceleo] eClass().name comparison not working .. [message #677721 is a reply to message #677665] |
Thu, 09 June 2011 08:40 |
|
Hi,
@Ed : that doesn't really make sense :
"It looks as if either left or right hand side has not been converted
from EString to String and so the actual comparison occurs for one of
String/EString, EString/String when String/String should have occurred."
Internally, we are simply delegating to OCL the evaluation of the operation call. IIRC, the actual comparison through OCL will evaluate both side's property calls, then use "equals()" on these values. Both sides are a String, string.equals(anotherString) will return true if they have the same value.
What I suspect here is more the "usual" problem of comparing a collection (containing a single String) with a String.
Could you post the real example where you observe this failure?
Laurent Goubet
Obeo
|
|
|
|
|
Re: [Acceleo] eClass().name comparison not working .. [message #677779 is a reply to message #677746] |
Thu, 09 June 2011 11:27 |
|
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.04712 seconds