Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xtend] Criterion for element equality in Xtend sets?
[Xtend] Criterion for element equality in Xtend sets? [message #545716] Thu, 08 July 2010 18:05 Go to next message
Abdull is currently offline Abdull
Messages: 32
Registered: May 2010
Member
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 #545729 is a reply to message #545716] Thu, 08 July 2010 19:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6301
Registered: July 2009
Senior Member
Hi,

the Set Type and the toSet Method thereby use the java.util.LinkedHashSet internal and thereby delegate to hashCode(). Since hashCode() and equals() have a common contract your thoughts are true - but i don't think this is a problem since it won't make sense if 2 model element equal but not identical. if they are sematicaly the same why would a modeler create them twice.

Regards
Christian
Re: [Xtend] Criterion for element equality in Xtend sets? [message #545845 is a reply to message #545716] Fri, 09 July 2010 11:35 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2829
Registered: July 2009
Senior Member
Hi Abdull,

it is true that EObjects do not override equals or hashCode. In fact,
the framework assumes that eObject.equals(something) is equivalent to
eObject == something so it is prohibited to specialize equals or hashCode.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 08.07.10 20:05, schrieb Abdull:
> 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()"...
> ( http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/a pi/java/lang/Object.html#equals%28java.lang.Object%29
> )
>
> Thanks,
> Abdull
Re: [Xtend] Criterion for element equality in Xtend sets? [message #545955 is a reply to message #545845] Fri, 09 July 2010 17:12 Go to previous message
Abdull is currently offline Abdull
Messages: 32
Registered: May 2010
Member
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.
Previous Topic:Problem with transformation UML to text with Atl query
Next Topic:Referencing ecore primitive types in Xtend
Goto Forum:
  


Current Time: Wed Sep 17 19:39:37 GMT 2014

Powered by FUDForum. Page generated in 0.16225 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software