[Xtend] Criterion for element equality in Xtend sets? [message #545716] |
Thu, 08 July 2010 14:05  |
Eclipse User |
|
|
|
Hello everybody,
from time to time, I'm using the someCollection.toSet() method of Xpand2's/Xtend's built-in API type "Collection". This method derives a set from a collection.
Which criterion is used to determine whether two elements of someCollection are identical, therefore allowing just one of these two collection elements to be an element in the derived set?
Is toSet() using the equals() method of Java? I noticed that Ecore-based EObjects (EObjectImpl... all Ecore based metamodel element instances are based on this class) do not override equals(). This means that any call to "myMetamodelElementInstance.equals()" falls back to "java.lang.Object.equals()"... ("this method returns true if and only if x and y refer to the same object (x == y has the value true)" )
Thanks,
Abdull
|
|
|
|
|
Re: [Xtend] Criterion for element equality in Xtend sets? [message #545955 is a reply to message #545845] |
Fri, 09 July 2010 13:12  |
Eclipse User |
|
|
|
I'll give some background for my question.
In a model transformation rule that I want to express as an Xtend transformation, I require an n:1 mapping of input model elements to output model elements - that is, from time to time, even though I've called a "create extention" with different parameters, I want to have two equal objects be returned from both invocations.
That is: imagine I have a tuple of input model elements <a1, b, c> of types <A, B, C>. Using a create extension, I get some new output model element of type D.
create anotherpack::D createSomeD(somepack::A myA, somepack::B myB, somepack::C myC) :
...
let myNewD = createSomeD(a1, b, c) :
Now imagine that for my model transformation to be correct, I require to receive an equal "d" in case I call createSomeD() with a slightly different tuple
let anotherNewD = createSomeD(a2, b, c) :
So I'd like to have the following expression to be true:
myNewD.equalsTo(anotherNewD) // (some pseudocode)
(you might ask, "why do you want to have an equal object be returned by different create invocations?"... the reason is: I require it ;-)
As much as I see, Xtend's create extensions allow for 1:1 mappings. That is: given any tuple of input, this tuple gets its own unique output.
But I just came across a transformation problem where I require an n:1 mapping. That is: given a tuple of input, it may map to the same output as some other tuple of input.
I'm trying to work around this problem using the JavaTuple library, but this unfortunately causes me to use JAVA extensions... distributing my whole transformation algorithm across some .ext files and some ugly static Java methods.
|
|
|
Powered by
FUDForum. Page generated in 0.03815 seconds