diff options
author | cbrun | 2012-10-11 09:03:42 +0000 |
---|---|---|
committer | cbrun | 2012-10-11 09:03:42 +0000 |
commit | b790b58524d5cdc2defcfa219265a1a79e9954e4 (patch) | |
tree | 34c8606785e774621f5174f90c0f44d235bac4b7 | |
parent | 43c798eace0eeeb8ad8b623c250401a0409af277 (diff) | |
download | org.eclipse.emf.compare-b790b58524d5cdc2defcfa219265a1a79e9954e4.tar.gz org.eclipse.emf.compare-b790b58524d5cdc2defcfa219265a1a79e9954e4.tar.xz org.eclipse.emf.compare-b790b58524d5cdc2defcfa219265a1a79e9954e4.zip |
bug 390664: ignore XMI id option does not fully ignore ids
https://bugs.eclipse.org/bugs/show_bug.cgi?id=390664
EditionDistance is now using a specific EqualityHelper which will not
use the standard EMF URIs but instead a list of fragments representing
the path to an object. A sequence of feature names + position.
8 files changed, 92 insertions, 93 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/framework/junit/internal/DiffStatement.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/framework/junit/internal/DiffStatement.java index 6ccbbef5d..cb979d1be 100644 --- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/framework/junit/internal/DiffStatement.java +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/framework/junit/internal/DiffStatement.java @@ -27,7 +27,6 @@ import org.eclipse.emf.compare.scope.DefaultComparisonScope; import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.compare.tests.framework.NotifierTuple;
import org.eclipse.emf.compare.tests.framework.junit.annotation.DiffTest;
-import org.eclipse.emf.compare.utils.EqualityHelper;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
@@ -109,7 +108,7 @@ public class DiffStatement extends Statement { }
if (engine == null) {
final IEObjectMatcher contentMatcher = ProximityEObjectMatcher.builder(
- EditionDistance.builder(new EqualityHelper()).build()).build();
+ EditionDistance.builder().build()).build();
final IEObjectMatcher matcher = new IdentifierEObjectMatcher(contentMatcher);
engine = new DefaultMatchEngine(matcher);
}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/framework/junit/internal/MatchStatement.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/framework/junit/internal/MatchStatement.java index 3cda4e041..7908dd1d3 100644 --- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/framework/junit/internal/MatchStatement.java +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/framework/junit/internal/MatchStatement.java @@ -26,7 +26,6 @@ import org.eclipse.emf.compare.scope.DefaultComparisonScope; import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.compare.tests.framework.NotifierTuple;
import org.eclipse.emf.compare.tests.framework.junit.annotation.MatchTest;
-import org.eclipse.emf.compare.utils.EqualityHelper;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
@@ -115,7 +114,7 @@ public class MatchStatement extends Statement { }
if (engine == null) {
final IEObjectMatcher contentMatcher = ProximityEObjectMatcher.builder(
- EditionDistance.builder(new EqualityHelper()).build()).build();
+ EditionDistance.builder().build()).build();
final IEObjectMatcher matcher = new IdentifierEObjectMatcher(contentMatcher);
engine = new DefaultMatchEngine(matcher);
}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fullcomparison/DistanceAxiomsTests.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fullcomparison/DistanceAxiomsTests.java index 80f322b9e..176a91e79 100644 --- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fullcomparison/DistanceAxiomsTests.java +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fullcomparison/DistanceAxiomsTests.java @@ -18,7 +18,6 @@ import com.google.common.collect.Lists; import org.eclipse.emf.compare.match.eobject.EditionDistance; import org.eclipse.emf.compare.match.eobject.ProximityEObjectMatcher.DistanceFunction; import org.eclipse.emf.compare.tests.suite.AllTests; -import org.eclipse.emf.compare.utils.EqualityHelper; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EcorePackage; import org.junit.Assume; @@ -48,7 +47,7 @@ public class DistanceAxiomsTests { @Before public void setUp() throws Exception { AllTests.fillEMFRegistries(); - this.meter = new EditionDistance(new EqualityHelper()); + this.meter = new EditionDistance(); } @DataPoints diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fullcomparison/MatchPerformanceComparisonTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fullcomparison/MatchPerformanceComparisonTest.java index 31464332a..874e4ea81 100644 --- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fullcomparison/MatchPerformanceComparisonTest.java +++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fullcomparison/MatchPerformanceComparisonTest.java @@ -22,7 +22,6 @@ import org.eclipse.emf.compare.scope.DefaultComparisonScope; import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.compare.tests.fullcomparison.data.distance.DistanceMatchInputData;
import org.eclipse.emf.compare.tests.suite.AllTests;
-import org.eclipse.emf.compare.utils.EqualityHelper;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.uml2.uml.UMLPackage;
@@ -62,7 +61,7 @@ public class MatchPerformanceComparisonTest { @Test
public void warmup() throws IOException {
final IEObjectMatcher contentMatcher = ProximityEObjectMatcher.builder(
- EditionDistance.builder(new EqualityHelper()).build()).build();
+ EditionDistance.builder().build()).build();
final IEObjectMatcher matcher = new IdentifierEObjectMatcher(contentMatcher);
DefaultMatchEngine matchEngine = new DefaultMatchEngine(matcher);
final IComparisonScope scope = new DefaultComparisonScope(left, right, origin);
@@ -82,7 +81,7 @@ public class MatchPerformanceComparisonTest { @Test
public void matchPerContentAlmostIdenticalModels() throws IOException {
final IEObjectMatcher contentMatcher = ProximityEObjectMatcher.builder(
- EditionDistance.builder(new EqualityHelper()).build()).build();
+ EditionDistance.builder().build()).build();
DefaultMatchEngine matchEngine = new DefaultMatchEngine(contentMatcher);
final IComparisonScope scope = new DefaultComparisonScope(left, right, origin);
for (int i = 0; i < nbIterations; i++) {
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/EMFCompare.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/EMFCompare.java index 41767d0a3..fe9a01724 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/EMFCompare.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/EMFCompare.java @@ -374,7 +374,7 @@ public final class EMFCompare { final IEObjectMatcher matcher;
switch (useIDs) {
case NEVER:
- matcher = ProximityEObjectMatcher.builder(EditionDistance.builder(helper).build()).build();
+ matcher = ProximityEObjectMatcher.builder(EditionDistance.builder().build()).build();
break;
case ONLY:
matcher = new IdentifierEObjectMatcher();
@@ -384,7 +384,7 @@ public final class EMFCompare { default:
// Use an ID matcher, delegating to proximity when no ID is available
final IEObjectMatcher contentMatcher = ProximityEObjectMatcher.builder(
- EditionDistance.builder(helper).build()).build();
+ EditionDistance.builder().build()).build();
matcher = new IdentifierEObjectMatcher(contentMatcher);
break;
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java index 577552c16..0d79b5c89 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java @@ -86,13 +86,32 @@ public class EditionDistance implements DistanceFunction { /**
* Instanciate a new Edition Distance using the given equality helper.
- *
- * @param equalityHelper
- * the equality helper to use.
*/
- public EditionDistance(EqualityHelper equalityHelper) {
+ public EditionDistance() {
weights = Maps.newHashMap();
- this.helper = equalityHelper;
+ this.helper = new EqualityHelper() {
+
+ @Override
+ protected boolean matchingEObjects(Comparison comparison, EObject object1, EObject object2) {
+ final Match match = comparison.getMatch(object1);
+
+ final boolean equal;
+ // Match could be null if the value is out of the scope
+ if (match != null) {
+ equal = match.getLeft() == object2 || match.getRight() == object2
+ || match.getOrigin() == object2;
+ } else {
+ /*
+ * use a temporary variable as buffer for the "equal" boolean. We know that the following
+ * try/catch block can, and will, only initialize it once ... but the compiler does not.
+ */
+ equal = uriDistance.proximity(object1, object2) == 0;
+ }
+
+ return equal;
+ }
+
+ };
this.toBeIgnored = Sets.newLinkedHashSet();
}
@@ -106,12 +125,10 @@ public class EditionDistance implements DistanceFunction { /**
* Create a new builder to instanciate and configure an EditionDistance.
*
- * @param helper
- * the equality helper (required to instanciate an EditionDistance).
* @return a configuration builder.
*/
- public static Builder builder(EqualityHelper helper) {
- return new Builder(helper);
+ public static Builder builder() {
+ return new Builder();
}
/**
@@ -125,12 +142,9 @@ public class EditionDistance implements DistanceFunction { /**
* Create the builder.
- *
- * @param toBe
- * the equality helper (required to instanciate an EditionDistance).
*/
- public Builder(EqualityHelper toBe) {
- this.toBeBuilt = new EditionDistance(toBe);
+ public Builder() {
+ this.toBeBuilt = new EditionDistance();
}
/**
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/URIDistance.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/URIDistance.java index 7e0a29a6b..02ab775bb 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/URIDistance.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/URIDistance.java @@ -34,84 +34,73 @@ import org.eclipse.emf.ecore.util.FeatureMap; * * @author <a href="mailto:cedric.brun@obeo.fr">Cedric Brun</a> */ -public class URIDistance { +public class URIDistance implements Function<EObject, List<String>> { + /** - * Function computing the location of each EObject. + * A computing cache for the locations. */ - private EObjectToLocation eObjToLoc = new EObjectToLocation(); + private Cache<EObject, List<String>> locationCache = CacheBuilder.newBuilder().maximumSize(1000).build( + CacheLoader.from(this)); /** - * This is the function that will be used by our {@link #uriCache} to compute its values. + * {@inheritDoc} * - * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a> + * @see com.google.common.base.Function#apply(java.lang.Object) */ - private static class EObjectToLocation implements Function<EObject, List<String>> { - /** - * A computing cache for the locations. - */ - private Cache<EObject, List<String>> locationCache = CacheBuilder.newBuilder().maximumSize(1000) - .build(CacheLoader.from(this)); - - /** - * {@inheritDoc} - * - * @see com.google.common.base.Function#apply(java.lang.Object) - */ - public List<String> apply(EObject input) { - if (input == null) { - return null; - } - EObject cur = input; - EObject container = input.eContainer(); - Builder<String> builder = ImmutableList.builder(); - if (container != null) { - builder.addAll(locationCache.getUnchecked(container)); - EStructuralFeature feat = cur.eContainingFeature(); - if (feat != null) { - if (feat instanceof EAttribute) { - featureMapLocation(builder, cur, container, feat); + public List<String> apply(EObject input) { + if (input == null) { + return null; + } + EObject cur = input; + EObject container = input.eContainer(); + Builder<String> builder = ImmutableList.builder(); + if (container != null) { + builder.addAll(locationCache.getUnchecked(container)); + EStructuralFeature feat = cur.eContainingFeature(); + if (feat != null) { + if (feat instanceof EAttribute) { + featureMapLocation(builder, cur, container, feat); + } else { + if (feat.isMany()) { + EList<?> eList = (EList<?>)container.eGet(feat, false); + int index = eList.indexOf(cur); + builder.add(feat.getName()); + builder.add(Integer.valueOf(index).toString()); } else { - if (feat.isMany()) { - EList<?> eList = (EList<?>)container.eGet(feat, false); - int index = eList.indexOf(cur); - builder.add(feat.getName()); - builder.add(Integer.valueOf(index).toString()); - } else { - builder.add(feat.getName()); - builder.add("0"); - } + builder.add(feat.getName()); + builder.add("0"); } - } - } else { - builder.add("0"); - } - return builder.build(); + } + } else { + builder.add("0"); } - /** - * Update the builder with location hints for a feature map. - * - * @param builder - * the list builder to update. - * @param cur - * the current object. - * @param container - * the current object container. - * @param feat - * the containing feature of the current object. - */ - protected void featureMapLocation(Builder<String> builder, EObject cur, EObject container, - EStructuralFeature feat) { - FeatureMap featureMap = (FeatureMap)container.eGet(feat, false); - for (int i = 0, size = featureMap.size(); i < size; ++i) { - if (featureMap.getValue(i) == cur) { - EStructuralFeature entryFeature = featureMap.getEStructuralFeature(i); - if (entryFeature instanceof EReference && ((EReference)entryFeature).isContainment()) { - builder.add(feat.getName()); - builder.add(Integer.valueOf(i).toString()); - } + return builder.build(); + } + + /** + * Update the builder with location hints for a feature map. + * + * @param builder + * the list builder to update. + * @param cur + * the current object. + * @param container + * the current object container. + * @param feat + * the containing feature of the current object. + */ + protected void featureMapLocation(Builder<String> builder, EObject cur, EObject container, + EStructuralFeature feat) { + FeatureMap featureMap = (FeatureMap)container.eGet(feat, false); + for (int i = 0, size = featureMap.size(); i < size; ++i) { + if (featureMap.getValue(i) == cur) { + EStructuralFeature entryFeature = featureMap.getEStructuralFeature(i); + if (entryFeature instanceof EReference && ((EReference)entryFeature).isContainment()) { + builder.add(feat.getName()); + builder.add(Integer.valueOf(i).toString()); } } } @@ -180,7 +169,7 @@ public class URIDistance { * @return The number of changes to transform one uri to another one. */ public int proximity(EObject a, EObject b) { - return proximity(eObjToLoc.apply(a), eObjToLoc.apply(b)); + return proximity(apply(a), apply(b)); } } diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EqualityHelper.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EqualityHelper.java index d470238ef..9c7d35407 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EqualityHelper.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EqualityHelper.java @@ -126,7 +126,7 @@ public class EqualityHelper { * @return <code>true</code> if these two EObjects are to be considered equal, <code>false</code>
* otherwise.
*/
- private boolean matchingEObjects(Comparison comparison, EObject object1, EObject object2) {
+ protected boolean matchingEObjects(Comparison comparison, EObject object1, EObject object2) {
final Match match = comparison.getMatch(object1);
final boolean equal;
|