Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[henshin-dev] Bug fix for deleting root objects in resource

Dear all,

I noted that Hehnshin does not delete the root objects from a resource
while executing the changes of a rule application which include the
deletion of the root object. The relevant test in DeleteNodes only checks
whether the root object is not contained in the graph anymore but does not
check the resource. In my opinion, if a root object is deleted it should
be also removed from the resource (if not, it would still exists and
contradict the rule application).

I added a bug fix to EGraphImpl and adapted the test case to also check
for the removal of the root object from the resource. All test cases still
pass. Attached the small patch against the current head.

Best regards,

Matthias



### Eclipse Workspace Patch 1.0
#P org.eclipse.emf.henshin.tests
Index: src/org/eclipse/emf/henshin/tests/basicTests/DeleteNodes.java
===================================================================
---
src/org/eclipse/emf/henshin/tests/basicTests/DeleteNodes.java	(revision
1872)
+++ src/org/eclipse/emf/henshin/tests/basicTests/DeleteNodes.java	(working
copy)
@@ -12,6 +12,8 @@
package org.eclipse.emf.henshin.tests.basicTests;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.henshin.tests.framework.GraphTransformations;
import org.eclipse.emf.henshin.tests.framework.HenshinLoaders;
import org.eclipse.emf.henshin.tests.framework.HenshinTest;
@@ -142,9 +144,18 @@
		 */
		loadGraph("graphWithRootNode");
		loadRule("deleteRootNode");
+		
+		EObject rootNode = htEGraph.getRoots().get(0);
+		Resource res = rootNode.eResource();
+		
		Rules.assertRuleCanBeApplied(htRuleApp);
-		if (Tools.getGraphRoot(htEGraph) != null) {
+		if (Tools.getGraphRoot(htEGraph) != null ) {
			throw new AssertionError("expected: Root node deleted, but a root node
still exists.");
		}
+		if (res.getContents().contains(rootNode))
+		{
+			throw new AssertionError("expected: Root node removed from resource,
but resource still containts the root node");
+		}
	}
+
}
#P org.eclipse.emf.henshin.interpreter
Index: src/org/eclipse/emf/henshin/interpreter/impl/EGraphImpl.java
===================================================================
--- src/org/eclipse/emf/henshin/interpreter/impl/EGraphImpl.java	(revision
1872)
+++ src/org/eclipse/emf/henshin/interpreter/impl/EGraphImpl.java	(working
copy)
@@ -129,8 +129,14 @@
	public boolean remove(Object object) {
		boolean removed = super.remove(object);
		if (removed && object instanceof EObject) {
-			domainMap.get(((EObject) object).eClass()).remove(object);
-			((EObject) object).eAdapters().remove(crossReferenceAdapter);
+			EObject eObject = (EObject) object;
+			domainMap.get(eObject.eClass()).remove(object);
+			eObject.eAdapters().remove(crossReferenceAdapter);
+			// if eObject is not inside a container but directly contained in the
contents of the resource we need to remove the object from the resource
directly
+			if (eObject.eContainer() == null &&
eObject.eResource().getContents().contains(object))
+			{
+				eObject.eResource().getContents().remove(object);
+			}
		}
		return removed;
	}








Back to the top