Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 347745

Summary: A move of an EObject from a containment reference to another one should NOT create two diffs
Product: [Modeling] EMFCompare Reporter: Mikaël Barbero <mikael.barbero>
Component: CoreAssignee: EMF Compare <emf.compare-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: laurent.goubet
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Mikaël Barbero CLA 2011-05-31 04:19:13 EDT
Assuming this sample Ecore model:

<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="p1">
  <eSubpackages name="p2">
    <eSubpackages name="p3"/>
    <eSubpackages name="p4"/>
  </eSubpackages>
</ecore:EPackage>

if I move p3 upward into p1

<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="p1">
  <eSubpackages name="p2">
    <eSubpackages name="p4"/>
  </eSubpackages>
  <eSubpackages name="p3"/>
</ecore:EPackage>

There is no reason to have the two diff that EMFCompare returns to me:

- a change in p3 (p2 has been moved from p1 to p2)
- a change in p2 (the order of the reference eSubpackages values has changed

The issue is located into ReferencesCheck#checkContainmentReferenceOrderChange(DiffGroup, Match2Elements, EReference)

When you are purging left list of all references values that have been added, you should ALSO purge elements that moved from one container to this one as they will be handled by GenericDiffEngine#checkMoves().

The patch is trivial and is about adding an or-ed condition to the purge condition:

// Purge "left" list of all reference values that have been added to it
for (EObject leftValue : new ArrayList<EObject>(leftElementReferences)) {
    if (isUnmatched(leftValue) || leftValue.eContainer() != getMatchedEObject(leftValue).eContainer())
        leftElementReferences.remove(leftValue);
}

Regards,
Mikael
Comment 1 Laurent Goubet CLA 2011-06-10 06:45:32 EDT
Fixed on master and backported for 1.2.1