Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java7
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/MatchUtilFeatureContainsTest.java95
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/MatchUtil.java48
3 files changed, 145 insertions, 5 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
index 20767fe68..5ea30df1d 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2015 Obeo.
+ * Copyright (c) 2012, 2015 Obeo and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* Obeo - initial API and implementation
* Philip Langer - Adds additional test classes
* Stefan Dirix - Adds additional test classes
+ * Michael Borkowski - Adds additional test classes
*******************************************************************************/
package org.eclipse.emf.compare.tests.suite;
@@ -60,6 +61,7 @@ import org.eclipse.emf.compare.tests.rcp.AllRCPTests;
import org.eclipse.emf.compare.tests.req.ReqComputingTest;
import org.eclipse.emf.compare.tests.scope.DefaultComparisonScopeTest;
import org.eclipse.emf.compare.tests.utils.EqualityHelperTest;
+import org.eclipse.emf.compare.tests.utils.MatchUtilFeatureContainsTest;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.junit.BeforeClass;
@@ -86,7 +88,8 @@ import org.junit.runners.Suite.SuiteClasses;
FeatureMapsPseudoConflictsMergeTest.class, TwoWayBatchMergingTest.class, EqualityHelperTest.class,
FeatureFilterTest.class, ThreeWayBatchMergingTest.class,
MultiLineAttributeConflictDetectionTest.class, ThreeWayTextDiffTest.class,
- MultiLineAttributeMergeTest.class, MonitorCancelTest.class, IdentifierEObjectMatcherTest.class })
+ MultiLineAttributeMergeTest.class, MonitorCancelTest.class, IdentifierEObjectMatcherTest.class,
+ MatchUtilFeatureContainsTest.class })
public class AllTests {
/**
* Standalone launcher for all of compare's tests.
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/MatchUtilFeatureContainsTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/MatchUtilFeatureContainsTest.java
new file mode 100644
index 000000000..f46559d4d
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/MatchUtilFeatureContainsTest.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2015 EclipseSource Muenchen GmbH.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Michael Borkowski - initial tests
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.utils;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.compare.utils.MatchUtil;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings({"boxing", "nls" })
+public class MatchUtilFeatureContainsTest {
+
+ List<EObject> featureList;
+
+ InternalEObject value;
+
+ EObject container;
+
+ EClass eClass;
+
+ EStructuralFeature feature;
+
+ @Before
+ public void setUp() {
+ EPackage ePackage = mock(EPackage.class);
+
+ container = mock(EObject.class);
+ feature = mock(EStructuralFeature.class);
+
+ eClass = mock(EClass.class);
+ when(eClass.getEPackage()).thenReturn(ePackage);
+
+ when(container.eClass()).thenReturn(eClass);
+ when(feature.getEContainingClass()).thenReturn(eClass);
+
+ featureList = new LinkedList<EObject>();
+ when(container.eGet(feature, false)).thenReturn(featureList);
+
+ value = mockInternalObject();
+ featureList.add(value);
+ }
+
+ @Test
+ public void test_SameObject() {
+ assertTrue(MatchUtil.featureContains(container, feature, value));
+ }
+
+ @Test
+ public void test_Proxy() {
+ URI uri = URI.createFileURI("/my/path");
+
+ InternalEObject proxyValue = mockInternalObject();
+ when(proxyValue.eIsProxy()).thenReturn(true);
+ when(proxyValue.eProxyURI()).thenReturn(uri);
+
+ when(value.eIsProxy()).thenReturn(true);
+ when(value.eProxyURI()).thenReturn(uri);
+
+ assertTrue(MatchUtil.featureContains(container, feature, proxyValue));
+ }
+
+ @Test
+ public void test_DifferentObject() {
+ InternalEObject otherValue = mockInternalObject();
+
+ assertFalse(MatchUtil.featureContains(container, feature, otherValue));
+ }
+
+ private InternalEObject mockInternalObject() {
+ InternalEObject internalObject = mock(InternalEObject.class);
+ when(internalObject.eClass()).thenReturn(eClass);
+ return internalObject;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/MatchUtil.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/MatchUtil.java
index d1a05531e..77854875b 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/MatchUtil.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/MatchUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * Copyright (c) 2012, 2015 Obeo and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,11 +7,13 @@
*
* Contributors:
* Obeo - initial API and implementation
+ * Michael Borkowski - bug 467576
*******************************************************************************/
package org.eclipse.emf.compare.utils;
import static org.eclipse.emf.compare.utils.ReferenceUtil.getAsList;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.AttributeChange;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
@@ -23,6 +25,7 @@ import org.eclipse.emf.compare.util.CompareSwitch;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.EcoreUtil;
/**
* This utility class holds methods that will be used by the diff and merge processes.
@@ -149,7 +152,7 @@ public final class MatchUtil {
throw new IllegalArgumentException();
}
if (source == DifferenceSource.LEFT) {
- if (getAsList(match.getLeft(), feature).contains(value)) {
+ if (featureContains(match.getLeft(), feature, value)) {
result = match.getLeft();
} else if (comparison.isThreeWay()) {
result = match.getOrigin();
@@ -157,7 +160,7 @@ public final class MatchUtil {
result = match.getRight();
}
} else {
- if (getAsList(match.getRight(), feature).contains(value)) {
+ if (featureContains(match.getRight(), feature, value)) {
result = match.getRight();
} else if (comparison.isThreeWay()) {
result = match.getOrigin();
@@ -174,6 +177,45 @@ public final class MatchUtil {
}
/**
+ * Determines whether the given feature of the given {@link EObject} contains the provided value, while
+ * correctly handling proxies (in other words, in case of proxies, the proxy URI is compared instead of
+ * the objects, which would otherwise lead to false negatives).
+ *
+ * @param eObject
+ * The object of which a feature is to be checked
+ * @param feature
+ * The feature of which containment is to be checked
+ * @param value
+ * The value which is to be verified in the feature
+ * @return <code>true</code> if the feature contains the given value
+ */
+ // public for testing
+ public static boolean featureContains(EObject eObject, EStructuralFeature feature, Object value) {
+ URI proxyUri = null;
+ if (value instanceof EObject) {
+ EObject eObjectValue = (EObject)value;
+ proxyUri = EcoreUtil.getURI(eObjectValue);
+ }
+
+ for (Object element : getAsList(eObject, feature)) {
+ if (element == value) {
+ return true;
+ }
+ if (element != null && element.equals(value)) {
+ return true;
+ }
+ if (proxyUri != null && element instanceof EObject) {
+ EObject eObjectElement = (EObject)element;
+ if (eObjectElement.eIsProxy() && EcoreUtil.getURI(eObjectElement).equals(proxyUri)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
* Get the value of any difference.
*
* @param input

Back to the top