Skip to main content

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

Hi,

I dug a little bit into the code. The reason that i thought that henshin does automatically add but not remove root objects is that in the application wizard in the UI there is a code clone (Henshination.java/runUnitApplication:230) which does half of the work of InterpreterUtil.applyToResource(), namely adding new root objects to the resource. But the other half of it, removing deleted root objects from the resource is not there. This is were my misinterpretation came from during my tests. The question is now whether to do both parts or none in the wizard. The current implementation seems to be awkward.

To your point about containment edges, is  a containment relation between objects in the containment tree not similar to the containment relation between a resource and a root object?

While i probably still tend to disagree :-) with the decision not to add/remove root objects to/from the resource directly in the interpreter, i can live with it due the mentioned Utility class. 

Thanks and cheers,

Matthias

From: Christian Krause <henshin.ck@xxxxxxxxx>
Reply-To: Henshin developers mailing list <henshin-dev@xxxxxxxxxxx>
Date: Dienstag, 2. Juli 2013 16:04
To: Henshin developers mailing list <henshin-dev@xxxxxxxxxxx>
Subject: Re: [henshin-dev] Bug fix for deleting root objects in resource

Hi Matthias,

Henshin itself does not add or remove objects to resources. If you explicitly create or delete a containment edge, the effect will be that the target object is added to / removed from the containment tree and hence to / from the resource. For root objects, there is of course no containment edge, which is why Henshin does not add or remove root objects to resources.

You said that Henshin adds objects as roots to resources. I don't think that is actually true. (except for the helper InterpreterUtil.applyToResource() method).

Cheers,
Christian 





2013/7/2 Matthias Tichy <matthias.tichy@xxxxxxxxx>
Hi Christian,

Thanks for the pointer to InterpreterUtil.applyToResource(…)! This helps me to solve my current problem.

However, some more explanations/arguments:

If you delete an object which is contained by another object, then it is automatically removed from the resource as well. Why should this not be the same for objects which are root objects in a resource?

In other words, if you have a rule which contains a node in the lhs but not in the rhs, then you would expect that after application of the rule the node is not contained in the host graph anymore. If you then apply the same rule on the resource a second time, you expect that the node is not matched to the same object in the host graph again (since the object should not be  part of the host graph anymore) as this would otherwise contradict the semantics of the delete action. In the current implementation, the matched object is still in the resource after the application of the rule and you can apply the same rule with the same matching again.

The other way around works, so if you create an object, which has no containment relation to another object, it is added to the resource as root object during the rule application. 

But maybe this boils down to my misunderstanding of the relation between the resource and  the graph which is created from the objects in a resource?

Best regards,

Matthias 

From: Christian Krause <henshin.ck@xxxxxxxxx>
Reply-To: Henshin developers mailing list <henshin-dev@xxxxxxxxxxx>
Date: Dienstag, 2. Juli 2013 14:56
To: Henshin developers mailing list <henshin-dev@xxxxxxxxxxx>
Subject: Re: [henshin-dev] Bug fix for deleting root objects in resource

Hi Matthias,

thanks a lot for the patch. I am not sure though whether a rule should really remove objects from their resource(?).

Anyway, there is already a solution in Henshin for this problem: InterpreterUtil.applyToResource(...)

But this works only for one resource.

Cheers,
Christian


2013/7/2 Matthias Tichy <matthias.tichy@xxxxxxxxx>
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;
        }






_______________________________________________
henshin-dev mailing list
henshin-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/henshin-dev


_______________________________________________
henshin-dev mailing list
henshin-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/henshin-dev



Back to the top