Implementing "Equals" and "HashCode" in an EMF Model [message #505398] |
Wed, 30 December 2009 06:50  |
Eclipse User |
|
|
|
Hi,
I need to implement usual equals() and hashCode() methods in my EMF classes: when I try to do this in my generated classes (the *Impl package) Eclipse complains "There are no non-static fields in this class", and that's true. So, before I dig into generated code, there is anyone who knows "where" and "how" can I accomplish this?
Thanks in advance and happy new year to all
Regards,
Giovanni.
|
|
|
Re: Implementing "Equals" and "HashCode" in an EMF Model [message #505404 is a reply to message #505398] |
Wed, 30 December 2009 07:04  |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------010302030506010002060409
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Giovanni,
The Javadoc for EObject says:
Any |EObject| is assumed to also implement |InternalEObject
< eclipse-javadoc:%E2%98%82=org.eclipse.emf.ecore/src%3Corg.ec lipse.emf.ecore%7BEObject.java%E2%98%83EObject%E2%98%82Inter nalEObject >|,
which provides lower-level access that is not necessarily suitable
for general consumption but is required for maintaining the EMF
support mechanisms. Implementations of EObject should extend
|BasicEObjectImpl
< eclipse-javadoc:%E2%98%82=org.eclipse.emf.ecore/src%3Corg.ec lipse.emf.ecore%7BEObject.java%E2%98%83EObject%E2%98%82org.e clipse.emf.ecore.impl.BasicEObjectImpl >|
or one of its derived classes because methods can and will be added
to this API. *The framework also assumes that implementations will
not specialize |equals(Object)
< eclipse-javadoc:%E2%98%82=org.eclipse.emf.ecore/src%3Corg.ec lipse.emf.ecore%7BEObject.java%E2%98%83EObject%E2%98%82%E2%9 8%82equals%E2%98%82Object >|
(nor |hashCode()
< eclipse-javadoc:%E2%98%82=org.eclipse.emf.ecore/src%3Corg.ec lipse.emf.ecore%7BEObject.java%E2%98%83EObject%E2%98%82%E2%9 8%82hashCode%E2%98%82 >|)
so that "|==|" can be always used for equality testing*;
|EcoreUtil.equals
< eclipse-javadoc:%E2%98%82=org.eclipse.emf.ecore/src%3Corg.ec lipse.emf.ecore%7BEObject.java%E2%98%83EObject%E2%98%82org.e clipse.emf.ecore.util.EcoreUtil%E2%98%82equals%E2%98%82EObje ct%E2%98%82EObject >|
should be used for doing structural equality testing.
So don't go there.
giovanni wrote:
> Hi,
>
> I need to implement usual equals() and hashCode() methods in my EMF
> classes: when I try to do this in my generated classes (the *Impl
> package) Eclipse complains "There are no non-static fields in this
> class", and that's true. So, before I dig into generated code, there
> is anyone who knows "where" and "how" can I accomplish this?
>
> Thanks in advance and happy new year to all
>
> Regards,
>
> Giovanni.
--------------010302030506010002060409
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Giovanni,<br>
<br>
The Javadoc for EObject says:<br>
<br>
<blockquote>Any <code>EObject</code> is assumed to also implement <code><a
href=" eclipse-javadoc:%E2%98%82=org.eclipse.emf.ecore/src%3Corg.ec lipse.emf.ecore%7BEObject.java%E2%98%83EObject%E2%98%82Inter nalEObject ">InternalEObject</a></code>,
which provides lower-level access that is not necessarily suitable for
general consumption but is required for maintaining the EMF support
mechanisms. Implementations of EObject should extend <code><a
href=" eclipse-javadoc:%E2%98%82=org.eclipse.emf.ecore/src%3Corg.ec lipse.emf.ecore%7BEObject.java%E2%98%83EObject%E2%98%82org.e clipse.emf.ecore.impl.BasicEObjectImpl ">BasicEObjectImpl</a></code>
or one of its derived classes because methods can and will be added to
this API. <b>The framework also assumes that implementations will not
specialize <code><a
href=" eclipse-javadoc:%E2%98%82=org.eclipse.emf.ecore/src%3Corg.ec lipse.emf.ecore%7BEObject.java%E2%98%83EObject%E2%98%82%E2%9 8%82equals%E2%98%82Object ">equals(Object)</a></code>
(nor <code><a
href=" eclipse-javadoc:%E2%98%82=org.eclipse.emf.ecore/src%3Corg.ec lipse.emf.ecore%7BEObject.java%E2%98%83EObject%E2%98%82%E2%9 8%82hashCode%E2%98%82 ">hashCode()</a></code>)
so that "<code>==</code>" can be always used for equality testing</b>; <code><a
href=" eclipse-javadoc:%E2%98%82=org.eclipse.emf.ecore/src%3Corg.ec lipse.emf.ecore%7BEObject.java%E2%98%83EObject%E2%98%82org.e clipse.emf.ecore.util.EcoreUtil%E2%98%82equals%E2%98%82EObje ct%E2%98%82EObject ">EcoreUtil.equals</a></code>
should be used for doing structural equality testing. <br>
</blockquote>
<br>
So don't go there.<br>
<br>
giovanni wrote:
<blockquote cite="mid:hhfer1$dd9$1@build.eclipse.org" type="cite">Hi,
<br>
<br>
I need to implement usual equals() and hashCode() methods in my EMF
classes: when I try to do this in my generated classes (the *Impl
package) Eclipse complains "There are no non-static fields in this
class", and that's true. So, before I dig into generated code, there is
anyone who knows "where" and "how" can I accomplish this?
<br>
<br>
Thanks in advance and happy new year to all
<br>
<br>
Regards,
<br>
<br>
Giovanni. </blockquote>
</body>
</html>
--------------010302030506010002060409--
|
|
|
Powered by
FUDForum. Page generated in 0.05181 seconds