Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 311872 - moved one element but EMF Compare produced two changes: A MoveModelElement (regular move) and a UpdateContainmentFeature (containment change)
Summary: moved one element but EMF Compare produced two changes: A MoveModelElement (r...
Status: CLOSED FIXED
Alias: None
Product: EMFCompare
Classification: Modeling
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: EMF Compare CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-06 09:07 EDT by Patrick Konemann CLA
Modified: 2011-08-18 04:05 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Konemann CLA 2010-05-06 09:07:18 EDT
Build Identifier: I20100429-1549

In one of my comparisons I moved one element but EMF Compare produced two changes: A MoveModelElement (regular move) and a UpdateContainmentFeature (containment change), and both contain the very same properties!

Example scenario and proposed fix below.
Version: Eclipse 3.6M7


Scenario:

Changing an association between two UML classes from unidirectional to directional.
Technically speaking: The first listing is the model with the unidirectional association, the second listing the model with the directional association.

LISTING UNCHANGED:
  <Class> A
  <Class> B
   - (feature ownedAttribute): <Property> dst : A
  <Association> A_src_dst
   - (feature ownedEnds): <Property> src : B

LISTING CHANGED:
  <Class> A
  - (feature ownedAttribute): <Property> src : B
  <Class> B
   - (feature ownedAttribute): <Property> dst : A
  <Association> A_src_dst

The two changes that EMF Compare detects are:
- <Property> src : B has been moved from <Association> A_src_dst to <Class> A
- Containment reference has been changed from ownedEnd to ownedAttribute

As I understand it, there is a bug for the detection of containment reference changes: they should only be detected if it is not already a move. In other words, the containment reference changes should only be created if the container differs.

I checked the generic diff engine and saw that this check is done for Match3Elements but not for Match2Elements.
So I guess we just need to adjust the generic diff engine as follows (just one line added; untested):

    protected void checkContainmentUpdate(DiffGroup current, Match2Elements matchElement) {
        final EObject leftElement = matchElement.getLeftElement();
        final EObject rightElement = matchElement.getRightElement();
        if (leftElement.eContainmentFeature() != null && rightElement.eContainmentFeature() != null) {
            if (!leftElement.eContainmentFeature().getName().equals(
                    rightElement.eContainmentFeature().getName())
                    && getMatchedEObject(leftElement.eContainer()).equals(rightElement.eContainer() // this line is new
                    ) {
                createUpdateContainmentOperation(current, leftElement, rightElement);
            }
        }
    }

Example models below.


FILE: move_unchanged.uml
---------------------------8<---------------------------
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_9e02AAyyEd-lddWJYP-XCg" name="myModel">
  <packagedElement xmi:type="uml:Class" xmi:id="_nb3TwVgiEd-v-4PFzr_Xug" name="A"/>
  <packagedElement xmi:type="uml:Class" xmi:id="_nb360FgiEd-v-4PFzr_Xug" name="B">
    <ownedAttribute xmi:id="_nb4h4VgiEd-v-4PFzr_Xug" name="dst" type="_nb3TwVgiEd-v-4PFzr_Xug" association="_nb4h4FgiEd-v-4PFzr_Xug">
      <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_nb4h4lgiEd-v-4PFzr_Xug" value="1"/>
      <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_nb4h41giEd-v-4PFzr_Xug" value="1"/>
    </ownedAttribute>
  </packagedElement>
  <packagedElement xmi:type="uml:Association" xmi:id="_nb4h4FgiEd-v-4PFzr_Xug" name="A_src_dst" memberEnd="_nb4h4VgiEd-v-4PFzr_Xug _nb4h5FgiEd-v-4PFzr_Xug">
    <ownedEnd xmi:id="_nb4h5FgiEd-v-4PFzr_Xug" name="src" type="_nb360FgiEd-v-4PFzr_Xug" association="_nb4h4FgiEd-v-4PFzr_Xug">
      <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_nb4h5VgiEd-v-4PFzr_Xug" value="1"/>
      <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_nb4h5lgiEd-v-4PFzr_Xug" value="1"/>
    </ownedEnd>
  </packagedElement>
</uml:Model>
--------------------------->8---------------------------

FILE: move_changed.uml
---------------------------8<---------------------------
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_9e02AAyyEd-lddWJYP-XCg" name="myModel">
  <packagedElement xmi:type="uml:Class" xmi:id="_nb3TwVgiEd-v-4PFzr_Xug" name="A">
    <ownedAttribute xmi:id="_nb4h5FgiEd-v-4PFzr_Xug" name="src" type="_nb360FgiEd-v-4PFzr_Xug" association="_nb4h4FgiEd-v-4PFzr_Xug">
      <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_nb4h5VgiEd-v-4PFzr_Xug" value="1"/>
      <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_nb4h5lgiEd-v-4PFzr_Xug" value="1"/>
    </ownedAttribute>
  </packagedElement>
  <packagedElement xmi:type="uml:Class" xmi:id="_nb360FgiEd-v-4PFzr_Xug" name="B">
    <ownedAttribute xmi:id="_nb4h4VgiEd-v-4PFzr_Xug" name="dst" type="_nb3TwVgiEd-v-4PFzr_Xug" association="_nb4h4FgiEd-v-4PFzr_Xug">
      <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_nb4h4lgiEd-v-4PFzr_Xug" value="1"/>
      <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_nb4h41giEd-v-4PFzr_Xug" value="1"/>
    </ownedAttribute>
  </packagedElement>
  <packagedElement xmi:type="uml:Association" xmi:id="_nb4h4FgiEd-v-4PFzr_Xug" name="A_src_dst" memberEnd="_nb4h4VgiEd-v-4PFzr_Xug _nb4h5FgiEd-v-4PFzr_Xug"/>
</uml:Model>

--------------------------->8---------------------------



Reproducible: Always
Comment 1 Cedric Brun CLA 2010-05-25 04:32:17 EDT
You were right, its fixed now and will be available in RC2 , thanks for your feedback !
Comment 2 Laurent Goubet CLA 2011-08-18 04:05:15 EDT
Closing our "resolved" and "verified" bugs.