Problem with eSetResource(null, null) in EMF from GMF in Eclipse Juno [message #895518] |
Fri, 13 July 2012 11:17 |
Tiziano Leidi Messages: 28 Registered: July 2009 |
Junior Member |
|
|
Hi People,
we installed the new Eclipse 4.2 and we are currently facing the following problem in EMF/GMF code.
In the class (GMF) there is the following method.
public static EObject appendEObjectAt(EObject eObject,
EReference reference, EObject referencedObject) {
if (isOkToAppendEObjectAt(eObject, reference, referencedObject) == false) {
return null;
}
if (reference.isContainment()) {
((InternalEObject)referencedObject).eSetResource(null,null);
sendCreateEvent(referencedObject);
}
((Collection) eObject.eGet(reference)).add(referencedObject);
return referencedObject;
}
which calls
The implementation of has changed in EMF from the previous version, ... in BasicEObjectImpl now there is the following new implementation
public NotificationChain eSetResource(Resource.Internal resource, NotificationChain notifications)
{
Resource.Internal oldResource = eDirectResource();
// When setting the resource to null we assume that detach has already been called in the resource implementation
//
if (oldResource != null && resource != null)
{
notifications = ((InternalEList<?>)oldResource.getContents()).basicRemove(this, notifications);
oldResource.detached(this);
}
which was before (Eclipse Indigo)
public NotificationChain eSetResource(Resource.Internal resource, NotificationChain notifications)
{
Resource.Internal oldResource = eDirectResource();
if (oldResource != null)
{
notifications = ((InternalEList<?>)oldResource.getContents()).basicRemove(this, notifications);
// When setting the resource to null we assume that detach has already been called in the resource implementation
//
if (resource != null)
{
oldResource.detached(this);
}
}
As a consequence, the behavior is different for a call and the object is not removed from the resource with as it previously was.
Please, let us know if the behavior is correct or if the implementation is wrong either in GMF or EMF. Do we have to modify something in our source code to continue using the Clipboard support of GMF as previously?
Many thanks
Tiziano
|
|
|
Re: Problem with eSetResource(null, null) in EMF from GMF in Eclipse Juno [message #895526 is a reply to message #895518] |
Fri, 13 July 2012 11:38 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Tiziano,<br>
<br>
This change was made to fix <a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=346805">https://bugs.eclipse.org/bugs/show_bug.cgi?id=346805</a>.
<br>
<br>
This API was never intended to be called directly by clients:<small><br>
</small>
<blockquote><small> /**</small><br>
<small> * Sets this object to be directly contained by the
resource </small><br>
<small> * and returns accumulated notifications.</small><br>
<small> * This is only done as the inverse of {@link
Resource#getContents()}<code>.add(this)</code>.</small><br>
<small> * @return accumulated notifications.</small><br>
<small> */</small><br>
<small> NotificationChain eSetResource(Resource.Internal
resource, NotificationChain notifications);</small><br>
</blockquote>
The GMF code should be using resource.getContents().remove(...).
I.e., perhaps it should be
referencedObject.eResource().getContents().remove(referencedObject)
though I'm not sure if the referenced object is necessarily
contained directly in a resource so maybe it should check that
eResource() isn't null. <br>
<br>
You should open a bugzilla for the GMF runtime to fix this.<br>
<br>
<br>
<br>
<div class="moz-cite-prefix">On 13/07/2012 1:17 PM, Tiziano Leidi
wrote:<br>
</div>
<blockquote cite="mid:jtp04f$js0$1@xxxxxxxxe.org" type="cite">Hi
People,
<br>
we installed the new Eclipse 4.2 and we are currently facing the
following problem in EMF/GMF code.
<br>
<br>
In the class ClipboardSupportUtil (GMF) there is the following
method.
<br>
<br>
public static EObject appendEObjectAt(EObject eObject,
<br>
EReference reference, EObject referencedObject) {
<br>
if (isOkToAppendEObjectAt(eObject, reference,
referencedObject) == false) {
<br>
return null;
<br>
}
<br>
if (reference.isContainment()) {
<br>
((InternalEObject)referencedObject).eSetResource(null,null);
<br>
sendCreateEvent(referencedObject);
<br>
}
<br>
((Collection)
eObject.eGet(reference)).add(referencedObject);
<br>
return referencedObject;
<br>
}
<br>
<br>
which calls eSetResource(null,null)
<br>
<br>
The implementation of eSetResource has changed in EMF from the
previous version, ... in BasicEObjectImpl now there is the
following new implementation
<br>
<br>
public NotificationChain eSetResource(Resource.Internal resource,
NotificationChain notifications)
<br>
{
<br>
Resource.Internal oldResource = eDirectResource();
<br>
// When setting the resource to null we assume that detach has
already been called in the resource implementation
<br>
//
<br>
if (oldResource != null && resource != null)
<br>
{
<br>
notifications =
((InternalEList<?>)oldResource.getContents()).basicRemove(this,
notifications);
<br>
oldResource.detached(this);
<br>
}
<br>
<br>
which was before (Eclipse Indigo)
<br>
<br>
public NotificationChain eSetResource(Resource.Internal resource,
NotificationChain notifications)
<br>
{
<br>
Resource.Internal oldResource = eDirectResource();
<br>
if (oldResource != null)
<br>
{
<br>
notifications =
((InternalEList<?>)oldResource.getContents()).basicRemove(this,
notifications);
<br>
<br>
// When setting the resource to null we assume that detach
has already been called in the resource implementation
<br>
//
<br>
if (resource != null)
<br>
{
<br>
oldResource.detached(this);
<br>
}
<br>
}
<br>
<br>
As a consequence, the behavior is different for a call
eSetResource(null,null) and the object is not removed from the
resource with basicRemove as it previously was.
<br>
<br>
Please, let us know if the behavior is correct or if the
implementation is wrong either in GMF or EMF. Do we have to modify
something in our source code to continue using the Clipboard
support of GMF as previously?
<br>
<br>
Many thanks
<br>
Tiziano
<br>
<br>
<br>
</blockquote>
<br>
<br>
</body>
</html>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.03382 seconds