Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Goubet2013-05-30 09:11:03 +0000
committerMikaƫl Barbero2013-08-19 09:03:03 +0000
commita30b3180a942a8a285fd0be8eb719a3a7052540d (patch)
tree1f0067c493d05d162a464f6a31f711b44a41a1f5
parent1e4852cee8d61bad2f517b8e3d6c931869e213ce (diff)
downloadorg.eclipse.emf.compare-a30b3180a942a8a285fd0be8eb719a3a7052540d.tar.gz
org.eclipse.emf.compare-a30b3180a942a8a285fd0be8eb719a3a7052540d.tar.xz
org.eclipse.emf.compare-a30b3180a942a8a285fd0be8eb719a3a7052540d.zip
[409374] Consider RessourceAttachmentChanges in requirements
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/spec/ComparisonSpec.java20
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/req/DefaultReqEngine.java53
2 files changed, 51 insertions, 22 deletions
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/spec/ComparisonSpec.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/spec/ComparisonSpec.java
index 49db91be9..1927e125b 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/spec/ComparisonSpec.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/spec/ComparisonSpec.java
@@ -13,7 +13,6 @@ package org.eclipse.emf.compare.internal.spec;
import static com.google.common.collect.Iterables.filter;
import com.google.common.cache.CacheBuilder;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
@@ -29,6 +28,7 @@ import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.Match;
+import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.impl.ComparisonImpl;
import org.eclipse.emf.compare.internal.DiffCrossReferencer;
import org.eclipse.emf.compare.internal.MatchCrossReferencer;
@@ -87,25 +87,25 @@ public class ComparisonSpec extends ComparisonImpl {
}
final EList<Diff> result;
- Iterable<Diff> diffOnElement = filter(getInverse(element, diffCrossReferencer), Diff.class);
final Match match = getMatch(element);
if (match != null) {
- Iterable<Diff> left = ImmutableList.of();
- Iterable<Diff> right = ImmutableList.of();
- Iterable<Diff> origin = ImmutableList.of();
+ List<Iterable<? extends EObject>> lists = Lists.newArrayList();
+ lists.add(getInverse(element, diffCrossReferencer));
if (match.getLeft() != null) {
- left = filter(getInverse(match.getLeft(), diffCrossReferencer), Diff.class);
+ lists.add(getInverse(match.getLeft(), diffCrossReferencer));
}
if (match.getRight() != null) {
- right = filter(getInverse(match.getRight(), diffCrossReferencer), Diff.class);
+ lists.add(getInverse(match.getRight(), diffCrossReferencer));
}
if (match.getOrigin() != null) {
- origin = filter(getInverse(match.getOrigin(), diffCrossReferencer), Diff.class);
+ lists.add(getInverse(match.getOrigin(), diffCrossReferencer));
}
- Set<Diff> crossRefs = ImmutableSet.copyOf(Iterables.concat(diffOnElement, left, right, origin));
+ lists.add(filter(match.getDifferences(), ResourceAttachmentChange.class));
+ Set<Diff> crossRefs = ImmutableSet.copyOf(filter(Iterables.concat(lists), Diff.class));
result = new BasicEList<Diff>(crossRefs);
} else {
- result = new BasicEList<Diff>(ImmutableSet.copyOf(diffOnElement));
+ result = new BasicEList<Diff>(ImmutableSet.copyOf(filter(
+ getInverse(element, diffCrossReferencer), Diff.class)));
}
return result;
}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/req/DefaultReqEngine.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/req/DefaultReqEngine.java
index 3f984043e..b0f48a8c3 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/req/DefaultReqEngine.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/req/DefaultReqEngine.java
@@ -15,9 +15,11 @@ import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.filter;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
+import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -164,9 +166,8 @@ public class DefaultReqEngine implements IReqEngine {
* The given difference.
* @return The found differences.
*/
- private Set<ReferenceChange> getDELOriginValueOnContainmentRefSingle(Comparison comparison,
- Diff sourceDifference) {
- Set<ReferenceChange> result = new HashSet<ReferenceChange>();
+ private Set<Diff> getDELOriginValueOnContainmentRefSingle(Comparison comparison, Diff sourceDifference) {
+ Set<Diff> result = new HashSet<Diff>();
if (!(sourceDifference instanceof ReferenceChange)) {
return result;
}
@@ -196,18 +197,46 @@ public class DefaultReqEngine implements IReqEngine {
* The given kind.
* @return The found differences.
*/
- private Set<ReferenceChange> getDifferenceOnGivenObject(Comparison comparison, EObject object,
- DifferenceKind kind) {
- final Set<ReferenceChange> result = new HashSet<ReferenceChange>();
- for (ReferenceChange diff : filter(comparison.getDifferences(object), ReferenceChange.class)) {
- if (diff.getKind() == kind && diff.getReference().isContainment()) {
- result.add(diff);
- }
+ private Set<Diff> getDifferenceOnGivenObject(Comparison comparison, EObject object, DifferenceKind kind) {
+ final Set<Diff> result = new LinkedHashSet<Diff>();
+ for (Diff diff : filter(comparison.getDifferences(object), isRequiredContainmentChange(object, kind))) {
+ result.add(diff);
}
return result;
}
/**
+ * Will be used to filter out of a list of differences all those that relate to containment changes on the
+ * given object (a containment reference change or a resource attachment change if the given object has no
+ * direct container.
+ *
+ * @param object
+ * The object for which we seek containmnent differences.
+ * @param kind
+ * The kind of difference we seek.
+ * @return The created predicate.
+ */
+ private Predicate<? super Diff> isRequiredContainmentChange(final EObject object,
+ final DifferenceKind kind) {
+ return new Predicate<Diff>() {
+ public boolean apply(Diff input) {
+ if (input.getKind() != kind) {
+ return false;
+ }
+
+ boolean result = false;
+ if (input instanceof ReferenceChange
+ && ((ReferenceChange)input).getReference().isContainment()) {
+ result = true;
+ } else if (input instanceof ResourceAttachmentChange && object.eContainer() == null) {
+ result = true;
+ }
+ return result;
+ }
+ };
+ }
+
+ /**
* Retrieve candidate reference changes from a list of given <code>objects</code>.
*
* @see DefaultReqEngine#getDifferenceOnGivenObject(EObject, DifferenceKind).
@@ -219,9 +248,9 @@ public class DefaultReqEngine implements IReqEngine {
* The kind of requested differences.
* @return The found differences.
*/
- private Set<ReferenceChange> getDifferenceOnGivenObject(Comparison comparison, List<EObject> objects,
+ private Set<Diff> getDifferenceOnGivenObject(Comparison comparison, List<EObject> objects,
DifferenceKind kind) {
- Set<ReferenceChange> result = new HashSet<ReferenceChange>();
+ Set<Diff> result = new HashSet<Diff>();
for (EObject object : objects) {
result.addAll(getDifferenceOnGivenObject(comparison, object, kind));
}

Back to the top