Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCedric Notot2012-09-06 15:20:52 +0000
committerCedric Notot2012-09-06 15:24:15 +0000
commit81e3178aac3818f2405024c42e2461a6f0b8c8df (patch)
treeff106d04ca7d43a3e1fd55c626c93df8f75dea7c /plugins/org.eclipse.emf.compare.uml2.tests
parent13263b97d491aa702abb4f60adcc30453a8b137a (diff)
downloadorg.eclipse.emf.compare-81e3178aac3818f2405024c42e2461a6f0b8c8df.tar.gz
org.eclipse.emf.compare-81e3178aac3818f2405024c42e2461a6f0b8c8df.tar.xz
org.eclipse.emf.compare-81e3178aac3818f2405024c42e2461a6f0b8c8df.zip
delete of the uml predicates (use of a label provider)
Diffstat (limited to 'plugins/org.eclipse.emf.compare.uml2.tests')
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/AbstractTest.java36
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/ProfilesInputData.java4
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/UMLComparePredicates.java876
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/executionSpecification/AddActionExecutionSpecificationTest.java12
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/executionSpecification/AddBehaviorExecutionSpecificationTest.java12
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/generalizationSet/AddGeneralizationSetTest.java84
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/include/AddIncludeTest.java8
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/message/AddMessageTest.java12
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/profiles/AddProfileTest.java105
9 files changed, 187 insertions, 962 deletions
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/AbstractTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/AbstractTest.java
index b328fb34e..3d2436184 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/AbstractTest.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/AbstractTest.java
@@ -6,10 +6,14 @@ import com.google.common.collect.Iterators;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.emf.compare.AttributeChange;
import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.compare.extension.EMFCompareExtensionRegistry;
import org.eclipse.emf.compare.extension.PostProcessorDescriptor;
import org.eclipse.emf.compare.uml2.diff.UMLDiffExtensionPostProcessor;
+import org.eclipse.emf.compare.utils.ReferenceUtil;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.junit.After;
import org.junit.Before;
@@ -43,4 +47,36 @@ public abstract class AbstractTest {
return Integer.valueOf(count);
}
+ public static Predicate<? super Diff> onRealFeature(final EStructuralFeature feature) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ final EStructuralFeature affectedFeature;
+ if (input instanceof AttributeChange) {
+ affectedFeature = ((AttributeChange)input).getAttribute();
+ } else if (input instanceof ReferenceChange) {
+ affectedFeature = ((ReferenceChange)input).getReference();
+ } else {
+ return false;
+ }
+ return feature == affectedFeature;
+ }
+ };
+ }
+
+ public static Predicate<? super Diff> isChangeAdd() {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ if (input instanceof ReferenceChange) {
+ return ReferenceUtil.getAsList(input.getMatch().getLeft(),
+ ((ReferenceChange)input).getReference()).contains(
+ ((ReferenceChange)input).getValue());
+ } else if (input instanceof AttributeChange) {
+ return ReferenceUtil.getAsList(input.getMatch().getLeft(),
+ ((AttributeChange)input).getAttribute()).contains(
+ ((AttributeChange)input).getValue());
+ }
+ return false;
+ }
+ };
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/ProfilesInputData.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/ProfilesInputData.java
index f2488953a..e2ba0d472 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/ProfilesInputData.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/ProfilesInputData.java
@@ -17,7 +17,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.uml2.uml.resource.UMLResource;
-import org.eclipse.uml2.uml.util.UMLUtil;
+import org.eclipse.uml2.uml.resources.util.UMLResourcesUtil;
public class ProfilesInputData extends AbstractInputData {
@@ -53,7 +53,7 @@ public class ProfilesInputData extends AbstractInputData {
+ " have to be defined.", umlResourcesJarLocation != null
&& testProfileJarLocation != null);
- UMLUtil.init(resourceSet);
+ UMLResourcesUtil.init(resourceSet);
final Map uriMap = resourceSet.getURIConverter().getURIMap();
uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), URI.createURI(umlResourcesJarLocation
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/UMLComparePredicates.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/UMLComparePredicates.java
deleted file mode 100644
index 6244e3636..000000000
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/UMLComparePredicates.java
+++ /dev/null
@@ -1,876 +0,0 @@
-package org.eclipse.emf.compare.uml2.tests;
-
-import static com.google.common.base.Predicates.and;
-
-import com.google.common.base.Predicate;
-
-import java.util.Iterator;
-
-import org.eclipse.emf.compare.AttributeChange;
-import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceKind;
-import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.Match;
-import org.eclipse.emf.compare.ReferenceChange;
-import org.eclipse.emf.compare.utils.EqualityHelper;
-import org.eclipse.emf.ecore.EAttribute;
-import org.eclipse.emf.ecore.ENamedElement;
-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.edit.provider.IItemLabelProvider;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.edit.providers.UMLItemProviderAdapterFactory;
-
-public final class UMLComparePredicates {
-
- private static UMLItemProviderAdapterFactory factory = new UMLItemProviderAdapterFactory();
-
- /**
- * This class does not need to be instantiated.
- */
- private UMLComparePredicates() {
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the modification of a single-valued
- * reference going by the given {@code referenceName} on an EObject which name matches
- * {@code qualifiedName}. This can be used both on three-way and two-way Diffs : if three-way, we'll
- * consider that the {@code fromQualifiedName} can be either one of the right or origin values, and the
- * {@code toQualifiedName} to be either left or right. on two-way diffs however, {@code fromQualifiedName}
- * can only be the right value, and {@code toQualifiedName} will be the left one.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present a ReferenceChange.
- * @param referenceName
- * Name of the single-valued reference on which we expect a change.
- * @param fromQualifiedName
- * The original value of this reference.
- * @param toQualifiedName
- * The value to which this reference has been changed.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> changedReference(final String qualifiedName,
- final String referenceName, final String fromQualifiedName, final String toQualifiedName) {
- final Predicate<? super Diff> valuesMatch = new ReferenceValuesMatch(referenceName,
- fromQualifiedName, toQualifiedName);
- return and(ofKind(DifferenceKind.CHANGE), onEObject(qualifiedName), valuesMatch);
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the addition of a value in a
- * multi-valued attribute going by {@code attributeName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present an AttributeChange.
- * @param attributeName
- * Name of the multi-valued attribute on which we expect a change.
- * @param addedValue
- * The value we expect to have been added to this attribute.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> addedToAttribute(final String qualifiedName,
- final String attributeName, final Object addedValue) {
- // This is only meant for multi-valued attributes
- return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName), attributeValueMatch(attributeName,
- addedValue, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the addition of a value in a
- * multi-valued reference going by {@code referenceName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present a ReferenceChange.
- * @param referenceName
- * Name of the multi-valued reference on which we expect a change.
- * @param addedQualifiedName
- * Qualified name of the EObject which we expect to have been added to this reference.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> addedToReference(final String qualifiedName,
- final String referenceName, final String addedQualifiedName) {
- // This is only meant for multi-valued references
- return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName), referenceValueMatch(referenceName,
- addedQualifiedName, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the moving of a value within a
- * multi-valued attribute going by {@code attributeName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present an AttributeChange.
- * @param attributeName
- * Name of the multi-valued attribute on which we expect a change.
- * @param removedValue
- * Value which we expect to have been moved within this attribute.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> movedInAttribute(final String qualifiedName,
- final String attributeName, final Object removedValue) {
- // This is only meant for multi-valued attributes
- return and(ofKind(DifferenceKind.MOVE), onEObject(qualifiedName), attributeValueMatch(attributeName,
- removedValue, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the moving of a value within a
- * multi-valued reference going by {@code referenceName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present a ReferenceChange.
- * @param referenceName
- * Name of the multi-valued reference on which we expect a change.
- * @param removedQualifiedName
- * Qualified name of the EObject which we expect to have been moved within this reference.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> movedInReference(final String qualifiedName,
- final String referenceName, final String removedQualifiedName) {
- // This is only meant for multi-valued references
- return and(ofKind(DifferenceKind.MOVE), onEObject(qualifiedName), referenceValueMatch(referenceName,
- removedQualifiedName, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the deletion of a value from a
- * multi-valued attribute going by {@code attributeName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present an AttributeChange.
- * @param attributeName
- * Name of the multi-valued attribute on which we expect a change.
- * @param removedValue
- * Value which we expect to have been removed from this attribute.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> removedFromAttribute(final String qualifiedName,
- final String attributeName, final Object removedValue) {
- // This is only meant for multi-valued attributes
- return and(ofKind(DifferenceKind.DELETE), onEObject(qualifiedName), attributeValueMatch(
- attributeName, removedValue, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the deletion of a value from a
- * multi-valued reference going by {@code referenceName} on an EObject which name matches
- * {@code qualifiedName}.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present a ReferenceChange.
- * @param referenceName
- * Name of the multi-valued reference on which we expect a change.
- * @param removedQualifiedName
- * Qualified name of the EObject which we expect to have been removed from this reference.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> removedFromReference(final String qualifiedName,
- final String referenceName, final String removedQualifiedName) {
- // This is only meant for multi-valued references
- return and(ofKind(DifferenceKind.DELETE), onEObject(qualifiedName), referenceValueMatch(
- referenceName, removedQualifiedName, true));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the modification of a single-valued
- * attribute going by the given {@code attributeName} on an EObject which name matches
- * {@code qualifiedName}. This can be used both on three-way and two-way Diffs : if three-way, we'll
- * consider that the {@code fromValue} can be either one of the right or origin values, and the
- * {@code toValue} to be either left or right. on two-way diffs however, {@code fromValue} can only be the
- * right value, and {@code toValue} will be the left one.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a String
- * for us to compare it with the given qualified name.
- * </p>
- *
- * @param qualifiedName
- * Qualified name of the EObject which we expect to present an AttributeChange.
- * @param attributeName
- * Name of the single-valued attribute on which we expect a change.
- * @param fromValue
- * The original value of this attribute.
- * @param toValue
- * The value to which this attribute has been changed.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> changedAttribute(final String qualifiedName,
- final String attributeName, final Object fromValue, final Object toValue) {
- final Predicate<? super Diff> valuesMatch = new AttributeValuesMatch(attributeName, fromValue,
- toValue);
- return and(ofKind(DifferenceKind.CHANGE), onEObject(qualifiedName), valuesMatch);
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the addition of an EObject matching
- * the given qualified name. Namely, it will check that that Diff is a ReferenceChange, that one of its
- * Match sides correspond to the given qualified name's ancestors, and that its value correspond to the
- * given qualified name's last segment.
- * <p>
- * For example, {@code added("extlibrary.BookCategory.Encyclopedia")} will check that an EObject named
- * "Encyclopedia" has been added under the container "extlibrary.BookCategory". Note that
- * {@code added("emf.compare.Match")} will <b>not</b> match a difference on the EObject
- * "org.eclipse.emf.compare.Match". The qualified name must be absolute.
- * </p>
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a
- * String.
- * </p>
- *
- * @param qualifiedName
- * The qualified name of the EObject we expect to have been added.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> added(final String qualifiedName) {
- final int parentEndIndex = qualifiedName.lastIndexOf('.');
- if (parentEndIndex >= 0) {
- final String ancestors = qualifiedName.substring(0, parentEndIndex);
- final String objectName = qualifiedName.substring(parentEndIndex + 1);
- return and(ofKind(DifferenceKind.ADD), onEObject(ancestors), valueNameMatches(objectName));
- }
- return and(valueNameMatches(qualifiedName), ofKind(DifferenceKind.ADD));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the move of an EObject matching the
- * given qualified name. Namely, it will check that that Diff is a ReferenceChange, that one of its Match
- * sides correspond to the given qualified name's ancestors, and that its value correspond to the given
- * qualified name's last segment.
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a
- * String.
- * </p>
- *
- * @param qualifiedName
- * The qualified name of the EObject we expect to have been moved.
- * @param referenceName
- * Name of the reference in which we expect a child to have been added.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> moved(final String qualifiedName, final String referenceName) {
- final int parentEndIndex = qualifiedName.lastIndexOf('.');
- if (parentEndIndex >= 0) {
- final String ancestors = qualifiedName.substring(0, parentEndIndex);
- final String objectName = qualifiedName.substring(parentEndIndex + 1);
- return and(ofKind(DifferenceKind.MOVE), onEObject(ancestors), onFeature(referenceName),
- valueNameMatches(objectName));
- }
- return and(ofKind(DifferenceKind.MOVE), valueNameMatches(qualifiedName), onFeature(referenceName));
- }
-
- /**
- * This predicate can be used to check whether a given Diff represents the removal of an EObject matching
- * the given qualified name. Namely, it will check that that Diff is a ReferenceChange, that one of its
- * Match sides correspond to the given qualified name's ancestors, and that its value correspond to the
- * given qualified name's last segment.
- * <p>
- * For example, {@code removed("extlibrary.BookCategory.Encyclopedia")} will check that an EObject named
- * "Encyclopedia" has been removed from the container "extlibrary.BookCategory". Note that
- * {@code removed("emf.compare.Match")} will <b>not</b> match a difference on the EObject
- * "org.eclipse.emf.compare.Match". The qualified name must be absolute.
- * </p>
- * <p>
- * Note that in order for this to work, we expect the EObjects to have a "name" feature returning a
- * String.
- * </p>
- *
- * @param qualifiedName
- * The qualified name of the EObject we expect to have been removed.
- * @return The created predicate.
- */
- @SuppressWarnings("unchecked")
- public static Predicate<? super Diff> removed(final String qualifiedName) {
- final int parentEndIndex = qualifiedName.lastIndexOf('.');
- if (parentEndIndex >= 0) {
- final String ancestors = qualifiedName.substring(0, parentEndIndex);
- final String objectName = qualifiedName.substring(parentEndIndex + 1);
- return and(ofKind(DifferenceKind.DELETE), onEObject(ancestors), valueNameMatches(objectName));
- }
- return and(valueNameMatches(qualifiedName), ofKind(DifferenceKind.DELETE));
- }
-
- /**
- * This can be used to check that a given Diff correspond to either an {@link AttributeChange} or a
- * {@link ReferenceChange}, and that the corresponding reference or attribute matches the given
- * {@code featureName}.
- *
- * @param featureName
- * Name of the feature on which we expect a change.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> onFeature(final String featureName) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- final EStructuralFeature affectedFeature;
- if (input instanceof AttributeChange) {
- affectedFeature = ((AttributeChange)input).getAttribute();
- } else if (input instanceof ReferenceChange) {
- affectedFeature = ((ReferenceChange)input).getReference();
- } else {
- return false;
- }
- return featureName.equals(affectedFeature.getName());
- }
- };
- }
-
- /**
- * This can be used to check that a given Diff originates from the given {@code source} side.
- *
- * @param source
- * The side from which we expect this diff to originate.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> fromSide(final DifferenceSource source) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- return input.getSource() == source;
- }
- };
- }
-
- /**
- * This can be used in order to check that a Diff has been detected on the given EObject.
- *
- * @param eObject
- * The EObject which we expect the diff to concern.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> onEObject(final EObject eObject) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- final Match match = input.getMatch();
- return match.getLeft() == eObject || match.getRight() == eObject
- || match.getOrigin() == eObject;
- }
- };
- }
-
- /**
- * This can be used in order to check whether a Diff has been detected on an EObject matching the given
- * qualified name.
- * <p>
- * For this to work, we expect the EObjects to have a feature named "name" returning a String.
- * </p>
- *
- * @param qualifiedName
- * The qualified name of the EObject we expect that diff to concern.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> onEObject(final String qualifiedName) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- final Match match = input.getMatch();
- return match(match.getLeft(), qualifiedName) || match(match.getRight(), qualifiedName)
- || match(match.getOrigin(), qualifiedName);
- }
- };
- }
-
- /**
- * This predicate can be used to check whether a particular diff is of the given {@code kind}. This is
- * mainly used to differentiate additions from deletions.
- *
- * @param kind
- * The kind we expect this diff to have.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> ofKind(final DifferenceKind kind) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- return input.getKind() == kind;
- }
- };
- }
-
- /**
- * This predicate can be used in order to check that a particular Diff describes either a
- * {@link ReferenceChange} or {@link AttributeChange} for the given {@code expectedValue}.
- * <p>
- * For example, this could be used to check that the given value has indeed been added to a reference or
- * attribute, though such checks are more easily performed through {@link #addedIn(EObject, EObject)} or
- * {@link #removedFrom(EObject, EObject)}.
- * </p>
- *
- * @param expectedValue
- * The value which we expect to have changed and detected through a Diff.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> valueIs(final Object expectedValue) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- final Object value;
- if (input instanceof ReferenceChange) {
- value = ((ReferenceChange)input).getValue();
- } else if (input instanceof AttributeChange) {
- value = ((AttributeChange)input).getValue();
- } else {
- return false;
- }
- return value == expectedValue;
- }
- };
- }
-
- /**
- * This predicate can be used to check whether a given Diff describes an AttributeChange with the given
- * {@code attributeName} and which changed value corresponds to the given {@code expectedValue}.
- *
- * @param attributeName
- * The name of the attribute for which we seek an AttributeChange.
- * @param expectedValue
- * The value we expect to correspond to this AttributeChange.
- * @param multiValued
- * Tells us to check for either multi- or single-valued reference changes.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> attributeValueMatch(final String attributeName,
- final Object expectedValue, final boolean multiValued) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- if (input instanceof AttributeChange
- && ((AttributeChange)input).getAttribute().getName().equals(attributeName)
- && ((AttributeChange)input).getAttribute().isMany() == multiValued) {
- final Object value = ((AttributeChange)input).getValue();
- return new EqualityHelper().matchingAttributeValues(value, expectedValue);
- }
- return false;
- }
- };
- }
-
- /**
- * This predicate can be used to check whether a given Diff describes a ReferenceChange with the given
- * {@code referenceName} and which changed value corresponds to the given {@code qualifiedName}.
- * <p>
- * For this to work, we expect the EObject to have a feature named "name" returning a String for us to try
- * and match it.
- * </p>
- *
- * @param referenceName
- * The reference for which we seek a ReferenceChange.
- * @param qualifiedName
- * The qualified name of the EObject on which we detected a change.
- * @param multiValued
- * Tells us to check for either multi- or single-valued reference changes.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> referenceValueMatch(final String referenceName,
- final String qualifiedName, final boolean multiValued) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- if (input instanceof ReferenceChange
- && ((ReferenceChange)input).getReference().getName().equals(referenceName)
- && ((ReferenceChange)input).getReference().isMany() == multiValued) {
- final Object value = ((ReferenceChange)input).getValue();
- return qualifiedName != null && value instanceof EObject
- && match((EObject)value, qualifiedName);
- }
- return false;
- }
- };
- }
-
- /**
- * This can be used to check whether a given Diff describes either a {@link ReferenceChange} on an EObject
- * which name is {@code expectedName}.
- * <p>
- * For this to work, we expect the EObject to have a feature named "name" returning a String for us to try
- * and match it.
- * </p>
- *
- * @param expectedName
- * The name of the EObject which we expect as a changed reference value.
- * @return The created predicate.
- */
- public static Predicate<? super Diff> valueNameMatches(final String expectedName) {
- return new Predicate<Diff>() {
- public boolean apply(Diff input) {
- final EObject value;
- if (input instanceof ReferenceChange) {
- value = ((ReferenceChange)input).getValue();
- } else {
- return false;
- }
- return internalMatch(value, expectedName);
- }
- };
- }
-
- /**
- * This will be used to check that a given {@link EObject} corresponds to the given {@code qualifiedName}.
- * <p>
- * For example, {@code match("extlibrary.BookCategory.Encyclopedia")} will return {@code true} for an
- * EObject named "Encyclopedia" under the container "extlibrary.BookCategory". Note, however that
- * {@code match("emf.compare.Match")} will <b>not</b> match the EObject "org.eclipse.emf.compare.Match".
- * The qualified name must be absolute.
- * </p>
- * <p>
- * For this to work, we expect the EObject to have a feature named "name" returning a String for us to try
- * and match it. See also {@link #getNameFeature(EObject)}.
- * </p>
- *
- * @param eObject
- * The EObject which qualified name we are to check.
- * @param qualifiedName
- * The expected, <b>absolute</b> qualified name of the given {@code eObject}.
- * @return {@code true} if the given {@code eObject} matches the given {@code qualifiedName},
- * {@code false} if not, or if we could not determine the "name" feature of that EObject.
- * @see #getNameFeature(EObject)
- */
- private static boolean match(EObject eObject, String qualifiedName) {
- if (eObject == null || qualifiedName == null || qualifiedName.length() == 0) {
- return false;
- }
- final String[] names = qualifiedName.split("\\."); //$NON-NLS-1$
-
- int current = names.length - 1;
- boolean matches = internalMatch(eObject, names[current--]);
- if (matches) {
- EObject container = eObject.eContainer();
- while (matches && container != null && current >= 0) {
- matches = internalMatch(container, names[current--]);
- container = container.eContainer();
- }
- // This qualified name does not match if there was still a container "above"
- // "emf.compare.Match" does not match the EObject "org.eclipse.emf.compare.Match"
- matches = matches && container == null;
- }
-
- return matches;
- }
-
- /**
- * This will be used to check whether a given Object matches the given {@code qualifiedName}, considering
- * {@code null} as legal values. Namely, this will return {@code true} in the following cases :
- * <ul>
- * <li>both {@code eObject} and {@code qualifiedName} are {@code null}</li>
- * <li>eObject is an instance of {@link EObject} and its qualified name matches the given
- * {@code qualifiedName} according to the semantics of {@link #match(EObject, String)}</li>
- * </ul>
- *
- * @param eObject
- * The Object which qualified name we are to check. May be {@code null}.
- * @param qualifiedName
- * The expected, <b>absolute</b> qualified name of the given {@code eObject}. May be
- * {@code null}.
- * @return {@code true} if the given {@code eObject} matches the given {@code qualifiedName},
- * {@code false} if not, or if we could not determine the "name" feature of that EObject.
- * @see #match(EObject, String)
- */
- private static boolean matchAllowingNull(Object eObject, String qualifiedName) {
- if (eObject == null) {
- return qualifiedName == null;
- }
- return qualifiedName != null && eObject instanceof EObject && match((EObject)eObject, qualifiedName);
- }
-
- /**
- * Checks that the given {@code eObject}'s name is equal to {@code name}.
- * <p>
- * For this to work, we expect the EObject to have a feature named "name" returning a String for us to try
- * and match it. See also {@link #getNameFeature(EObject)}.
- * </p>
- *
- * @param eObject
- * the EObject which name we are to check.
- * @param name
- * The expected name of {@code eObject}.
- * @return {@code true} if the given {@code eObject}'s name is equal to the given {@code name},
- * {@code false} if not, or if we could not determine the "name" feature of that EObject.
- * @see #getNameFeature(EObject)
- */
- private static boolean internalMatch(EObject eObject, String name) {
- final EStructuralFeature nameFeature = getNameFeature(eObject);
- if (nameFeature != null) {
- final Object featureValue = eObject.eGet(nameFeature, false);
- if (featureValue instanceof String) {
- return featureValue.equals(name);
- } else if (eObject instanceof NamedElement && ((NamedElement)eObject).getName() != null) {
- return name.equals(((NamedElement)eObject).getName());
- }
- }
- IItemLabelProvider adapter = (IItemLabelProvider)factory.adapt(eObject, IItemLabelProvider.class);
- String featureValue = adapter.getText(eObject);
- featureValue = featureValue.replaceAll("<.*>", "");
- featureValue = featureValue.replaceAll("<<.*>>", "");
- featureValue = featureValue.substring(featureValue.lastIndexOf("/") + 1); //$NON-NLS-1$
- if (featureValue.trim().length() == 0) {
- featureValue = eObject.eClass().getName();
- }
- return featureValue.trim().equals(name);
- }
-
- /**
- * Tries and determine the "name" feature of the given EObject. By default, we only consider
- * {@link ENamedElement#name} or a feature of the given {@code eObject}'s EClass which would be named
- * "name".
- *
- * @param eObject
- * The EObject for which we are trying to determine a name.
- * @return The name feature of the given EObject if we could find one, {@code null} otherwise.
- */
- private static EStructuralFeature getNameFeature(EObject eObject) {
- if (eObject instanceof ENamedElement) {
- return EcorePackage.eINSTANCE.getENamedElement_Name();
- }
- if (eObject instanceof NamedElement) {
- return UMLPackage.eINSTANCE.getNamedElement_Name();
- }
- EStructuralFeature nameFeature = null;
- final Iterator<EStructuralFeature> features = eObject.eClass().getEAllStructuralFeatures().iterator();
- while (nameFeature == null && features.hasNext()) {
- final EStructuralFeature feature = features.next();
- if ("name".equals(feature.getName())) { //$NON-NLS-1$
- nameFeature = feature;
- }
- }
- return nameFeature;
- }
-
- /**
- * This particular predicate will be used to check that a given Diff corresponds to a ReferenceChange on a
- * given reference, with known "original" and "changed" values.
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- */
- private static final class ReferenceValuesMatch implements Predicate<Diff> {
- /** Name of the reference we expect to have been changed. */
- private final String referenceName;
-
- /** Qualified name of the expected original value of this reference. */
- private final String fromQualifiedName;
-
- /** Qualified name of the value to which this reference is expected to have changed. */
- private final String toQualifiedName;
-
- /**
- * Instantiates this predicate given the values it is meant to match.
- *
- * @param referenceName
- * Name of the single-valued reference on which we expect a change.
- * @param fromQualifiedName
- * The original value of this reference.
- * @param toQualifiedName
- * The value to which this reference has been changed.
- */
- public ReferenceValuesMatch(String referenceName, String fromQualifiedName, String toQualifiedName) {
- this.referenceName = referenceName;
- this.fromQualifiedName = fromQualifiedName;
- this.toQualifiedName = toQualifiedName;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see com.google.common.base.Predicate#apply(java.lang.Object)
- */
- public boolean apply(Diff input) {
- // Note that this is not meant for many-valued references
- if (input instanceof ReferenceChange
- && ((ReferenceChange)input).getReference().getName().equals(referenceName)
- && !((ReferenceChange)input).getReference().isMany()) {
- final EReference reference = ((ReferenceChange)input).getReference();
- final Match match = input.getMatch();
- final Object leftValue;
- if (match.getLeft() != null) {
- leftValue = match.getLeft().eGet(reference);
- } else {
- leftValue = null;
- }
- final Object rightValue;
- if (match.getRight() != null) {
- rightValue = match.getRight().eGet(reference);
- } else {
- rightValue = null;
- }
- final Object originValue;
- if (match.getOrigin() != null) {
- originValue = match.getOrigin().eGet(reference);
- } else {
- originValue = null;
- }
-
- // "from" is either right or origin
- boolean applies = false;
- if (matchAllowingNull(originValue, fromQualifiedName)) {
- // "from" is origin, "to" can be either left or right
- applies = matchAllowingNull(leftValue, toQualifiedName)
- || matchAllowingNull(rightValue, toQualifiedName);
- } else if (matchAllowingNull(rightValue, fromQualifiedName)) {
- // "from" is right, "to" can only be left
- applies = matchAllowingNull(leftValue, toQualifiedName);
- }
- return applies;
- }
- return false;
- }
- }
-
- /**
- * This particular predicate will be used to check that a given Diff corresponds to an AttributeChange on
- * a given attribute, with known "original" and "changed" values.
- *
- * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
- */
- private static final class AttributeValuesMatch implements Predicate<Diff> {
- /** Name of the attribute we expect to have been changed. */
- private final String attributeName;
-
- /** The expected original value of this attribute. */
- private final Object fromValue;
-
- /** The value to which this attribute is expected to have changed. */
- private final Object toValue;
-
- /**
- * Instantiates this predicate given the values it is meant to match.
- *
- * @param attributeName
- * Name of the single-valued attribute on which we expect a change.
- * @param fromValue
- * The original value of this attribute.
- * @param toValue
- * The value to which this attribute has been changed.
- */
- public AttributeValuesMatch(String attributeName, Object fromValue, Object toValue) {
- this.attributeName = attributeName;
- this.fromValue = fromValue;
- this.toValue = toValue;
- }
-
- /**
- * Checks whether the two given Objects match : they are either both {@code null}, the same instance,
- * or their "equals" returns {@code true}. If neither is {@code true}, we assume that these two
- * Objects don't match.
- * <p>
- * Do note that "unset" values are in fact set to the empty String instead of {@code null}. We will
- * thus consider {@code null} equal to the empty String here.
- * </p>
- *
- * @param attributeValue
- * The reference value, first of the two Objects to compare.
- * @param expectedValue
- * The expected value, second of the two Objects to compare.
- * @return {@code true} if these two Objects are equal, {@code false} otherwise.
- */
- private static boolean equalAttributeValues(Object attributeValue, Object expectedValue) {
- // Using == to handle the "null" case
- boolean equal = expectedValue == attributeValue || expectedValue != null
- && expectedValue.equals(attributeValue);
- // Consider that null is equal to the empty string (unset attributes)
- if (!equal) {
- equal = "".equals(attributeValue) && expectedValue == null || "".equals(expectedValue) //$NON-NLS-1$ //$NON-NLS-2$
- && attributeValue == null;
- }
- return equal;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see com.google.common.base.Predicate#apply(java.lang.Object)
- */
- public boolean apply(Diff input) {
- // Note that this is not meant for multi-valued attributes
- if (input instanceof AttributeChange
- && ((AttributeChange)input).getAttribute().getName().equals(attributeName)
- && !((AttributeChange)input).getAttribute().isMany()) {
- final EAttribute attribute = ((AttributeChange)input).getAttribute();
- final Match match = input.getMatch();
-
- final Object leftValue;
- if (match.getLeft() != null) {
- leftValue = match.getLeft().eGet(attribute);
- } else {
- leftValue = attribute.getDefaultValue();
- }
-
- final Object rightValue;
- if (match.getRight() != null) {
- rightValue = match.getRight().eGet(attribute);
- } else {
- rightValue = attribute.getDefaultValue();
- }
-
- final Object originValue;
- if (match.getOrigin() != null) {
- originValue = match.getOrigin().eGet(attribute);
- } else {
- originValue = attribute.getDefaultValue();
- }
-
- final Object actualFrom;
- if (fromValue == null) {
- actualFrom = attribute.getDefaultValue();
- } else {
- actualFrom = fromValue;
- }
- final Object actualTo;
- if (toValue == null) {
- actualTo = attribute.getDefaultValue();
- } else {
- actualTo = toValue;
- }
-
- // "from" is either right or origin
- boolean applies = false;
- if (equalAttributeValues(actualFrom, originValue)) {
- // "from" is origin, "to" can be either left or right
- applies = equalAttributeValues(actualTo, leftValue)
- || equalAttributeValues(actualTo, rightValue);
- } else if (equalAttributeValues(actualFrom, rightValue)) {
- // "from" is right, "to" can only be left
- applies = equalAttributeValues(actualTo, leftValue);
- }
- return applies;
- }
- return false;
- }
- }
-}
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/executionSpecification/AddActionExecutionSpecificationTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/executionSpecification/AddActionExecutionSpecificationTest.java
index 2935f9ef3..b046e021b 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/executionSpecification/AddActionExecutionSpecificationTest.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/executionSpecification/AddActionExecutionSpecificationTest.java
@@ -5,12 +5,12 @@ import static com.google.common.base.Predicates.instanceOf;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.assertTrue;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.added;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.addedToReference;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.changedReference;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.ofKind;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removed;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removedFromReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.added;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.addedToReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.changedReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.removed;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.removedFromReference;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/executionSpecification/AddBehaviorExecutionSpecificationTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/executionSpecification/AddBehaviorExecutionSpecificationTest.java
index b6417792a..7bc31fdc3 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/executionSpecification/AddBehaviorExecutionSpecificationTest.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/executionSpecification/AddBehaviorExecutionSpecificationTest.java
@@ -5,12 +5,12 @@ import static com.google.common.base.Predicates.instanceOf;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.assertTrue;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.added;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.addedToReference;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.changedReference;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.ofKind;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removed;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removedFromReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.added;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.addedToReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.changedReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.removed;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.removedFromReference;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/generalizationSet/AddGeneralizationSetTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/generalizationSet/AddGeneralizationSetTest.java
index 2f6de6f3e..2f8edbc61 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/generalizationSet/AddGeneralizationSetTest.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/generalizationSet/AddGeneralizationSetTest.java
@@ -5,11 +5,11 @@ import static com.google.common.base.Predicates.instanceOf;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.assertTrue;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.added;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.addedToReference;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.ofKind;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removed;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removedFromReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.added;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.onEObject;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.referenceValueMatch;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.removed;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
@@ -25,7 +25,9 @@ import org.eclipse.emf.compare.scope.IComparisonScope;
import org.eclipse.emf.compare.uml2.GeneralizationSetChange;
import org.eclipse.emf.compare.uml2.tests.AbstractTest;
import org.eclipse.emf.compare.uml2.tests.generalizationSet.data.GeneralizationSetInputData;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.uml2.uml.UMLPackage;
import org.junit.Test;
@SuppressWarnings("nls")
@@ -67,24 +69,32 @@ public class AddGeneralizationSetTest extends AbstractTest {
if (kind.equals(TestKind.DELETE)) {
addGeneralizationSetDescription = removed("model.GeneralizationSet_Class2_Class0"); //$NON-NLS-1$
- addRefGeneralizationSetInClass2Description = removedFromReference("model.Class2.Class1",
- "generalizationSet", "model.GeneralizationSet_Class2_Class0");
- addRefGeneralizationSetInClass0Description = removedFromReference("model.Class0.Class1",
- "generalizationSet", "model.GeneralizationSet_Class2_Class0");
- addRefGeneralizationInGeneralizationSetDescription1 = removedFromReference(
- "model.GeneralizationSet_Class2_Class0", "generalization", "model.Class0.Class1");
- addRefGeneralizationInGeneralizationSetDescription2 = removedFromReference(
- "model.GeneralizationSet_Class2_Class0", "generalization", "model.Class2.Class1");
+ addRefGeneralizationSetInClass2Description = removedFromReference1("model.Class2.Class1",
+ "generalizationSet", "model.GeneralizationSet_Class2_Class0",
+ UMLPackage.Literals.GENERALIZATION__GENERAL);
+ addRefGeneralizationSetInClass0Description = removedFromReference1("model.Class0.Class1",
+ "generalizationSet", "model.GeneralizationSet_Class2_Class0",
+ UMLPackage.Literals.GENERALIZATION__GENERAL);
+ addRefGeneralizationInGeneralizationSetDescription1 = removedFromReference2(
+ "model.GeneralizationSet_Class2_Class0", "generalization", "model.Class0.Class1",
+ UMLPackage.Literals.GENERALIZATION__GENERAL);
+ addRefGeneralizationInGeneralizationSetDescription2 = removedFromReference2(
+ "model.GeneralizationSet_Class2_Class0", "generalization", "model.Class2.Class1",
+ UMLPackage.Literals.GENERALIZATION__GENERAL);
} else {
addGeneralizationSetDescription = added("model.GeneralizationSet_Class2_Class0"); //$NON-NLS-1$
- addRefGeneralizationSetInClass2Description = addedToReference("model.Class2.Class1",
- "generalizationSet", "model.GeneralizationSet_Class2_Class0");
- addRefGeneralizationSetInClass0Description = addedToReference("model.Class0.Class1",
- "generalizationSet", "model.GeneralizationSet_Class2_Class0");
- addRefGeneralizationInGeneralizationSetDescription1 = addedToReference(
- "model.GeneralizationSet_Class2_Class0", "generalization", "model.Class0.Class1");
- addRefGeneralizationInGeneralizationSetDescription2 = addedToReference(
- "model.GeneralizationSet_Class2_Class0", "generalization", "model.Class2.Class1");
+ addRefGeneralizationSetInClass2Description = addedToReference1("model.Class2.Class1",
+ "generalizationSet", "model.GeneralizationSet_Class2_Class0",
+ UMLPackage.Literals.GENERALIZATION__GENERAL);
+ addRefGeneralizationSetInClass0Description = addedToReference1("model.Class0.Class1",
+ "generalizationSet", "model.GeneralizationSet_Class2_Class0",
+ UMLPackage.Literals.GENERALIZATION__GENERAL);
+ addRefGeneralizationInGeneralizationSetDescription1 = addedToReference2(
+ "model.GeneralizationSet_Class2_Class0", "generalization", "model.Class0.Class1",
+ UMLPackage.Literals.GENERALIZATION__GENERAL);
+ addRefGeneralizationInGeneralizationSetDescription2 = addedToReference2(
+ "model.GeneralizationSet_Class2_Class0", "generalization", "model.Class2.Class1",
+ UMLPackage.Literals.GENERALIZATION__GENERAL);
}
final Diff addGeneralizationSet = Iterators.find(differences.iterator(),
@@ -183,4 +193,36 @@ public class AddGeneralizationSetTest extends AbstractTest {
}
+ public static Predicate<? super Diff> removedFromReference1(final String qualifiedName,
+ final String referenceName, final String removedQualifiedName,
+ final EStructuralFeature featureDelegate) {
+ // This is only meant for multi-valued references
+ return and(ofKind(DifferenceKind.DELETE), onEObject(qualifiedName, featureDelegate),
+ referenceValueMatch(referenceName, removedQualifiedName, true));
+ }
+
+ public static Predicate<? super Diff> removedFromReference2(final String qualifiedName,
+ final String referenceName, final String removedQualifiedName,
+ final EStructuralFeature featureDelegate) {
+ // This is only meant for multi-valued references
+ return and(ofKind(DifferenceKind.DELETE), onEObject(qualifiedName), referenceValueMatch(
+ referenceName, removedQualifiedName, true, featureDelegate));
+ }
+
+ public static Predicate<? super Diff> addedToReference1(final String qualifiedName,
+ final String referenceName, final String removedQualifiedName,
+ final EStructuralFeature featureDelegate) {
+ // This is only meant for multi-valued references
+ return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName, featureDelegate),
+ referenceValueMatch(referenceName, removedQualifiedName, true));
+ }
+
+ public static Predicate<? super Diff> addedToReference2(final String qualifiedName,
+ final String referenceName, final String removedQualifiedName,
+ final EStructuralFeature featureDelegate) {
+ // This is only meant for multi-valued references
+ return and(ofKind(DifferenceKind.ADD), onEObject(qualifiedName), referenceValueMatch(referenceName,
+ removedQualifiedName, true, featureDelegate));
+ }
+
}
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/include/AddIncludeTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/include/AddIncludeTest.java
index f2021ed6d..55942d815 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/include/AddIncludeTest.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/include/AddIncludeTest.java
@@ -5,10 +5,10 @@ import static com.google.common.base.Predicates.instanceOf;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.assertTrue;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.added;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.changedReference;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.ofKind;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removed;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.added;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.changedReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.removed;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/message/AddMessageTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/message/AddMessageTest.java
index 51712a4ec..3001ae0f7 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/message/AddMessageTest.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/message/AddMessageTest.java
@@ -6,12 +6,12 @@ import static com.google.common.base.Predicates.not;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.assertTrue;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.added;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.addedToReference;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.changedReference;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.ofKind;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removed;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removedFromReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.added;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.addedToReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.changedReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.removed;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.removedFromReference;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/profiles/AddProfileTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/profiles/AddProfileTest.java
index 2b54c8aff..57f46edfa 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/profiles/AddProfileTest.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/profiles/AddProfileTest.java
@@ -2,15 +2,16 @@ package org.eclipse.emf.compare.uml2.tests.profiles;
import static com.google.common.base.Predicates.and;
import static com.google.common.base.Predicates.instanceOf;
+import static com.google.common.base.Predicates.not;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.assertTrue;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.added;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.addedToReference;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.changedReference;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.ofKind;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removed;
-import static org.eclipse.emf.compare.uml2.tests.UMLComparePredicates.removedFromReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.added;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.addedToReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.changedReference;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.removed;
+import static org.eclipse.emf.compare.utils.EMFComparePredicates.removedFromReference;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
@@ -22,6 +23,7 @@ import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.EMFCompare;
+import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.scope.DefaultComparisonScope;
import org.eclipse.emf.compare.scope.FilterComparisonScope;
@@ -30,15 +32,11 @@ import org.eclipse.emf.compare.uml2.ProfileApplicationChange;
import org.eclipse.emf.compare.uml2.StereotypeApplicationChange;
import org.eclipse.emf.compare.uml2.tests.AbstractTest;
import org.eclipse.emf.compare.uml2.tests.profiles.data.ProfileInputData;
+import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
import org.junit.Test;
-//import static org.eclipse.emf.compare.utils.EMFComparePredicates.added;
-//import static org.eclipse.emf.compare.utils.EMFComparePredicates.addedToReference;
-//import static org.eclipse.emf.compare.utils.EMFComparePredicates.changedReference;
-//import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
-//import static org.eclipse.emf.compare.utils.EMFComparePredicates.removed;
-//import static org.eclipse.emf.compare.utils.EMFComparePredicates.removedFromReference;
@SuppressWarnings("nls")
public class AddProfileTest extends AbstractTest {
@@ -130,23 +128,36 @@ public class AddProfileTest extends AbstractTest {
Predicate<? super Diff> addReferencesInUMLAnnotationDescription = null;
if (kind.equals(TestKind.DELETE)) {
- addProfileApplicationDescription = removed("aModel.Ecore Profile"); //$NON-NLS-1$
-
- addAppliedProfileInProfileApplicationDescription = changedReference("aModel.Ecore Profile",
- "appliedProfile", "Ecore", null);
-
- addUMLAnnotationDescription = removed("aModel.Ecore Profile.UML");
- addReferencesInUMLAnnotationDescription = removedFromReference("aModel.Ecore Profile.UML",
- "references", "Ecore.UML.Ecore");
+ addProfileApplicationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.DELETE),
+ onRealFeature(UMLPackage.Literals.PACKAGE__PROFILE_APPLICATION));
+
+ addAppliedProfileInProfileApplicationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.CHANGE),
+ onRealFeature(UMLPackage.Literals.PROFILE_APPLICATION__APPLIED_PROFILE),
+ not(isChangeAdd()));
+
+ addUMLAnnotationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.DELETE),
+ onRealFeature(EcorePackage.Literals.EMODEL_ELEMENT__EANNOTATIONS));
+
+ addReferencesInUMLAnnotationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.DELETE),
+ onRealFeature(EcorePackage.Literals.EANNOTATION__REFERENCES));
} else {
- addProfileApplicationDescription = added("aModel.Ecore Profile"); //$NON-NLS-1$
+ addProfileApplicationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.ADD),
+ onRealFeature(UMLPackage.Literals.PACKAGE__PROFILE_APPLICATION));
+
+ addAppliedProfileInProfileApplicationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.CHANGE),
+ onRealFeature(UMLPackage.Literals.PROFILE_APPLICATION__APPLIED_PROFILE), isChangeAdd());
- addAppliedProfileInProfileApplicationDescription = changedReference("aModel.Ecore Profile",
- "appliedProfile", null, "Ecore");
+ addUMLAnnotationDescription = and(instanceOf(ReferenceChange.class), ofKind(DifferenceKind.ADD),
+ onRealFeature(EcorePackage.Literals.EMODEL_ELEMENT__EANNOTATIONS));
- addUMLAnnotationDescription = added("aModel.Ecore Profile.UML");
- addReferencesInUMLAnnotationDescription = addedToReference("aModel.Ecore Profile.UML",
- "references", "Ecore.UML.Ecore");
+ addReferencesInUMLAnnotationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.ADD), onRealFeature(EcorePackage.Literals.EANNOTATION__REFERENCES));
}
final Diff addProfileApplication = Iterators.find(differences.iterator(),
@@ -222,24 +233,36 @@ public class AddProfileTest extends AbstractTest {
Predicate<? super Diff> addStereotypeApplicationDescription = null;
if (kind.equals(TestKind.DELETE)) {
- addProfileApplicationDescription = removed("aModel.UML2CompareTestProfile"); //$NON-NLS-1$
-
- addAppliedProfileInProfileApplicationDescription = changedReference(
- "aModel.UML2CompareTestProfile", "appliedProfile", "UML2CompareTestProfile", null);
-
- addUMLAnnotationDescription = removed("aModel.UML2CompareTestProfile.UML");
- addReferencesInUMLAnnotationDescription = removedFromReference(
- "aModel.UML2CompareTestProfile.UML", "references",
- "UML2CompareTestProfile.UML.uml2comparetestprofile");
+ addProfileApplicationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.DELETE),
+ onRealFeature(UMLPackage.Literals.PACKAGE__PROFILE_APPLICATION));
+
+ addAppliedProfileInProfileApplicationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.CHANGE),
+ onRealFeature(UMLPackage.Literals.PROFILE_APPLICATION__APPLIED_PROFILE),
+ not(isChangeAdd()));
+
+ addUMLAnnotationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.DELETE),
+ onRealFeature(EcorePackage.Literals.EMODEL_ELEMENT__EANNOTATIONS));
+
+ addReferencesInUMLAnnotationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.DELETE),
+ onRealFeature(EcorePackage.Literals.EANNOTATION__REFERENCES));
} else {
- addProfileApplicationDescription = added("aModel.UML2CompareTestProfile"); //$NON-NLS-1$
+ addProfileApplicationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.ADD),
+ onRealFeature(UMLPackage.Literals.PACKAGE__PROFILE_APPLICATION));
- addAppliedProfileInProfileApplicationDescription = changedReference(
- "aModel.UML2CompareTestProfile", "appliedProfile", null, "UML2CompareTestProfile");
+ addAppliedProfileInProfileApplicationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.CHANGE),
+ onRealFeature(UMLPackage.Literals.PROFILE_APPLICATION__APPLIED_PROFILE), isChangeAdd());
- addUMLAnnotationDescription = added("aModel.UML2CompareTestProfile.UML");
- addReferencesInUMLAnnotationDescription = addedToReference("aModel.UML2CompareTestProfile.UML",
- "references", "UML2CompareTestProfile.UML.uml2comparetestprofile");
+ addUMLAnnotationDescription = and(instanceOf(ReferenceChange.class), ofKind(DifferenceKind.ADD),
+ onRealFeature(EcorePackage.Literals.EMODEL_ELEMENT__EANNOTATIONS));
+
+ addReferencesInUMLAnnotationDescription = and(instanceOf(ReferenceChange.class),
+ ofKind(DifferenceKind.ADD), onRealFeature(EcorePackage.Literals.EANNOTATION__REFERENCES));
}
addStereotypeApplicationDescription = instanceOf(ResourceAttachmentChange.class);

Back to the top