From 602a7f04975533d67e6c6857c0916b5044658e84 Mon Sep 17 00:00:00 2001 From: cbrun Date: Thu, 5 Jul 2007 14:26:47 +0000 Subject: [PATCH] [195496] Compare is now correctly handling sub-elements of moved elements. --- .../merge/impl/AddReferenceValueMerger.java | 29 +++++++++++++++++++++ .../merge/impl/RemoveReferenceValueMerger.java | 30 +++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/plugins/org.eclipse.emf.compare.diff/src/org/eclipse/emf/compare/diff/generic/merge/impl/AddReferenceValueMerger.java b/plugins/org.eclipse.emf.compare.diff/src/org/eclipse/emf/compare/diff/generic/merge/impl/AddReferenceValueMerger.java index 9c3b29fbe..7d50e06c7 100644 --- a/plugins/org.eclipse.emf.compare.diff/src/org/eclipse/emf/compare/diff/generic/merge/impl/AddReferenceValueMerger.java +++ b/plugins/org.eclipse.emf.compare.diff/src/org/eclipse/emf/compare/diff/generic/merge/impl/AddReferenceValueMerger.java @@ -10,8 +10,11 @@ *******************************************************************************/ package org.eclipse.emf.compare.diff.generic.merge.impl; +import java.util.Iterator; + import org.eclipse.emf.compare.EMFComparePlugin; import org.eclipse.emf.compare.diff.metamodel.AddReferenceValue; +import org.eclipse.emf.compare.diff.metamodel.DiffElement; import org.eclipse.emf.compare.util.EFactory; import org.eclipse.emf.compare.util.FactoryException; import org.eclipse.emf.ecore.EObject; @@ -37,6 +40,19 @@ public class AddReferenceValueMerger extends DefaultMerger { } catch (FactoryException e) { EMFComparePlugin.getDefault().log(e, true); } + // we should now have a look for AddReferencesLinks needing this object + final Iterator siblings = getDiffModel().eAllContents(); + while (siblings.hasNext()) { + final DiffElement op = (DiffElement)siblings.next(); + if (op instanceof AddReferenceValue) { + final AddReferenceValue link = (AddReferenceValue)op; + // now if I'm in the target References I should put my copy in the origin + if (link.getReference().equals(diff.getReference().getEOpposite()) + && link.getLeftAddedTarget().equals(element)) { + removeFromContainer(link); + } + } + } super.applyInOrigin(); } @@ -55,6 +71,19 @@ public class AddReferenceValueMerger extends DefaultMerger { } catch (FactoryException e) { EMFComparePlugin.getDefault().log(e, true); } + // we should now have a look for AddReferencesLinks needing this object + final Iterator siblings = getDiffModel().eAllContents(); + while (siblings.hasNext()) { + final DiffElement op = (DiffElement)siblings.next(); + if (op instanceof AddReferenceValue) { + final AddReferenceValue link = (AddReferenceValue)op; + // now if I'm in the target References I should put my copy in the origin + if (link.getReference().equals(diff.getReference().getEOpposite()) + && link.getRightAddedTarget().equals(element)) { + removeFromContainer(link); + } + } + } super.undoInTarget(); } } diff --git a/plugins/org.eclipse.emf.compare.diff/src/org/eclipse/emf/compare/diff/generic/merge/impl/RemoveReferenceValueMerger.java b/plugins/org.eclipse.emf.compare.diff/src/org/eclipse/emf/compare/diff/generic/merge/impl/RemoveReferenceValueMerger.java index d7587f471..e6eb7a5aa 100644 --- a/plugins/org.eclipse.emf.compare.diff/src/org/eclipse/emf/compare/diff/generic/merge/impl/RemoveReferenceValueMerger.java +++ b/plugins/org.eclipse.emf.compare.diff/src/org/eclipse/emf/compare/diff/generic/merge/impl/RemoveReferenceValueMerger.java @@ -10,7 +10,10 @@ *******************************************************************************/ package org.eclipse.emf.compare.diff.generic.merge.impl; +import java.util.Iterator; + import org.eclipse.emf.compare.EMFComparePlugin; +import org.eclipse.emf.compare.diff.metamodel.DiffElement; import org.eclipse.emf.compare.diff.metamodel.RemoveReferenceValue; import org.eclipse.emf.compare.util.EFactory; import org.eclipse.emf.compare.util.FactoryException; @@ -31,13 +34,25 @@ public class RemoveReferenceValueMerger extends DefaultMerger { public void applyInOrigin() { final RemoveReferenceValue diff = (RemoveReferenceValue)this.diff; final EObject element = diff.getLeftElement(); - // Iterator oldTarget = getReferencesOrigins().iterator(); final EObject leftTarget = diff.getLeftRemovedTarget(); try { EFactory.eRemove(element, diff.getReference().getName(), leftTarget); } catch (FactoryException e) { EMFComparePlugin.getDefault().log(e, true); } + // we should now have a look for AddReferencesLinks needing this object + final Iterator siblings = getDiffModel().eAllContents(); + while (siblings.hasNext()) { + final DiffElement op = (DiffElement)siblings.next(); + if (op instanceof RemoveReferenceValue) { + final RemoveReferenceValue link = (RemoveReferenceValue)op; + // now if I'm in the target References I should put my copy in the origin + if (link.getReference().equals(diff.getReference().getEOpposite()) + && link.getLeftRemovedTarget().equals(element)) { + removeFromContainer(link); + } + } + } super.applyInOrigin(); } @@ -56,6 +71,19 @@ public class RemoveReferenceValueMerger extends DefaultMerger { } catch (FactoryException e) { EMFComparePlugin.getDefault().log(e, true); } + // we should now have a look for AddReferencesLinks needing this object + final Iterator siblings = getDiffModel().eAllContents(); + while (siblings.hasNext()) { + final DiffElement op = (DiffElement)siblings.next(); + if (op instanceof RemoveReferenceValue) { + final RemoveReferenceValue link = (RemoveReferenceValue)op; + // now if I'm in the target References I should put my copy in the origin + if (link.getReference().equals(diff.getReference().getEOpposite()) + && link.getRightRemovedTarget().equals(element)) { + removeFromContainer(link); + } + } + } super.undoInTarget(); } } -- 2.11.4.GIT