Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2012-07-31 12:20:00 +0000
committervlorenzo2012-07-31 12:20:00 +0000
commitf9e0a7e12d3803f86e865b5c6e1f6f854693da7a (patch)
treee6f3211d572784fa107da7dfbfe58d4e91a7c2b1 /extraplugins
parent5ef8b2a0008fb8baa5f386f9f3d357a8e34775dc (diff)
downloadorg.eclipse.papyrus-f9e0a7e12d3803f86e865b5c6e1f6f854693da7a.tar.gz
org.eclipse.papyrus-f9e0a7e12d3803f86e865b5c6e1f6f854693da7a.tar.xz
org.eclipse.papyrus-f9e0a7e12d3803f86e865b5c6e1f6f854693da7a.zip
386219: [UML Compare] The API should provides the following possibilities
https://bugs.eclipse.org/bugs/show_bug.cgi?id=386219 Commit to support the following options : declared features that should be ignored during the comparison. - currently it doesn't work for ModelElementChangeLeft/Right - not JUnit test are provided, but current tests continue to work fine!
Diffstat (limited to 'extraplugins')
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/META-INF/MANIFEST.MF1
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/FeaturesCheck.java101
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/IFeaturesCheck.java45
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/PapyrusAttributesCheck.java129
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/PapyrusReferencesCheck.java148
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/utils/PapyrusCompareOptions.java21
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/check/PapyrusUML2ReferencesCheck.java64
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/services/nested/NestedMergeUtils.java4
-rw-r--r--extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/services/standalone/UMLStandaloneDiffEngine.java57
9 files changed, 560 insertions, 10 deletions
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/META-INF/MANIFEST.MF b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/META-INF/MANIFEST.MF
index 26a1b5e02ed..d9bc2d846d6 100644
--- a/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/META-INF/MANIFEST.MF
+++ b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/META-INF/MANIFEST.MF
@@ -22,6 +22,7 @@ Require-Bundle: org.eclipse.ui,
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.papyrus.infra.emf.compare.diff,
+ org.eclipse.papyrus.infra.emf.compare.diff.check,
org.eclipse.papyrus.infra.emf.compare.diff.internal.command,
org.eclipse.papyrus.infra.emf.compare.diff.internal.merger,
org.eclipse.papyrus.infra.emf.compare.diff.internal.provider,
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/FeaturesCheck.java b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/FeaturesCheck.java
new file mode 100644
index 00000000000..45b3ef008e1
--- /dev/null
+++ b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/FeaturesCheck.java
@@ -0,0 +1,101 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.compare.diff.check;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.compare.diff.engine.IMatchManager;
+import org.eclipse.emf.compare.diff.engine.check.AbstractCheck;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.papyrus.infra.emf.compare.diff.utils.PapyrusCompareOptions;
+
+/**
+ *
+ * This checker allow to know if differences on a feature should be ignored or not
+ *
+ */
+public class FeaturesCheck extends AbstractCheck implements IFeaturesCheck{
+
+ /**
+ * The list of the features that should be ignored in the whole diff
+ */
+ private final List<EStructuralFeature> ignoreAll;
+
+ /**
+ * the list of the features that should be ignored for some EObject
+ */
+ private final Map<EStructuralFeature, List<EObject>> ignoreSomeCase;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param manager
+ * @param options
+ */
+ @SuppressWarnings("unchecked")
+ //cast on List and Map
+ public FeaturesCheck(final IMatchManager manager, final Map<String, Object> options) {
+ super(manager);
+
+ if(options != null && options.containsKey(PapyrusCompareOptions.KEY_IGNORE_ALL_CHANGES_ON_FEATURES)) {
+ this.ignoreAll = (List<EStructuralFeature>)options.get(PapyrusCompareOptions.KEY_IGNORE_ALL_CHANGES_ON_FEATURES);
+ } else {
+ this.ignoreAll = Collections.EMPTY_LIST;
+ }
+ if(options != null && options.containsKey(PapyrusCompareOptions.KEY_IGNORE_CHANGES_ON_FEATURES_FOR)) {
+ this.ignoreSomeCase = (Map<EStructuralFeature, List<EObject>>)options.get(PapyrusCompareOptions.KEY_IGNORE_CHANGES_ON_FEATURES_FOR);
+ } else {
+ this.ignoreSomeCase = Collections.EMPTY_MAP;
+ }
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param manager
+ */
+ public FeaturesCheck(final IMatchManager manager) {
+ this(manager, null);
+ }
+
+ /**
+ * This method is used to know if a feature should always be ignored
+ *
+ * @param feature
+ * @return
+ */
+ public boolean shouldBeIgnored(final EStructuralFeature feature) {
+ return this.ignoreAll.contains(feature);
+ }
+
+ /**
+ * This method allows to know if a feature should be ignored in specific case (depends on the eobject)
+ *
+ * @param feature
+ * @param eobject
+ * @return
+ */
+ public boolean shouldBeIgnored(final EStructuralFeature feature, final EObject eobject) {
+ final List<EObject> values = this.ignoreSomeCase.get(feature);
+ if(values != null) {
+ return values.contains(eobject);
+ }
+ return false;
+ }
+}
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/IFeaturesCheck.java b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/IFeaturesCheck.java
new file mode 100644
index 00000000000..7ad0443c4a3
--- /dev/null
+++ b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/IFeaturesCheck.java
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.compare.diff.check;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+/**
+ *
+ * This interface allows to define checker enable to ignore differences following the context
+ *
+ */
+public interface IFeaturesCheck {
+
+ /**
+ * return <code>true</code> if the feature should be ignored
+ *
+ * @param feature
+ * @return
+ */
+ public boolean shouldBeIgnored(final EStructuralFeature feature);
+
+ /**
+ * return <code>true</code> if the feature should be ignored in this context
+ *
+ * @param feature
+ * a feature
+ * @param context
+ * the context of this attribute
+ * @return
+ */
+ public boolean shouldBeIgnored(final EStructuralFeature feature, final EObject context);
+
+}
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/PapyrusAttributesCheck.java b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/PapyrusAttributesCheck.java
new file mode 100644
index 00000000000..0d26a03b002
--- /dev/null
+++ b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/PapyrusAttributesCheck.java
@@ -0,0 +1,129 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.compare.diff.check;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.compare.FactoryException;
+import org.eclipse.emf.compare.diff.engine.IMatchManager;
+import org.eclipse.emf.compare.diff.engine.check.AttributesCheck;
+import org.eclipse.emf.compare.diff.metamodel.DiffElement;
+import org.eclipse.emf.compare.diff.metamodel.DiffGroup;
+import org.eclipse.emf.compare.match.metamodel.Match2Elements;
+import org.eclipse.emf.compare.match.metamodel.Match3Elements;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+
+
+public class PapyrusAttributesCheck extends AttributesCheck {
+
+ /**
+ * a checker used to manage diff configuration
+ */
+ private final FeaturesCheck checker;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param matchManager
+ * @param featuresCheck
+ * the checker used to manage diff configuration
+ */
+ public PapyrusAttributesCheck(final IMatchManager matchManager, final FeaturesCheck featuresCheck) {
+ super(matchManager);
+ this.checker = featuresCheck;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.diff.engine.check.AttributesCheck#shouldBeIgnored(org.eclipse.emf.ecore.EAttribute)
+ *
+ * @param attribute
+ * @return
+ */
+ @Override
+ protected boolean shouldBeIgnored(final EAttribute attribute) {
+ boolean shouldBeIgnored = super.shouldBeIgnored(attribute);
+ return shouldBeIgnored || this.checker.shouldBeIgnored(attribute);
+ }
+
+ /**
+ * return <code>true</code> if the attribute should be ignored in this context
+ *
+ * @param attribute
+ * an attribute
+ * @param context
+ * the context of this attribute
+ * @return
+ */
+ protected boolean shouldBeIgnored(final EAttribute attribute, final EObject context) {
+ return this.checker.shouldBeIgnored(attribute, context);
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.diff.engine.check.AttributesCheck#checkAttributesUpdates(org.eclipse.emf.compare.diff.metamodel.DiffGroup, org.eclipse.emf.compare.match.metamodel.Match2Elements)
+ *
+ * @param root
+ * @param mapping
+ * @throws FactoryException
+ */
+ @Override
+ public void checkAttributesUpdates(DiffGroup root, Match2Elements mapping) throws FactoryException {
+ final EClass eClass = mapping.getLeftElement().eClass();
+
+ final List<EAttribute> eclassAttributes = eClass.getEAllAttributes();
+ // for each feature, compare the value
+ final Iterator<EAttribute> it = eclassAttributes.iterator();
+ while(it.hasNext()) {
+ final EAttribute next = it.next();
+ if(!shouldBeIgnored(next) && !shouldBeIgnored(next, mapping.getLeftElement())) {
+ checkAttributeUpdates(root, mapping, next);
+ }
+ }
+ }
+
+ /**
+ * This will iterate through all the attributes of the <code>mapping</code>'s three elements to check if
+ * any of them has been modified.
+ *
+ * @param root
+ * {@link DiffGroup root} of the {@link DiffElement} to create if one of the attribute has
+ * actually been changed.
+ * @param mapping
+ * This contains the mapping information about the elements we need to check for a move.
+ * @throws FactoryException
+ * Thrown if one of the checks fails.
+ */
+ public void checkAttributesUpdates(DiffGroup root, Match3Elements mapping) throws FactoryException {
+ // Ignores matchElements when they don't have origin (no updates on
+ // these)
+ if(mapping.getOriginElement() == null)
+ return;
+ final EClass eClass = mapping.getOriginElement().eClass();
+
+ final List<EAttribute> eclassAttributes = eClass.getEAllAttributes();
+ // for each feature, compare the value
+ final Iterator<EAttribute> it = eclassAttributes.iterator();
+ while(it.hasNext()) {
+ final EAttribute next = it.next();
+ if(!shouldBeIgnored(next) && !shouldBeIgnored(next, mapping.getOriginElement())) {
+ checkAttributeUpdates(root, mapping, next);
+ }
+ }
+ }
+}
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/PapyrusReferencesCheck.java b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/PapyrusReferencesCheck.java
new file mode 100644
index 00000000000..ffc1b8a14d3
--- /dev/null
+++ b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/check/PapyrusReferencesCheck.java
@@ -0,0 +1,148 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.compare.diff.check;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.compare.FactoryException;
+import org.eclipse.emf.compare.diff.engine.IMatchManager;
+import org.eclipse.emf.compare.diff.engine.check.ReferencesCheck;
+import org.eclipse.emf.compare.diff.metamodel.DiffElement;
+import org.eclipse.emf.compare.diff.metamodel.DiffGroup;
+import org.eclipse.emf.compare.match.metamodel.Match2Elements;
+import org.eclipse.emf.compare.match.metamodel.Match3Elements;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+
+/**
+ *
+ * This reference checker allows to ignore differences on features for the comparison
+ *
+ */
+public class PapyrusReferencesCheck extends ReferencesCheck {
+
+ /**
+ * the checker used to take in account the ignored features for the Diff
+ */
+ private final FeaturesCheck checker;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param matchManager
+ * @param checker
+ * the checker used to take in account the ignored features for the Diff
+ */
+ public PapyrusReferencesCheck(final IMatchManager matchManager, final FeaturesCheck checker) {
+ super(matchManager);
+ this.checker = checker;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.compare.diff.engine.check.ReferencesCheck#shouldBeIgnored(org.eclipse.emf.ecore.EReference)
+ *
+ * @param reference
+ * @return
+ */
+ @Override
+ protected boolean shouldBeIgnored(final EReference reference) {
+ boolean shouldBeIgnored = super.shouldBeIgnored(reference);
+ return shouldBeIgnored || this.checker.shouldBeIgnored(reference);
+ }
+
+ /**
+ * return <code>true</code> if the attribute should be ignored in this context
+ *
+ * @param reference
+ * a reference
+ * @param context
+ * the context of this reference
+ * @return
+ */
+ protected boolean shouldBeIgnored(final EReference reference, final EObject context) {
+ return this.checker.shouldBeIgnored(reference, context);
+ }
+
+ /**
+ * Checks if there's been references updates in the model.<br/>
+ * <p>
+ * A reference is considered updated if its value(s) has been changed (either removal or addition of an element if the reference is multi-valued
+ * or update of a single-valued reference) between the left and the right model.
+ * </p>
+ *
+ * @param root
+ * {@link DiffGroup root} of the {@link DiffElement} to create.
+ * @param mapping
+ * Contains informations about the left and right model elements we have to compare.
+ * @throws FactoryException
+ * Thrown if we cannot fetch the references' values.
+ */
+ public void checkReferencesUpdates(DiffGroup root, Match2Elements mapping) throws FactoryException {
+ final EClass eClass = mapping.getLeftElement().eClass();
+ final List<EReference> eclassReferences = eClass.getEAllReferences();
+
+ final Iterator<EReference> it = eclassReferences.iterator();
+ while(it.hasNext()) {
+ final EReference next = it.next();
+ if(!shouldBeIgnored(next, mapping.getLeftElement())) {
+ if(!shouldBeIgnored(next)) {
+ checkReferenceUpdates(root, mapping, next);
+ } else if(next.isContainment() && next.isOrdered()) {
+ checkContainmentReferenceOrderChange(root, mapping, next);
+ }
+ }
+ }
+ }
+
+ /**
+ * Checks if there's been references updates in the model.<br/>
+ * <p>
+ * A reference is considered updated if its value(s) has been changed (either removal or addition of an element if the reference is multi-valued
+ * or update of a single-valued reference) between the left and the ancestor model, the right and the ancestor or between the left and the right
+ * model.
+ * </p>
+ *
+ * @param root
+ * {@link DiffGroup root} of the {@link DiffElement} to create.
+ * @param mapping
+ * Contains informations about the left, right and origin model elements we have to compare.
+ * @throws FactoryException
+ * Thrown if we cannot fetch the references' values.
+ */
+ public void checkReferencesUpdates(DiffGroup root, Match3Elements mapping) throws FactoryException {
+ // Ignores matchElements when they don't have origin (no updates on these)
+ if(mapping.getOriginElement() == null)
+ return;
+ final EClass eClass = mapping.getOriginElement().eClass();
+ final List<EReference> eclassReferences = eClass.getEAllReferences();
+
+ final Iterator<EReference> it = eclassReferences.iterator();
+ while(it.hasNext()) {
+ final EReference next = it.next();
+ if(!shouldBeIgnored(next, mapping.getLeftElement())) {
+ if(!shouldBeIgnored(next)) {
+ checkReferenceUpdates(root, mapping, next);
+ } else if(next.isContainment() && next.isOrdered()) {
+ checkContainmentReferenceOrderChange(root, mapping, next);
+ }
+ }
+ }
+ }
+
+
+}
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/utils/PapyrusCompareOptions.java b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/utils/PapyrusCompareOptions.java
index b8ff671a5df..fcbb24040c8 100644
--- a/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/utils/PapyrusCompareOptions.java
+++ b/extraplugins/uml/compare/org.eclipse.papyrus.infra.emf.compare.diff/src/org/eclipse/papyrus/infra/emf/compare/diff/utils/PapyrusCompareOptions.java
@@ -16,7 +16,7 @@ package org.eclipse.papyrus.infra.emf.compare.diff.utils;
/**
*
* This class provides the keys for options managed by Papyrus Compare
- *
+ *
*/
public class PapyrusCompareOptions {
@@ -30,13 +30,24 @@ public class PapyrusCompareOptions {
public static final String KEY_ALLOW_MERGE_LEFT_TO_RIGHT = "allow_merge_left_to_right"; //$NON-NLS-1$
public static final String KEY_ALLOW_UNDO_IN_TARGET = KEY_ALLOW_MERGE_LEFT_TO_RIGHT;
-
+
/**
* the keys to define the merge from right to left is enabled or not
*/
public static final String KEY_ALLOW_MERGE_RIGHT_TO_LEFT = "allow_merge_right_to_left"; //$NON-NLS-1$
-
- public static final String KEY_ALLOW_APPLY_IN_ORIGIN = KEY_ALLOW_MERGE_RIGHT_TO_LEFT;
-
+
+ public static final String KEY_ALLOW_APPLY_IN_ORIGIN = KEY_ALLOW_MERGE_RIGHT_TO_LEFT;
+
+ /**
+ * this key allows to ignore all changes on features
+ * the value associated to this key must be a list of EStructuralFeature to ignore
+ */
+ public static final String KEY_IGNORE_ALL_CHANGES_ON_FEATURES = "ignore_all_changes_on_features";
+
+ /**
+ * this key allows to define features changes to ignore for some elements
+ * the value linked to this key should be a Map<EStructuralFeature, List<EObject>>
+ */
+ public static final String KEY_IGNORE_CHANGES_ON_FEATURES_FOR = "ignore_changes_on_features_for";
}
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/check/PapyrusUML2ReferencesCheck.java b/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/check/PapyrusUML2ReferencesCheck.java
new file mode 100644
index 00000000000..65a8d9050ba
--- /dev/null
+++ b/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/check/PapyrusUML2ReferencesCheck.java
@@ -0,0 +1,64 @@
+package org.eclipse.papyrus.uml.compare.diff.check;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.eclipse.emf.compare.diff.engine.IMatchManager;
+import org.eclipse.emf.compare.uml2.diff.UML2DiffEngine;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.papyrus.infra.emf.compare.diff.check.FeaturesCheck;
+import org.eclipse.papyrus.infra.emf.compare.diff.check.PapyrusReferencesCheck;
+
+//adapted code from EMF-Compare UML2ReferencesCheck
+public class PapyrusUML2ReferencesCheck extends PapyrusReferencesCheck {
+
+
+
+ /**
+ * Parameters.
+ */
+ private static final String SUBSETS_OF_CONTAINMENT_PROPERTIES = "/org/eclipse/emf/compare/uml2/diff/internal/subsets.of.containment.properties"; //$NON-NLS-1$
+
+ /**
+ * Properties for parameters.
+ */
+ private static final Properties SUBSETS_OF_CONTAINMENT = new Properties();
+
+ static {
+ try {
+ SUBSETS_OF_CONTAINMENT.load(UML2DiffEngine.class.getResourceAsStream(SUBSETS_OF_CONTAINMENT_PROPERTIES));
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param matchManager
+ * {@link IMatchManager}
+ */
+ public PapyrusUML2ReferencesCheck(final IMatchManager matchManager, final FeaturesCheck checker) {
+ super(matchManager, checker);
+ }
+
+ @Override
+ protected boolean shouldBeIgnored(EReference reference) {
+ final String fqn = fqn(reference);
+ boolean answer = super.shouldBeIgnored(reference) || SUBSETS_OF_CONTAINMENT.getProperty(fqn) != null;
+ return super.shouldBeIgnored(reference) || SUBSETS_OF_CONTAINMENT.getProperty(fqn) != null;
+ }
+
+ /**
+ * Transforms the {@link EReference} to a string.
+ *
+ * @param reference
+ * The {@link EReference}
+ * @return The string.
+ */
+ private String fqn(EReference reference) {
+ final StringBuilder fqn = new StringBuilder(reference.getEContainingClass().getName());
+ fqn.append('.').append(reference.getName());
+ return fqn.toString();
+ }
+}
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/services/nested/NestedMergeUtils.java b/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/services/nested/NestedMergeUtils.java
index 62c08971992..d14e11c79f3 100644
--- a/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/services/nested/NestedMergeUtils.java
+++ b/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/services/nested/NestedMergeUtils.java
@@ -29,7 +29,9 @@ public class NestedMergeUtils {
options.put(MatchOptions.OPTION_PROGRESS_MONITOR, monitor);
options.put(MatchOptions.OPTION_IGNORE_ID, Boolean.TRUE);
options.put(MatchOptions.OPTION_IGNORE_XMI_ID, Boolean.TRUE);
- options.put(MatchOptions.OPTION_MATCH_SCOPE_PROVIDER, new GenericMatchScopeProvider(left, right));
+ if(left!=null && right!=null){
+ options.put(MatchOptions.OPTION_MATCH_SCOPE_PROVIDER, new GenericMatchScopeProvider(left, right));
+ }
return options;
}
}
diff --git a/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/services/standalone/UMLStandaloneDiffEngine.java b/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/services/standalone/UMLStandaloneDiffEngine.java
index 201be187619..fc89d5818fe 100644
--- a/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/services/standalone/UMLStandaloneDiffEngine.java
+++ b/extraplugins/uml/compare/org.eclipse.papyrus.uml.compare.diff/src/org/eclipse/papyrus/uml/compare/diff/services/standalone/UMLStandaloneDiffEngine.java
@@ -16,7 +16,8 @@ package org.eclipse.papyrus.uml.compare.diff.services.standalone;
import java.util.Iterator;
import java.util.Map;
-import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.compare.diff.engine.check.AttributesCheck;
+import org.eclipse.emf.compare.diff.engine.check.ReferencesCheck;
import org.eclipse.emf.compare.diff.metamodel.AbstractDiffExtension;
import org.eclipse.emf.compare.diff.metamodel.DiffElement;
import org.eclipse.emf.compare.diff.metamodel.DiffGroup;
@@ -24,21 +25,26 @@ import org.eclipse.emf.compare.diff.metamodel.DiffModel;
import org.eclipse.emf.compare.diff.metamodel.MoveModelElement;
import org.eclipse.emf.compare.diff.metamodel.UpdateReference;
import org.eclipse.emf.compare.diff.metamodel.util.DiffSwitch;
+import org.eclipse.emf.compare.match.metamodel.Match2Elements;
import org.eclipse.emf.compare.match.metamodel.MatchModel;
import org.eclipse.emf.compare.uml2.diff.UML2DiffEngine;
+import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.emf.compare.diff.utils.PapyrusCompareOptions;
-import org.eclipse.papyrus.infra.emf.compare.diff.utils.PapyrusCompareOptionsUtils;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.papyrus.infra.emf.compare.diff.check.FeaturesCheck;
+import org.eclipse.papyrus.infra.emf.compare.diff.check.PapyrusAttributesCheck;
import org.eclipse.papyrus.infra.emf.compare.diff.utils.PapyrusOptionsAdapter;
+import org.eclipse.papyrus.uml.compare.diff.check.PapyrusUML2ReferencesCheck;
import org.eclipse.papyrus.uml.compare.diff.internal.utils.UMLDiffElementExtensionBuilder;
-
public class UMLStandaloneDiffEngine extends UML2DiffEngine {//GenericDiffEngine {
private DiffSwitch<AbstractDiffExtension> extensionBuilder;
private Map<String, Object> options;
+ protected FeaturesCheck featuresCheck;
+
public UMLStandaloneDiffEngine() {
this(null);
}
@@ -48,6 +54,32 @@ public class UMLStandaloneDiffEngine extends UML2DiffEngine {//GenericDiffEngine
this.options = options;
}
+ /**
+ * This will check if the elements matched by a given {@link Match2Elements} have been moved.
+ *
+ * @param root
+ * {@link DiffGroup root} of the {@link DiffElement} to create if the elements have actually
+ * been moved.
+ * @param matchElement
+ * This contains the mapping information about the elements we need to check for a move.
+ */
+ protected void checkMoves(DiffGroup root, Match2Elements matchElement) {
+ final EObject left = matchElement.getLeftElement();
+ final EObject right = matchElement.getRightElement();
+
+ if(left instanceof EGenericType || right instanceof EGenericType)
+ return;
+ if(left.eContainer() != null && right.eContainer() != null && getMatchManager().getMatchedEObject(left.eContainer()) != right.eContainer()) {
+ final EStructuralFeature leftFeature = left.eContainingFeature();
+ if(this.featuresCheck == null) {
+ this.featuresCheck = new FeaturesCheck(getMatchManager(), options);
+ }
+ if(!this.featuresCheck.shouldBeIgnored(leftFeature) && !this.featuresCheck.shouldBeIgnored(leftFeature, left)) {
+ super.checkMoves(root, matchElement);
+ }
+ }
+ }
+
@Override
public DiffModel doDiff(MatchModel match, boolean threeWay) {
DiffModel result = super.doDiff(match, threeWay);
@@ -56,6 +88,7 @@ public class UMLStandaloneDiffEngine extends UML2DiffEngine {//GenericDiffEngine
return result;
}
+
/**
* Attach an adapter containing the merge options to each DiffElement
*
@@ -118,4 +151,20 @@ public class UMLStandaloneDiffEngine extends UML2DiffEngine {//GenericDiffEngine
parent.getSubDiffElements().add((DiffElement)newElement);
((AbstractDiffExtension)newElement).getHideElements().add(oldElement);
}
+
+ @Override
+ protected AttributesCheck getAttributesChecker() {
+ if(this.featuresCheck == null) {
+ this.featuresCheck = new FeaturesCheck(getMatchManager(), this.options);
+ }
+ return new PapyrusAttributesCheck(getMatchManager(), this.featuresCheck);
+ }
+
+ @Override
+ protected ReferencesCheck getReferencesChecker() {
+ if(this.featuresCheck == null) {
+ this.featuresCheck = new FeaturesCheck(getMatchManager(), this.options);
+ }
+ return new PapyrusUML2ReferencesCheck(getMatchManager(), this.featuresCheck);
+ }
}

Back to the top