Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Goubet2017-06-06 05:30:50 -0400
committerLaurent Goubet2017-06-06 09:17:31 -0400
commitce535306d74529bddffcc05894c98abff8c594a4 (patch)
treeaf4544d65bc864f7f20d9b73a48bf659294152b7
parentbef5a41577c7f5ebe5a0034de268877900ded2fc (diff)
downloadorg.eclipse.emf.compare-ce535306d74529bddffcc05894c98abff8c594a4.tar.gz
org.eclipse.emf.compare-ce535306d74529bddffcc05894c98abff8c594a4.tar.xz
org.eclipse.emf.compare-ce535306d74529bddffcc05894c98abff8c594a4.zip
Revert "Use more efficient feature look-up in ReferenceUtil"
This reverts commit 888d9a60c302d4519bf01f088d0c22b585cff675. Reverted for security as this is too bug-prone for a RC build. Change-Id: I4a3a949bbb6ddb69db1cc66d8cfd3147acc37272
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/utils/MatchUtilFeatureContainsTest.java14
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/ReferenceUtil.java58
2 files changed, 29 insertions, 43 deletions
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
index a905457db..f46559d4d 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015, 2017 EclipseSource Muenchen GmbH and others.
+ * 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
@@ -7,7 +7,6 @@
*
* Contributors:
* Michael Borkowski - initial tests
- * Philip Langer - bug 516524
*******************************************************************************/
package org.eclipse.emf.compare.tests.utils;
@@ -32,13 +31,11 @@ import org.junit.Test;
@SuppressWarnings({"boxing", "nls" })
public class MatchUtilFeatureContainsTest {
- private static final int MOCK_FEATURE_ID = 1;
-
List<EObject> featureList;
InternalEObject value;
- InternalEObject container;
+ EObject container;
EClass eClass;
@@ -48,20 +45,17 @@ public class MatchUtilFeatureContainsTest {
public void setUp() {
EPackage ePackage = mock(EPackage.class);
- container = mock(InternalEObject.class);
-
+ container = mock(EObject.class);
feature = mock(EStructuralFeature.class);
- when(feature.isMany()).thenReturn(true);
eClass = mock(EClass.class);
when(eClass.getEPackage()).thenReturn(ePackage);
- when(eClass.getFeatureID(feature)).thenReturn(MOCK_FEATURE_ID);
when(container.eClass()).thenReturn(eClass);
when(feature.getEContainingClass()).thenReturn(eClass);
featureList = new LinkedList<EObject>();
- when(container.eGet(MOCK_FEATURE_ID, false, true)).thenReturn(featureList);
+ when(container.eGet(feature, false)).thenReturn(featureList);
value = mockInternalObject();
featureList.add(value);
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/ReferenceUtil.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/ReferenceUtil.java
index 488b724a2..7fe6bd1b0 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/ReferenceUtil.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/ReferenceUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2017 Obeo and others.
+ * Copyright (c) 2012, 2014 Obeo.
* 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,7 +7,6 @@
*
* Contributors:
* Obeo - initial API and implementation
- * Philip Langer - bug 516524
*******************************************************************************/
package org.eclipse.emf.compare.utils;
@@ -22,7 +21,6 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
-import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.ExtendedMetaData;
import org.eclipse.emf.ecore.util.FeatureMapUtil;
@@ -89,8 +87,14 @@ public final class ReferenceUtil {
* @return The value of the given {@code feature} for the given {@code object}.
*/
public static Object safeEGet(EObject object, EStructuralFeature feature) {
- final int featureID = getFeatureID(feature, object.eClass());
- return ((InternalEObject)object).eGet(featureID, false, true);
+ final EClass clazz = object.eClass();
+ // TODO profile. This "if" might be counter productive : accessing both packages is probably as long
+ // as a direct lookup to the clazz.eGetEStructuralFeature...
+ if (clazz.getEPackage() == feature.getEContainingClass().getEPackage()) {
+ return object.eGet(feature, false);
+ }
+ // Assumes that the containing package is the same, let it fail otherwise
+ return object.eGet(clazz.getEStructuralFeature(feature.getName()), false);
}
/**
@@ -105,8 +109,14 @@ public final class ReferenceUtil {
* @return whether the {@code feature} for the given {@code object} is set.
*/
public static boolean safeEIsSet(EObject object, EStructuralFeature feature) {
- int featureID = getFeatureID(feature, object.eClass());
- return ((InternalEObject)object).eIsSet(featureID);
+ final EClass clazz = object.eClass();
+ // TODO profile. This "if" might be counter productive : accessing both packages is probably as long
+ // as a direct lookup to the clazz.eGetEStructuralFeature...
+ if (clazz.getEPackage() == feature.getEContainingClass().getEPackage()) {
+ return object.eIsSet(feature);
+ }
+ // Assumes that the containing package is the same, let it fail otherwise
+ return object.eIsSet(clazz.getEStructuralFeature(feature.getName()));
}
/**
@@ -122,33 +132,15 @@ public final class ReferenceUtil {
* The value to set, can be <code>null</code>.
*/
public static void safeESet(EObject object, EStructuralFeature feature, Object newValue) {
- int featureID = getFeatureID(feature, object.eClass());
- ((InternalEObject)object).eSet(featureID, newValue);
- }
-
- /**
- * Returns the ID of the given <code>feature</code> relative to the given <code>eClass</code>.
- * <p>
- * If the feature ID could not be found in <code>eClass</code> directly, this method will try find a
- * feature in <code>eClass</code> with the same name as the given <code>feature</code> and return its
- * feature ID. Otherwise, this method returns -1. , or -1 if the feature is not in this class.
- * </p>
- *
- * @param feature
- * The feature.
- * @param eClass
- * The class.
- * @return The ID of the <code>feature</code> relative to <code>class</code>, or -1 if the feature or an
- * equally named feature is not in <code>clazz</code>.
- */
- private static int getFeatureID(EStructuralFeature feature, final EClass eClass) {
- int featureID = eClass.getFeatureID(feature);
- if (featureID == -1) {
- // We may have a different but equivalent EClass, so try find the feature with the same name and
- // compute the feature ID for that.
- featureID = eClass.getFeatureID(eClass.getEStructuralFeature(feature.getName()));
+ final EClass clazz = object.eClass();
+ // TODO profile. This "if" might be counter productive : accessing both packages is probably as long
+ // as a direct lookup to the clazz.eGetEStructuralFeature...
+ if (clazz.getEPackage() == feature.getEContainingClass().getEPackage()) {
+ object.eSet(feature, newValue);
+ } else {
+ // Assumes that the containing package is the same, let it fail otherwise
+ object.eSet(clazz.getEStructuralFeature(feature.getName()), newValue);
}
- return featureID;
}
/**

Back to the top