Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EClassifier.isInstance behavior
EClassifier.isInstance behavior [message #642966] Fri, 03 December 2010 14:34 Go to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1813
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

say that in my meta model I have 'Field' which inherits from 'TypedElement'.

Now, if I have an EClass for TypedElement, say C, and I have an instance
of Field, say f, I would expect

C.isInstance(f)

to return true, but it returns false.

By debugging, I see that it calls

protected boolean dynamicIsInstance(EObject eObject)
{
return isSuperTypeOf(eObject.eClass());
}

and then it calls

public boolean isSuperTypeOf(EClass someClass)
{
return someClass == this ||
someClass.getEAllSuperTypes().contains(this);
}

the checking is done using == i.e., object identities (also contains
uses == for comparison), and thus the check fails, although
getEAllSuperTypes actually contains an EClass for TypedElement...

is it the desired semantics?

of course I can implement manually my intended behavior, but I was
curios about this...

thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: EClassifier.isInstance behavior [message #643006 is a reply to message #642966] Fri, 03 December 2010 15:51 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Lorenzo,

Comments below.

Lorenzo Bettini wrote:
> Hi
>
> say that in my meta model I have 'Field' which inherits from
> 'TypedElement'.
>
> Now, if I have an EClass for TypedElement, say C, and I have an
> instance of Field, say f, I would expect
>
> C.isInstance(f)
>
> to return true, but it returns false.
>
> By debugging, I see that it calls
>
> protected boolean dynamicIsInstance(EObject eObject)
> {
> return isSuperTypeOf(eObject.eClass());
> }
>
> and then it calls
>
> public boolean isSuperTypeOf(EClass someClass)
> {
> return someClass == this ||
> someClass.getEAllSuperTypes().contains(this);
> }
>
> the checking is done using == i.e., object identities (also contains
> uses == for comparison), and thus the check fails, although
> getEAllSuperTypes actually contains an EClass for TypedElement...
No, at best it contains a copy that may or may not be structurally "the
same".
>
> is it the desired semantics?
Definitely. This is exactly what Java does as well. You can have
multiple loaded copies of "the same" java.lang.Class, but .equals will
return false and instances will not be assignment compatible.
>
> of course I can implement manually my intended behavior, but I was
> curios about this...
I doubt you can implement it consistently. You'd have to define
structural equality and the testing of it would have to cover the entire
graph of objects associated with the class, i.e., the containing package
and everything reachable from it would need to be structurally equal (or
minimally everything reachable from references in the class). Can you
imagine having to perform such a massive test just to do isInstance
checking? The system will grind to a halt doing the most trivial of
things. Don't go there. Best to ensure that everything is using the
right instance of the class....
>
> thanks in advance
> Lorenzo
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:MinimalEObjectImpl
Next Topic:How to create a dynamic instances of two dependant Metamodels
Goto Forum:
  


Current Time: Fri Sep 20 20:34:16 GMT 2024

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

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

Back to the top