Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Delaigue2017-02-02 08:32:25 -0500
committerLaurent Delaigue2017-03-14 05:55:56 -0400
commitb1ff6cc006e1fb1160d4aeccd9bfdf49b1d39a92 (patch)
treecdf058e62107da1de5840b9392d61a3b4828b60c
parentb599b8cd35475a5485b939ab0511f079484906e0 (diff)
downloadorg.eclipse.emf.compare-b1ff6cc006e1fb1160d4aeccd9bfdf49b1d39a92.tar.gz
org.eclipse.emf.compare-b1ff6cc006e1fb1160d4aeccd9bfdf49b1d39a92.tar.xz
org.eclipse.emf.compare-b1ff6cc006e1fb1160d4aeccd9bfdf49b1d39a92.zip
Improve final state and MergeData when merging
Mergers now properly set the final state of diffs according to whether they were accepted or rejected. We now install a DiffStateAdapter on the comparison and all its diffs to listen to diff state changes and update MergeData accordingly. Change-Id: Ib0945557e4a90feab82280a773ab49237e31c0ce Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr>
-rw-r--r--plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/contentmergeviewer/diagram/DiagramContentMergeViewer.java3
-rw-r--r--plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java145
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/MergeAllCommandTests.java112
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/MergeActionTest.java16
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/MergeNonConflictingRunnableTest.java8
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/PseudoConflictsMergeActionTest.java24
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434822.java121
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434827.java66
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434828.java61
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434828_2.java61
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug470503.java10
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug475586.java6
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/provider/TreeMergeViewerItemContentProvider.java12
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/ide_ui_messages.properties1
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java8
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeRunnable.java77
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeNonConflictingRunnable.java33
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeRunnableImpl.java27
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ContainmentReferenceChangeAccessorImpl.java5
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/FeatureMapKeyChangeAccessorImpl.java20
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ResourceContentsAccessorImpl.java5
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/mergeviewer/item/impl/MergeViewerItem.java12
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/mergeviewer/item/impl/ResourceAttachmentChangeMergeViewerItem.java21
-rw-r--r--plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/util/MergeViewerUtil.java8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/ResourceAttachmentChangeBug492261.java18
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/ConflictMergeTest.java157
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/MultipleMergeTest.java59
-rw-r--r--plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/stereotypes/AbstractStereotypedElementChangeTests.java15
-rw-r--r--plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/merge/OpaqueElementBodyChangeMerger.java26
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IMergeData.java23
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDataImpl.java35
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeMode.java65
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/AbstractMerger.java10
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ConflictMerger.java8
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ReferenceChangeMerger.java3
35 files changed, 626 insertions, 655 deletions
diff --git a/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/contentmergeviewer/diagram/DiagramContentMergeViewer.java b/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/contentmergeviewer/diagram/DiagramContentMergeViewer.java
index c6e64101a..b4028e57a 100644
--- a/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/contentmergeviewer/diagram/DiagramContentMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.diagram.ide.ui/src/org/eclipse/emf/compare/diagram/ide/ui/internal/contentmergeviewer/diagram/DiagramContentMergeViewer.java
@@ -15,6 +15,7 @@ package org.eclipse.emf.compare.diagram.ide.ui.internal.contentmergeviewer.diagr
import static com.google.common.base.Predicates.and;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.base.Predicates.or;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.onFeature;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.valueIs;
@@ -1850,7 +1851,7 @@ public class DiagramContentMergeViewer extends EMFCompareContentMergeViewer {
Diff diff = input.getDiff(); // equivalent to getInput().getTarget()
- if (diff.getState() != DifferenceState.MERGED && diff != fCurrentSelectedDiff) {
+ if (!isInTerminalState(diff) && diff != fCurrentSelectedDiff) {
fDecoratorsManager.revealDecorators(diff);
}
diff --git a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java
index 11eb887a1..66c684bfc 100644
--- a/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java
+++ b/plugins/org.eclipse.emf.compare.edit/src/org/eclipse/emf/compare/provider/spec/OverlayImageProvider.java
@@ -12,19 +12,19 @@ package org.eclipse.emf.compare.provider.spec;
import static com.google.common.collect.Lists.newArrayList;
import static org.eclipse.emf.compare.ConflictKind.REAL;
+import static org.eclipse.emf.compare.DifferenceState.DISCARDED;
+import static org.eclipse.emf.compare.DifferenceState.MERGED;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.canBeConsideredAsPseudoConflicting;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasDirectOrIndirectConflict;
import java.util.Collection;
import java.util.List;
-import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.internal.merge.IMergeData;
import org.eclipse.emf.compare.internal.utils.ComparisonUtil;
@@ -141,20 +141,18 @@ public class OverlayImageProvider {
* the diff we have to find an image for.
* @return the path to the image overlay for the given {@code diff}.
*/
- // Nothing here has to be externalized
- @SuppressWarnings("nls")
private String getImageOverlay(Diff diff) {
final Comparison comparison = ComparisonUtil.getComparison(diff);
- String path = "full/ovr16/";
+ String path = "full/ovr16/"; //$NON-NLS-1$
- if (diff.getState() == DifferenceState.MERGED) {
+ if (diff.getState() == MERGED) {
path += getMergedOverlay(diff);
- } else if (diff.getState() == DifferenceState.DISCARDED) {
- path += REJECTED_OV;
+ } else if (diff.getState() == DISCARDED) {
+ path += getDiscardedOverlay(diff);
} else if (comparison.isThreeWay()) {
path += getThreeWayOverlay(diff);
} else {
- path += getTwoWayDiffOverlay(diff);
+ path += getTwoWayOverlay(diff);
}
return path;
}
@@ -166,41 +164,36 @@ public class OverlayImageProvider {
* the diff we have to find an image for.
* @return the overlay path for the given unmerged diff.
*/
- // Nothing here has to be externalized
- @SuppressWarnings("nls")
private String getThreeWayOverlay(final Diff diff) {
- final DifferenceKind diffKind = diff.getKind();
- final DifferenceSource source = diff.getSource();
-
+ DifferenceKind diffKind = diff.getKind();
+ DifferenceSource source = diff.getSource();
StringBuilder path = new StringBuilder();
if (hasDirectOrIndirectConflict(REAL).apply(diff)) {
// The diff or one of its refining diffs are in a pseudo conflict
- path.append("conf");
+ path.append("conf"); //$NON-NLS-1$
if (source == DifferenceSource.RIGHT) {
- path.append("r_");
+ path.append("r_"); //$NON-NLS-1$
}
} else if (canBeConsideredAsPseudoConflicting().apply(diff)) {
- // If the diff is not a refined diff and are in a pseudo conflict
- // Or if the diff is a refined diff that are not in a direct pseudo conflict, but all its refining
- // diffs are in pseudo conflicts
- path.append("pconf");
+ // If the diff is not a refined diff and is in a pseudo conflict
+ // Or if the diff is a refined diff that is not in a direct pseudo conflict, but all its
+ // refining diffs are in pseudo conflicts
+ path.append("pconf"); //$NON-NLS-1$
if (source == DifferenceSource.RIGHT) {
- path.append("r_");
+ path.append("r_"); //$NON-NLS-1$
}
} else {
switch (source) {
case LEFT:
- path.append("r_out");
+ path.append("r_out"); //$NON-NLS-1$
break;
case RIGHT:
- path.append("r_in");
+ path.append("r_in"); //$NON-NLS-1$
break;
default:
- // Cannot happen ... for now
- break;
+ throw new IllegalArgumentException();
}
}
-
switch (diffKind) {
case ADD:
path.append(ADD_OV);
@@ -214,52 +207,80 @@ public class OverlayImageProvider {
path.append(CHG_OV);
break;
default:
- // Cannot happen ... for now
- break;
+ throw new IllegalArgumentException();
}
return path.toString();
}
/**
- * Return the merged overlay path for the given diff.
+ * Returns the overlay for a diff that's in a 'DISCARDED' state.
*
* @param diff
- * the diff we have to find an image for.
- * @return the merged overlay for the given diff.
+ * The diff
+ * @return The overlay path to use.
*/
- private String getMergedOverlay(Diff diff) {
- final String path;
- Adapter adapter = EcoreUtil.getExistingAdapter(diff, IMergeData.class);
- if (adapter != null) {
- IMergeData mergeData = (IMergeData)adapter;
- switch (mergeData.getMergeMode()) {
- case LEFT_TO_RIGHT:
- path = MERGED_TO_RIGHT_OV;
- break;
- case RIGHT_TO_LEFT:
- path = MERGED_TO_LEFT_OV;
- break;
- case ACCEPT:
- path = ACCEPTED_OV;
- break;
- case REJECT:
- path = REJECTED_OV;
- break;
+ // @CHECKSTYLE:OFF
+ private String getDiscardedOverlay(Diff diff) {
+ DifferenceSource source = diff.getSource();
+ Comparison comp = ComparisonUtil.getComparison(diff);
+ IMergeData mergeData = (IMergeData)EcoreUtil.getExistingAdapter(comp, IMergeData.class);
+ if (mergeData != null) {
+ switch (source) {
+ case LEFT:
+ if (mergeData.isLeftEditable() && mergeData.isRightEditable()) {
+ return MERGED_TO_LEFT_OV;
+ } else {
+ return REJECTED_OV;
+ }
+ case RIGHT:
+ if (mergeData.isLeftEditable() && mergeData.isRightEditable()) {
+ return MERGED_TO_RIGHT_OV;
+ } else {
+ return REJECTED_OV;
+ }
default:
- throw new IllegalStateException();
+ throw new IllegalArgumentException();
}
- } else {
- // fall-back to standard overlay.
- final Match match = diff.getMatch();
- final Comparison comparison = match.getComparison();
- if (comparison.isThreeWay()) {
- path = getThreeWayOverlay(diff);
- } else {
- path = getTwoWayDiffOverlay(diff);
+ }
+ // Cannot determine direction
+ return REJECTED_OV;
+ }
+ // @CHECKSTYLE:ON
+
+ /**
+ * Returns the overlay for a diff that's in a 'MERGED' state.
+ *
+ * @param diff
+ * The diff
+ * @return The overlay path to use.
+ */
+ // @CHECKSTYLE:OFF
+ private String getMergedOverlay(Diff diff) {
+ DifferenceSource source = diff.getSource();
+ Comparison comp = ComparisonUtil.getComparison(diff);
+ IMergeData mergeData = (IMergeData)EcoreUtil.getExistingAdapter(comp, IMergeData.class);
+ if (mergeData != null) {
+ switch (source) {
+ case LEFT:
+ if (mergeData.isLeftEditable() && mergeData.isRightEditable()) {
+ return MERGED_TO_RIGHT_OV;
+ } else {
+ return ACCEPTED_OV;
+ }
+ case RIGHT:
+ if (mergeData.isLeftEditable() && mergeData.isRightEditable()) {
+ return MERGED_TO_LEFT_OV;
+ } else {
+ return ACCEPTED_OV;
+ }
+ default:
+ throw new IllegalArgumentException();
}
}
- return path;
+ // Cannot determine direction
+ return ACCEPTED_OV;
}
+ // @CHECKSTYLE:ON
/**
* Returns the overlay path for the given unmerged diff.
@@ -268,7 +289,7 @@ public class OverlayImageProvider {
* the diff we have to find an image for.
* @return the overlay path for the given unmerged diff.
*/
- private String getTwoWayDiffOverlay(Diff diff) {
+ private String getTwoWayOverlay(Diff diff) {
final String path;
final DifferenceKind diffKind = diff.getKind();
switch (diffKind) {
@@ -294,10 +315,8 @@ public class OverlayImageProvider {
*
* @return the overlay path for the given match.
*/
- // Nothing here has to be externalized
- @SuppressWarnings("nls")
private String getImageOverlay() {
- return "full/ovr16/match_ov";
+ return "full/ovr16/match_ov"; //$NON-NLS-1$
}
/**
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/MergeAllCommandTests.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/MergeAllCommandTests.java
index 7f08df2db..21e3d10ac 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/MergeAllCommandTests.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/command/MergeAllCommandTests.java
@@ -14,6 +14,9 @@ package org.eclipse.emf.compare.ide.ui.tests.command;
import static com.google.common.base.Predicates.and;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.size;
+import static org.eclipse.emf.compare.DifferenceState.DISCARDED;
+import static org.eclipse.emf.compare.DifferenceState.MERGED;
+import static org.eclipse.emf.compare.DifferenceState.UNRESOLVED;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasState;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
@@ -30,7 +33,6 @@ import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.command.impl.MergeAllNonConflictingCommand;
import org.eclipse.emf.compare.domain.impl.EMFCompareEditingDomain;
@@ -92,20 +94,20 @@ public class MergeAllCommandTests {
EList<Diff> differencesBefore = comparison.getDifferences();
// Test state of differences before command
// 3 Left Delete differences
- Iterable<Diff> leftDelete = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> leftDelete = filter(differencesBefore,
+ and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.DELETE), hasState(UNRESOLVED)));
assertEquals(3, size(leftDelete));
// 3 Right Delete differences
- Iterable<Diff> rightDelete = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> rightDelete = filter(differencesBefore,
+ and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.DELETE), hasState(UNRESOLVED)));
assertEquals(3, size(rightDelete));
// 3 Left Add differences
- Iterable<Diff> leftAdd = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> leftAdd = filter(differencesBefore,
+ and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD), hasState(UNRESOLVED)));
assertEquals(3, size(leftAdd));
// 3 Right Add differences
- Iterable<Diff> rightAdd = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> rightAdd = filter(differencesBefore,
+ and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD), hasState(UNRESOLVED)));
assertEquals(3, size(rightAdd));
// Execute command
@@ -115,19 +117,19 @@ public class MergeAllCommandTests {
// Test state of differences before command
// 3 Left Delete differences merged
leftDelete = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ ofKind(DifferenceKind.DELETE), hasState(MERGED, DISCARDED)));
assertEquals(3, size(leftDelete));
// 0 Right Delete differences merged
rightDelete = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ ofKind(DifferenceKind.DELETE), hasState(MERGED, DISCARDED)));
assertEquals(0, size(rightDelete));
// 3 Left Add differences merged
leftAdd = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD),
- hasState(DifferenceState.MERGED)));
+ hasState(MERGED, DISCARDED)));
assertEquals(3, size(leftAdd));
// 0 Right Add differences merged
rightAdd = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD),
- hasState(DifferenceState.MERGED)));
+ hasState(MERGED, DISCARDED)));
assertEquals(0, size(rightAdd));
command.dispose();
@@ -161,20 +163,20 @@ public class MergeAllCommandTests {
EList<Diff> differencesBefore = comparison.getDifferences();
// Test state of differences before command
// 3 Left Delete differences
- Iterable<Diff> leftDelete = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> leftDelete = filter(differencesBefore,
+ and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.DELETE), hasState(UNRESOLVED)));
assertEquals(3, size(leftDelete));
// 3 Right Delete differences
- Iterable<Diff> rightDelete = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> rightDelete = filter(differencesBefore,
+ and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.DELETE), hasState(UNRESOLVED)));
assertEquals(3, size(rightDelete));
// 3 Left Add differences
- Iterable<Diff> leftAdd = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> leftAdd = filter(differencesBefore,
+ and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD), hasState(UNRESOLVED)));
assertEquals(3, size(leftAdd));
// 3 Right Add differences
- Iterable<Diff> rightAdd = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> rightAdd = filter(differencesBefore,
+ and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD), hasState(UNRESOLVED)));
assertEquals(3, size(rightAdd));
// Execute command
@@ -184,19 +186,19 @@ public class MergeAllCommandTests {
// Test state of differences after command
// 0 Left Delete differences merged
leftDelete = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ ofKind(DifferenceKind.DELETE), hasState(MERGED, DISCARDED)));
assertEquals(0, size(leftDelete));
// 3 Right Delete differences merged
rightDelete = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ ofKind(DifferenceKind.DELETE), hasState(MERGED, DISCARDED)));
assertEquals(3, size(rightDelete));
// 0 Left Add differences merged
leftAdd = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD),
- hasState(DifferenceState.MERGED)));
+ hasState(MERGED, DISCARDED)));
assertEquals(0, size(leftAdd));
// 3 Right Add differences merged
rightAdd = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD),
- hasState(DifferenceState.MERGED)));
+ hasState(MERGED, DISCARDED)));
assertEquals(3, size(rightAdd));
command.dispose();
@@ -230,20 +232,20 @@ public class MergeAllCommandTests {
EList<Diff> differencesBefore = comparison.getDifferences();
// Test state of differences before command
// 3 Left Delete differences
- Iterable<Diff> leftDelete = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> leftDelete = filter(differencesBefore,
+ and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.DELETE), hasState(UNRESOLVED)));
assertEquals(3, size(leftDelete));
// 3 Right Delete differences
- Iterable<Diff> rightDelete = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> rightDelete = filter(differencesBefore,
+ and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.DELETE), hasState(UNRESOLVED)));
assertEquals(3, size(rightDelete));
// 3 Left Add differences
- Iterable<Diff> leftAdd = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> leftAdd = filter(differencesBefore,
+ and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD), hasState(UNRESOLVED)));
assertEquals(3, size(leftAdd));
// 3 Right Add differences
- Iterable<Diff> rightAdd = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> rightAdd = filter(differencesBefore,
+ and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD), hasState(UNRESOLVED)));
assertEquals(3, size(rightAdd));
// Execute command
@@ -253,19 +255,19 @@ public class MergeAllCommandTests {
// Test state of differences after command
// 3 Left Delete differences merged
leftDelete = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ ofKind(DifferenceKind.DELETE), hasState(MERGED, DISCARDED)));
assertEquals(3, size(leftDelete));
// 3 Right Delete differences merged
rightDelete = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ ofKind(DifferenceKind.DELETE), hasState(MERGED, DISCARDED)));
assertEquals(3, size(rightDelete));
// 3 Left Add differences merged
leftAdd = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD),
- hasState(DifferenceState.MERGED)));
+ hasState(MERGED, DISCARDED)));
assertEquals(3, size(leftAdd));
// 3 Right Add differences merged
rightAdd = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD),
- hasState(DifferenceState.MERGED)));
+ hasState(MERGED, DISCARDED)));
assertEquals(3, size(rightAdd));
command.dispose();
@@ -299,20 +301,20 @@ public class MergeAllCommandTests {
EList<Diff> differencesBefore = comparison.getDifferences();
// Test state of differences before command
// 3 Left Delete differences
- Iterable<Diff> leftDelete = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> leftDelete = filter(differencesBefore,
+ and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.DELETE), hasState(UNRESOLVED)));
assertEquals(3, size(leftDelete));
// 3 Right Delete differences
- Iterable<Diff> rightDelete = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> rightDelete = filter(differencesBefore,
+ and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.DELETE), hasState(UNRESOLVED)));
assertEquals(3, size(rightDelete));
// 3 Left Add differences
- Iterable<Diff> leftAdd = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> leftAdd = filter(differencesBefore,
+ and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD), hasState(UNRESOLVED)));
assertEquals(3, size(leftAdd));
// 3 Right Add differences
- Iterable<Diff> rightAdd = filter(differencesBefore, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> rightAdd = filter(differencesBefore,
+ and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD), hasState(UNRESOLVED)));
assertEquals(3, size(rightAdd));
// Execute command
@@ -322,19 +324,19 @@ public class MergeAllCommandTests {
// Test state of differences after command
// 3 Left Delete differences merged
leftDelete = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ ofKind(DifferenceKind.DELETE), hasState(MERGED, DISCARDED)));
assertEquals(3, size(leftDelete));
// 3 Right Delete differences merged
rightDelete = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ ofKind(DifferenceKind.DELETE), hasState(MERGED, DISCARDED)));
assertEquals(3, size(rightDelete));
// 3 Left Add differences merged
leftAdd = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD),
- hasState(DifferenceState.MERGED)));
+ hasState(MERGED, DISCARDED)));
assertEquals(3, size(leftAdd));
// 3 Right Add differences merged
rightAdd = filter(differencesAfter, and(fromSide(DifferenceSource.RIGHT), ofKind(DifferenceKind.ADD),
- hasState(DifferenceState.MERGED)));
+ hasState(MERGED, DISCARDED)));
assertEquals(3, size(rightAdd));
command.dispose();
@@ -376,12 +378,12 @@ public class MergeAllCommandTests {
EList<Diff> differencesBefore = comparison.getDifferences();
// Test state of differences before command
// 3 Left Delete differences
- Iterable<Diff> leftDelete = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> leftDelete = filter(differencesBefore,
+ and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.DELETE), hasState(UNRESOLVED)));
assertEquals(3, size(leftDelete));
// 3 Left Add differences
- Iterable<Diff> leftAdd = filter(differencesBefore, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.ADD), hasState(DifferenceState.UNRESOLVED)));
+ Iterable<Diff> leftAdd = filter(differencesBefore,
+ and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD), hasState(UNRESOLVED)));
assertEquals(3, size(leftAdd));
// Execute command
@@ -391,11 +393,11 @@ public class MergeAllCommandTests {
// Test state of differences after command
// 3 Left Delete differences merged
leftDelete = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT),
- ofKind(DifferenceKind.DELETE), hasState(DifferenceState.MERGED)));
+ ofKind(DifferenceKind.DELETE), hasState(MERGED, DISCARDED)));
assertEquals(3, size(leftDelete));
// 3 Left Add differences merged
leftAdd = filter(differencesAfter, and(fromSide(DifferenceSource.LEFT), ofKind(DifferenceKind.ADD),
- hasState(DifferenceState.MERGED)));
+ hasState(MERGED, DISCARDED)));
assertEquals(3, size(leftAdd));
command.dispose();
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/MergeActionTest.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/MergeActionTest.java
index ac152ca5f..39f2dfe7b 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/MergeActionTest.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/MergeActionTest.java
@@ -169,7 +169,7 @@ public class MergeActionTest extends AbstractTestUITreeNodeItemProviderAdapter {
assertEquals(MergeOperation.MERGE, accept.getMergeAction(localAddDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(localAdd));
action.run();
- assertEquals(DifferenceState.MERGED, localAddDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, localAddDiff.getState());
// REJECT Local delete difference
Diff localDeleteDiff = (Diff)localDelete.getData();
@@ -178,7 +178,7 @@ public class MergeActionTest extends AbstractTestUITreeNodeItemProviderAdapter {
accept.getMergeAction(localDeleteDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(localDelete));
action.run();
- assertEquals(DifferenceState.MERGED, localDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, localDeleteDiff.getState());
// REJECT Remote add difference
Diff remoteAddDiff = (Diff)remoteAdd.getData();
@@ -187,7 +187,7 @@ public class MergeActionTest extends AbstractTestUITreeNodeItemProviderAdapter {
accept.getMergeAction(remoteAddDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(remoteAdd));
action.run();
- assertEquals(DifferenceState.MERGED, remoteAddDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, remoteAddDiff.getState());
// REJECT Remote delete difference
Diff remoteDeleteDiff = (Diff)remoteDelete.getData();
@@ -196,7 +196,7 @@ public class MergeActionTest extends AbstractTestUITreeNodeItemProviderAdapter {
accept.getMergeAction(remoteDeleteDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(remoteDelete));
action.run();
- assertEquals(DifferenceState.MERGED, remoteDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, remoteDeleteDiff.getState());
}
@@ -273,7 +273,7 @@ public class MergeActionTest extends AbstractTestUITreeNodeItemProviderAdapter {
assertEquals(MergeOperation.MERGE, accept.getMergeAction(localAddDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(localAdd));
action.run();
- assertEquals(DifferenceState.MERGED, localAddDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, localAddDiff.getState());
// REJECT Local delete difference
Diff localDeleteDiff = (Diff)localDelete.getData();
@@ -282,7 +282,7 @@ public class MergeActionTest extends AbstractTestUITreeNodeItemProviderAdapter {
accept.getMergeAction(localDeleteDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(localDelete));
action.run();
- assertEquals(DifferenceState.MERGED, localDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, localDeleteDiff.getState());
// REJECT Remote add difference
Diff remoteAddDiff = (Diff)remoteAdd.getData();
@@ -291,7 +291,7 @@ public class MergeActionTest extends AbstractTestUITreeNodeItemProviderAdapter {
accept.getMergeAction(remoteAddDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(remoteAdd));
action.run();
- assertEquals(DifferenceState.MERGED, remoteAddDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, remoteAddDiff.getState());
// REJECT Remote delete difference
Diff remoteDeleteDiff = (Diff)remoteDelete.getData();
@@ -300,7 +300,7 @@ public class MergeActionTest extends AbstractTestUITreeNodeItemProviderAdapter {
accept.getMergeAction(remoteDeleteDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(remoteDelete));
action.run();
- assertEquals(DifferenceState.MERGED, remoteDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, remoteDeleteDiff.getState());
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/MergeNonConflictingRunnableTest.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/MergeNonConflictingRunnableTest.java
index 52b617316..b1d5ad030 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/MergeNonConflictingRunnableTest.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/MergeNonConflictingRunnableTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 EclipseSource Muenchen GmbH and others.
+ * Copyright (c) 2015, 2017 EclipseSource Muenchen GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -28,7 +28,6 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.Iterators;
-import java.util.Collection;
import java.util.Iterator;
import org.eclipse.emf.common.util.BasicEList;
@@ -637,11 +636,6 @@ public class MergeNonConflictingRunnableTest {
}
return new MergeNonConflictingRunnable(isLeftEditable, isRightEditable, mergeMode) {
@Override
- protected void addOrUpdateMergeData(Collection<Diff> differences, MergeMode mode) {
- // do nothing to prevent call of EcoreUtil.getAdapter()
- }
-
- @Override
protected void markAsMerged(Diff diff, MergeMode mode, boolean mergeRightToLeft,
Registry registry) {
// overwritten to prevent call of EcoreUtil.getAdapter()
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/PseudoConflictsMergeActionTest.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/PseudoConflictsMergeActionTest.java
index b14dd0556..362914d40 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/PseudoConflictsMergeActionTest.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/PseudoConflictsMergeActionTest.java
@@ -303,8 +303,8 @@ public class PseudoConflictsMergeActionTest extends AbstractTestUITreeNodeItemPr
reject.getMergeAction(remoteAddDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(remoteAdd));
action.run();
- assertEquals(DifferenceState.MERGED, localAddDiff.getState());
- assertEquals(DifferenceState.MERGED, remoteAddDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, localAddDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, remoteAddDiff.getState());
// REJECT Remote Delete difference
Diff localDeleteDiff = (Diff)localDelete.getData();
@@ -314,8 +314,8 @@ public class PseudoConflictsMergeActionTest extends AbstractTestUITreeNodeItemPr
reject.getMergeAction(remoteDeleteDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(remoteDelete));
action.run();
- assertEquals(DifferenceState.MERGED, localDeleteDiff.getState());
- assertEquals(DifferenceState.MERGED, remoteDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, localDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, remoteDeleteDiff.getState());
// REJECT Remote Change difference
Diff localChangeDiff = (Diff)localChange.getData();
@@ -325,8 +325,8 @@ public class PseudoConflictsMergeActionTest extends AbstractTestUITreeNodeItemPr
reject.getMergeAction(remoteChangeDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(remoteChange));
action.run();
- assertEquals(DifferenceState.MERGED, localChangeDiff.getState());
- assertEquals(DifferenceState.MERGED, remoteChangeDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, localChangeDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, remoteChangeDiff.getState());
}
@@ -509,8 +509,8 @@ public class PseudoConflictsMergeActionTest extends AbstractTestUITreeNodeItemPr
reject.getMergeAction(remoteAddDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(remoteAdd));
action.run();
- assertEquals(DifferenceState.MERGED, localAddDiff.getState());
- assertEquals(DifferenceState.MERGED, remoteAddDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, localAddDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, remoteAddDiff.getState());
// REJECT Remote Delete difference
Diff localDeleteDiff = (Diff)localDelete.getData();
@@ -520,8 +520,8 @@ public class PseudoConflictsMergeActionTest extends AbstractTestUITreeNodeItemPr
reject.getMergeAction(remoteDeleteDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(remoteDelete));
action.run();
- assertEquals(DifferenceState.MERGED, localDeleteDiff.getState());
- assertEquals(DifferenceState.MERGED, remoteDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, localDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, remoteDeleteDiff.getState());
// REJECT Remote Change difference
Diff localChangeDiff = (Diff)localChange.getData();
@@ -531,8 +531,8 @@ public class PseudoConflictsMergeActionTest extends AbstractTestUITreeNodeItemPr
reject.getMergeAction(remoteChangeDiff, leftEditable, rightEditable));
action.updateSelection(new StructuredSelection(remoteChange));
action.run();
- assertEquals(DifferenceState.MERGED, localChangeDiff.getState());
- assertEquals(DifferenceState.MERGED, remoteChangeDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, localChangeDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, remoteChangeDiff.getState());
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434822.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434822.java
index c788fe832..953cc124f 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434822.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434822.java
@@ -10,6 +10,14 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.tests.structuremergeviewer.actions;
+import static org.eclipse.emf.compare.DifferenceState.DISCARDED;
+import static org.eclipse.emf.compare.DifferenceState.MERGED;
+import static org.eclipse.emf.compare.DifferenceState.UNRESOLVED;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.ACCEPT;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.REJECT;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.getMergeMode;
+import static org.junit.Assert.assertEquals;
+
import com.google.common.collect.Lists;
import java.io.IOException;
@@ -17,18 +25,14 @@ import java.util.ArrayList;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeRunnableImpl;
-import org.eclipse.emf.compare.internal.merge.IMergeData;
-import org.eclipse.emf.compare.internal.merge.MergeMode;
+import org.eclipse.emf.compare.internal.merge.MergeDataImpl;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
import org.eclipse.emf.compare.scope.DefaultComparisonScope;
import org.eclipse.emf.compare.tests.framework.AbstractInputData;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -42,9 +46,9 @@ public class TestBug434822 {
private IMerger.Registry mergerRegistry;
- private Diff deletionDiff;
+ private Diff rightDelete;
- private Diff movingDiff;
+ private Diff leftMove;
/**
* Set up the three test models.
@@ -81,16 +85,20 @@ public class TestBug434822 {
Resource origin = inputData.getResource("origin.nodes"); //$NON-NLS-1$
DefaultComparisonScope scope = new DefaultComparisonScope(left, right, origin);
Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ // Add a IMergeData to handle status decorations on Diffs
+ comparison.eAdapters().add(new MergeDataImpl(true, false));
+
mergerRegistry = EMFCompareRCPPlugin.getDefault().getMergerRegistry();
// Keeps track of the 2 differences
for (Diff diff : comparison.getDifferences()) {
switch (diff.getKind()) {
case MOVE:
- movingDiff = diff;
+ leftMove = diff;
break;
case DELETE:
- deletionDiff = diff;
+ rightDelete = diff;
break;
default:
}
@@ -102,27 +110,35 @@ public class TestBug434822 {
*/
@Test
public void testMergeDataAfterAcceptingDeletion() {
+ ArrayList<Diff> uiDiff = Lists.newArrayList(rightDelete);
- Assert.assertNotNull(movingDiff);
- Assert.assertNotNull(deletionDiff);
+ MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, ACCEPT);
+ mergeRunnable.merge(uiDiff, false, mergerRegistry);
- /*
- * Mocks the UI behavior of UI if the deleting diff is selected for merging (with cascading diff
- * filter activated).
- */
- ArrayList<Diff> uiDiff = Lists.newArrayList(deletionDiff, movingDiff);
+ // Assert merge data and diff states
+ assertEquals(MERGED, rightDelete.getState());
+ assertEquals(ACCEPT, getMergeMode(rightDelete, true, false));
+ assertEquals(DISCARDED, leftMove.getState());
+ assertEquals(REJECT, getMergeMode(leftMove, true, false));
+ }
- MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, MergeMode.ACCEPT);
+ /**
+ * Checks that accepting the deletion works properly (no crash and correct merge data).
+ */
+ @Test
+ public void testMergeDataAfterAcceptingDeletionSeveral() {
+ // Mocks the UI behavior of UI if the deleting diff is selected for merging (with cascading diff
+ // filter activated).
+ ArrayList<Diff> uiDiff = Lists.newArrayList(rightDelete, leftMove);
+
+ MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, ACCEPT);
mergeRunnable.merge(uiDiff, false, mergerRegistry);
// Assert merge data and diff states
- Assert.assertEquals(DifferenceState.MERGED, deletionDiff.getState());
- Assert.assertEquals(MergeMode.ACCEPT, getMergeData(deletionDiff).getMergeMode());
- Assert.assertEquals(DifferenceState.MERGED, movingDiff.getState());
- IMergeData mergeData = getMergeData(movingDiff);
- Assert.assertNotNull(mergeData);
- Assert.assertEquals(MergeMode.REJECT, mergeData.getMergeMode());
-
+ assertEquals(MERGED, rightDelete.getState());
+ assertEquals(ACCEPT, getMergeMode(rightDelete, true, false));
+ assertEquals(DISCARDED, leftMove.getState());
+ assertEquals(REJECT, getMergeMode(leftMove, true, false));
}
/**
@@ -130,26 +146,19 @@ public class TestBug434822 {
*/
@Test
public void testMergeDataAfterRejectingDeletion() {
-
- Assert.assertNotNull(movingDiff);
- Assert.assertNotNull(deletionDiff);
-
/*
* Mocks the UI behavior of UI if the deleting diff is selected for merging (with cascading diff
* filter activated).
*/
- ArrayList<Diff> uiDiff = Lists.newArrayList(deletionDiff);
+ ArrayList<Diff> uiDiff = Lists.newArrayList(rightDelete);
- MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, MergeMode.REJECT);
+ MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, REJECT);
mergeRunnable.merge(uiDiff, false, mergerRegistry);
// Assert merge data and diff states
- Assert.assertEquals(DifferenceState.MERGED, deletionDiff.getState());
- Assert.assertEquals(MergeMode.REJECT, getMergeData(deletionDiff).getMergeMode());
- Assert.assertEquals(DifferenceState.UNRESOLVED, movingDiff.getState());
- IMergeData mergeData = getMergeData(movingDiff);
- Assert.assertNull(mergeData);
-
+ assertEquals(DISCARDED, rightDelete.getState());
+ assertEquals(REJECT, getMergeMode(rightDelete, true, false));
+ assertEquals(UNRESOLVED, leftMove.getState());
}
/**
@@ -157,24 +166,17 @@ public class TestBug434822 {
*/
@Test
public void testMergeDataAfterAcceptingMovement() {
-
- Assert.assertNotNull(movingDiff);
- Assert.assertNotNull(deletionDiff);
-
// Mocks the UI behavior of UI if the movement diff is selected for merging.
- ArrayList<Diff> uiDiff = Lists.newArrayList(movingDiff);
+ ArrayList<Diff> uiDiff = Lists.newArrayList(leftMove);
- MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, MergeMode.ACCEPT);
+ MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, ACCEPT);
mergeRunnable.merge(uiDiff, false, mergerRegistry);
// Assert merge data
- Assert.assertEquals(DifferenceState.MERGED, movingDiff.getState());
- Assert.assertEquals(MergeMode.ACCEPT, getMergeData(movingDiff).getMergeMode());
- Assert.assertEquals(DifferenceState.MERGED, deletionDiff.getState());
- IMergeData mergeData = getMergeData(deletionDiff);
- Assert.assertNotNull(mergeData);
- Assert.assertEquals(MergeMode.REJECT, mergeData.getMergeMode());
-
+ assertEquals(MERGED, leftMove.getState());
+ assertEquals(ACCEPT, getMergeMode(leftMove, true, false));
+ assertEquals(DISCARDED, rightDelete.getState());
+ assertEquals(REJECT, getMergeMode(rightDelete, true, false));
}
/**
@@ -182,27 +184,16 @@ public class TestBug434822 {
*/
@Test
public void testMergeDataAfterRejectingMovement() {
-
- Assert.assertNotNull(movingDiff);
- Assert.assertNotNull(deletionDiff);
-
// Mocks the UI behavior of UI if the movement diff is selected for merging.
- ArrayList<Diff> uiDiff = Lists.newArrayList(movingDiff);
+ ArrayList<Diff> uiDiff = Lists.newArrayList(leftMove);
- MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, MergeMode.REJECT);
+ MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, REJECT);
mergeRunnable.merge(uiDiff, false, mergerRegistry);
// Assert merge data
- Assert.assertEquals(DifferenceState.MERGED, movingDiff.getState());
- Assert.assertEquals(MergeMode.REJECT, getMergeData(movingDiff).getMergeMode());
- Assert.assertEquals(DifferenceState.UNRESOLVED, deletionDiff.getState());
- IMergeData mergeData = getMergeData(deletionDiff);
- Assert.assertNull(mergeData);
-
- }
-
- private IMergeData getMergeData(Diff diff) {
- return (IMergeData)EcoreUtil.getExistingAdapter(diff, IMergeData.class);
+ assertEquals(DISCARDED, leftMove.getState());
+ assertEquals(REJECT, getMergeMode(leftMove, true, false));
+ assertEquals(UNRESOLVED, rightDelete.getState());
}
/**
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434827.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434827.java
index df25e87d7..9f74b0e4a 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434827.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434827.java
@@ -10,6 +10,16 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.tests.structuremergeviewer.actions;
+import static org.eclipse.emf.compare.DifferenceState.DISCARDED;
+import static org.eclipse.emf.compare.DifferenceState.MERGED;
+import static org.eclipse.emf.compare.DifferenceState.UNRESOLVED;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.ACCEPT;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.REJECT;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.getMergeMode;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
import com.google.common.collect.Lists;
import java.io.IOException;
@@ -17,11 +27,10 @@ import java.util.ArrayList;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeRunnableImpl;
import org.eclipse.emf.compare.internal.merge.IMergeData;
-import org.eclipse.emf.compare.internal.merge.MergeMode;
+import org.eclipse.emf.compare.internal.merge.MergeDataImpl;
import org.eclipse.emf.compare.internal.spec.ReferenceChangeSpec;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
@@ -34,7 +43,6 @@ import org.eclipse.emf.compare.tests.nodes.NodesPackage;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -85,6 +93,10 @@ public class TestBug434827 {
Resource origin = inputData.getResource("origin.nodes"); //$NON-NLS-1$
final IComparisonScope scope = new DefaultComparisonScope(left, right, origin);
comparison = EMFCompare.builder().build().compare(scope);
+
+ // Add a IMergeData to handle status decorations on Diffs
+ comparison.eAdapters().add(new MergeDataImpl(true, false));
+
mergerRegistry = EMFCompareRCPPlugin.getDefault().getMergerRegistry();
// Keeps track of the 3 differences
@@ -113,28 +125,28 @@ public class TestBug434827 {
@Test
public void testMergeDataAfterAcceptingDeletion() {
- Assert.assertNotNull(subDiff);
- Assert.assertNotNull(deletionDiff);
- Assert.assertNotNull(oppositeDiff);
+ assertNotNull(subDiff);
+ assertNotNull(deletionDiff);
+ assertNotNull(oppositeDiff);
// Mocks the UI behavior of UI if the deleting diff is selected with cascading diff filter active.
// The subDiff is not added in this list because it is not considered as a cascading diff.
ArrayList<Diff> uiDiff = Lists.newArrayList(deletionDiff);
- MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, MergeMode.ACCEPT);
+ MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, ACCEPT);
mergeRunnable.merge(uiDiff, false, mergerRegistry);
Node rootNode = (Node)left.getContents().get(0);
// Checks that ReferencedNode has been deleted.
- Assert.assertEquals(0, rootNode.getContainmentRef1().get(0).getContainmentRef1().size());
+ assertEquals(0, rootNode.getContainmentRef1().get(0).getContainmentRef1().size());
// Assert merge data
- Assert.assertEquals(DifferenceState.MERGED, deletionDiff.getState());
- Assert.assertEquals(DifferenceState.MERGED, subDiff.getState());
- Assert.assertEquals(DifferenceState.MERGED, oppositeDiff.getState());
- Assert.assertEquals(MergeMode.ACCEPT, getMergeData(deletionDiff).getMergeMode());
- Assert.assertEquals(MergeMode.REJECT, getMergeData(subDiff).getMergeMode());
- Assert.assertEquals(MergeMode.REJECT, getMergeData(oppositeDiff).getMergeMode());
+ assertEquals(MERGED, deletionDiff.getState());
+ assertEquals(DISCARDED, subDiff.getState());
+ assertEquals(DISCARDED, oppositeDiff.getState());
+ assertEquals(ACCEPT, getMergeMode(deletionDiff, true, false));
+ assertEquals(REJECT, getMergeMode(subDiff, true, false));
+ assertEquals(REJECT, getMergeMode(oppositeDiff, true, false));
}
@@ -148,36 +160,36 @@ public class TestBug434827 {
@Test
public void testMergeDataAfterRejectingDeletion() {
- Assert.assertNotNull(subDiff);
- Assert.assertNotNull(deletionDiff);
- Assert.assertNotNull(oppositeDiff);
+ assertNotNull(subDiff);
+ assertNotNull(deletionDiff);
+ assertNotNull(oppositeDiff);
// Mocks the UI behavior of UI if the deleting diff is selected with cascading diff filter active.
// The subDiff is not added in this list because it is not considered as a cascading diff.
ArrayList<Diff> uiDiff = Lists.newArrayList(deletionDiff);
- MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, MergeMode.REJECT);
+ MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, REJECT);
mergeRunnable.merge(uiDiff, false, mergerRegistry);
Node rootNode = (Node)left.getContents().get(0);
// Checks that ReferenceNode node has not been deleted.
- Assert.assertEquals(1, rootNode.getContainmentRef1().get(0).getContainmentRef1().size());
+ assertEquals(1, rootNode.getContainmentRef1().get(0).getContainmentRef1().size());
NodeOppositeRefOneToOne holdingRefNode = (NodeOppositeRefOneToOne)rootNode.getContainmentRef1()
.get(1);
NodeOppositeRefOneToOne referencedNode = (NodeOppositeRefOneToOne)rootNode.getContainmentRef1().get(0)
.getContainmentRef1().get(0);
// Checks that the opposite reference has been set.
- Assert.assertEquals(holdingRefNode, referencedNode.getSource());
- Assert.assertEquals(referencedNode, holdingRefNode.getDestination());
+ assertEquals(holdingRefNode, referencedNode.getSource());
+ assertEquals(referencedNode, holdingRefNode.getDestination());
// Assert merge data
- Assert.assertEquals(DifferenceState.MERGED, deletionDiff.getState());
- Assert.assertEquals(MergeMode.REJECT, getMergeData(deletionDiff).getMergeMode());
+ assertEquals(DISCARDED, deletionDiff.getState());
+ assertEquals(REJECT, getMergeMode(deletionDiff, true, false));
// The two differences should be Unresolved.
- Assert.assertNull(getMergeData(subDiff));
- Assert.assertNull(getMergeData(oppositeDiff));
- Assert.assertEquals(DifferenceState.UNRESOLVED, subDiff.getState());
- Assert.assertEquals(DifferenceState.UNRESOLVED, oppositeDiff.getState());
+ assertNull(getMergeData(subDiff));
+ assertNull(getMergeData(oppositeDiff));
+ assertEquals(UNRESOLVED, subDiff.getState());
+ assertEquals(UNRESOLVED, oppositeDiff.getState());
}
private IMergeData getMergeData(Diff diff) {
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434828.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434828.java
index 6033837e4..e4af7d616 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434828.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434828.java
@@ -10,6 +10,13 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.tests.structuremergeviewer.actions;
+import static org.eclipse.emf.compare.DifferenceState.DISCARDED;
+import static org.eclipse.emf.compare.DifferenceState.MERGED;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.ACCEPT;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.REJECT;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.getMergeMode;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@@ -19,11 +26,9 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeRunnableImpl;
-import org.eclipse.emf.compare.internal.merge.IMergeData;
-import org.eclipse.emf.compare.internal.merge.MergeMode;
+import org.eclipse.emf.compare.internal.merge.MergeDataImpl;
import org.eclipse.emf.compare.merge.BatchMerger;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
@@ -32,8 +37,6 @@ import org.eclipse.emf.compare.tests.framework.AbstractInputData;
import org.eclipse.emf.compare.tests.nodes.Node;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -83,25 +86,29 @@ public class TestBug434828 {
final Resource origin = inputData.getResource("origin.nodes"); //$NON-NLS-1$
scope = new DefaultComparisonScope(left, right, origin);
final Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ // Add a IMergeData to handle status decorations on Diffs
+ comparison.eAdapters().add(new MergeDataImpl(true, false));
+
mergerRegistry = EMFCompareRCPPlugin.getDefault().getMergerRegistry();
// Keeps tracks of the differences to test.
EList<Conflict> conflicts = comparison.getConflicts();
- Assert.assertEquals(1, conflicts.size());
+ assertEquals(1, conflicts.size());
Conflict conflict = conflicts.get(0);
// Get the left diff of the conflict: change of eopposite reference
EList<Diff> leftConflicts = conflict.getLeftDifferences();
- Assert.assertEquals(2, leftConflicts.size());
+ assertEquals(2, leftConflicts.size());
refChangeDiff = leftConflicts.get(0);// Both difference are equivalent.
// Get the right diff of the conflict; deletion of "ReferencedNode"
EList<Diff> rightConflicts = conflict.getRightDifferences();
- Assert.assertEquals(1, rightConflicts.size());
+ assertEquals(1, rightConflicts.size());
holdingRefDeletionDiff = rightConflicts.get(0);
// Get the required by diff of the right conflict
EList<Diff> rightRequiredBy = holdingRefDeletionDiff.getRequiredBy();
- Assert.assertEquals(1, rightRequiredBy.size());
+ assertEquals(1, rightRequiredBy.size());
deletedNodeDeletionDiff = rightRequiredBy.get(0);
}
@@ -119,16 +126,16 @@ public class TestBug434828 {
*/
@Test
public void testAcceptConflictDiffWithConflictingDiffWithRequiredBy() {
- MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, MergeMode.ACCEPT);
+ MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, ACCEPT);
mergeRunnable.merge(Collections.singletonList(refChangeDiff), false, mergerRegistry);
- Assert.assertEquals(DifferenceState.MERGED, refChangeDiff.getState());
- Assert.assertEquals(MergeMode.ACCEPT, getMergeData(refChangeDiff).getMergeMode());
- Assert.assertEquals(DifferenceState.MERGED, holdingRefDeletionDiff.getState());
- Assert.assertEquals(MergeMode.REJECT, getMergeData(holdingRefDeletionDiff).getMergeMode());
+ assertEquals(MERGED, refChangeDiff.getState());
+ assertEquals(ACCEPT, getMergeMode(refChangeDiff, true, false));
+ assertEquals(DISCARDED, holdingRefDeletionDiff.getState());
+ assertEquals(REJECT, getMergeMode(holdingRefDeletionDiff, true, false));
- Assert.assertEquals(DifferenceState.MERGED, deletedNodeDeletionDiff.getState());
- Assert.assertEquals(MergeMode.REJECT, getMergeData(deletedNodeDeletionDiff).getMergeMode());
+ assertEquals(DISCARDED, deletedNodeDeletionDiff.getState());
+ assertEquals(REJECT, getMergeMode(deletedNodeDeletionDiff, true, false));
// TODO The optimal way is to have the deletedNodeDeletionDiff unresolved
// Assert.assertEquals(DifferenceState.UNRESOLVED, deletedNodeDeletionDiff.getState());
@@ -137,14 +144,14 @@ public class TestBug434828 {
Resource leftResource = (Resource)scope.getLeft();
EList<EObject> content = leftResource.getContents();
- Assert.assertEquals(1, content.size());
+ assertEquals(1, content.size());
Node root = (Node)content.get(0);
EList<Node> children = root.getContainmentRef1();
// Checks that "HoldingDeletedNode" is in the model.
- Assert.assertEquals(2, children.size());
+ assertEquals(2, children.size());
Node firstChildren = children.get(0);
// Checks that "ReferencedNode" is in the model.
- Assert.assertEquals(1, firstChildren.getContainmentRef1().size());
+ assertEquals(1, firstChildren.getContainmentRef1().size());
}
/**
@@ -154,26 +161,22 @@ public class TestBug434828 {
public void testAcceptConflictDiffWithConflictingDiffWithRequiredByProg() {
new BatchMerger(mergerRegistry).copyAllLeftToRight(Arrays.asList(refChangeDiff), new BasicMonitor());
- Assert.assertEquals(DifferenceState.MERGED, refChangeDiff.getState());
- Assert.assertEquals(DifferenceState.MERGED, holdingRefDeletionDiff.getState());
- Assert.assertEquals(DifferenceState.MERGED, deletedNodeDeletionDiff.getState());
+ assertEquals(MERGED, refChangeDiff.getState());
+ assertEquals(DISCARDED, holdingRefDeletionDiff.getState());
+ assertEquals(DISCARDED, deletedNodeDeletionDiff.getState());
// Checks that the content of the right resource is correct.
Resource leftResource = (Resource)scope.getLeft();
EList<EObject> content = leftResource.getContents();
- Assert.assertEquals(1, content.size());
+ assertEquals(1, content.size());
Node root = (Node)content.get(0);
EList<Node> children = root.getContainmentRef1();
// Checks that "DeletedNode" is in the model.
- Assert.assertEquals(2, children.size());
+ assertEquals(2, children.size());
Node firstChildren = children.get(0);
// Checks that "ReferencedNode" is in the model.
- Assert.assertEquals(1, firstChildren.getContainmentRef1().size());
- }
-
- private IMergeData getMergeData(Diff diff) {
- return (IMergeData)EcoreUtil.getExistingAdapter(diff, IMergeData.class);
+ assertEquals(1, firstChildren.getContainmentRef1().size());
}
/**
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434828_2.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434828_2.java
index 9848b44ad..32c4d830c 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434828_2.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug434828_2.java
@@ -10,6 +10,13 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.tests.structuremergeviewer.actions;
+import static org.eclipse.emf.compare.DifferenceState.DISCARDED;
+import static org.eclipse.emf.compare.DifferenceState.MERGED;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.ACCEPT;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.REJECT;
+import static org.eclipse.emf.compare.internal.merge.MergeMode.getMergeMode;
+import static org.junit.Assert.assertEquals;
+
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@@ -19,11 +26,9 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Conflict;
import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions.MergeRunnableImpl;
-import org.eclipse.emf.compare.internal.merge.IMergeData;
-import org.eclipse.emf.compare.internal.merge.MergeMode;
+import org.eclipse.emf.compare.internal.merge.MergeDataImpl;
import org.eclipse.emf.compare.merge.BatchMerger;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin;
@@ -32,8 +37,6 @@ import org.eclipse.emf.compare.tests.framework.AbstractInputData;
import org.eclipse.emf.compare.tests.nodes.Node;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -84,25 +87,29 @@ public class TestBug434828_2 {
final Resource origin = inputData.getResource("origin.nodes"); //$NON-NLS-1$
scope = new DefaultComparisonScope(left, right, origin);
final Comparison comparison = EMFCompare.builder().build().compare(scope);
+
+ // Add a IMergeData to handle status decorations on Diffs
+ comparison.eAdapters().add(new MergeDataImpl(true, false));
+
mergerRegistry = EMFCompareRCPPlugin.getDefault().getMergerRegistry();
// Keeps tracks of the differences to test.
EList<Conflict> conflicts = comparison.getConflicts();
- Assert.assertEquals(1, conflicts.size());
+ assertEquals(1, conflicts.size());
Conflict conflict = conflicts.get(0);
// Get the right diff of the conflict: change of eopposite reference
EList<Diff> rightConflicts = conflict.getRightDifferences();
- Assert.assertEquals(2, rightConflicts.size());
+ assertEquals(2, rightConflicts.size());
refChangeDiff = rightConflicts.get(0);// Both difference are equivalent.
// Get the left diff of the conflict; deletion of "ReferencedNode"
EList<Diff> leftConflicts = conflict.getLeftDifferences();
- Assert.assertEquals(1, leftConflicts.size());
+ assertEquals(1, leftConflicts.size());
holdingRefDeletionDiff = leftConflicts.get(0);
// Get the required by diff of the left conflict
EList<Diff> leftRequiredBy = holdingRefDeletionDiff.getRequiredBy();
- Assert.assertEquals(1, leftRequiredBy.size());
+ assertEquals(1, leftRequiredBy.size());
deletedNodeDeletionDiff = leftRequiredBy.get(0);
}
@@ -120,29 +127,29 @@ public class TestBug434828_2 {
*/
@Test
public void testAcceptConflictDiffWithConflictingDiffWithRequiredBy() {
- MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, MergeMode.ACCEPT);
+ MergeRunnableImpl mergeRunnable = new MergeRunnableImpl(true, false, ACCEPT);
mergeRunnable.merge(Collections.singletonList(refChangeDiff), false, mergerRegistry);
- Assert.assertEquals(DifferenceState.MERGED, refChangeDiff.getState());
- Assert.assertEquals(MergeMode.ACCEPT, getMergeData(refChangeDiff).getMergeMode());
- Assert.assertEquals(DifferenceState.MERGED, holdingRefDeletionDiff.getState());
- Assert.assertEquals(MergeMode.REJECT, getMergeData(holdingRefDeletionDiff).getMergeMode());
+ assertEquals(MERGED, refChangeDiff.getState());
+ assertEquals(ACCEPT, getMergeMode(refChangeDiff, true, false));
+ assertEquals(DISCARDED, holdingRefDeletionDiff.getState());
+ assertEquals(REJECT, getMergeMode(holdingRefDeletionDiff, true, false));
- Assert.assertEquals(DifferenceState.MERGED, deletedNodeDeletionDiff.getState());
- Assert.assertEquals(MergeMode.REJECT, getMergeData(deletedNodeDeletionDiff).getMergeMode());
+ assertEquals(DISCARDED, deletedNodeDeletionDiff.getState());
+ assertEquals(REJECT, getMergeMode(deletedNodeDeletionDiff, true, false));
// Checks that the content of the left resource is correct.
Resource leftResource = (Resource)scope.getLeft();
EList<EObject> content = leftResource.getContents();
- Assert.assertEquals(1, content.size());
+ assertEquals(1, content.size());
Node root = (Node)content.get(0);
EList<Node> children = root.getContainmentRef1();
// Checks that "HoldingDeletedNode" is in the model.
- Assert.assertEquals(2, children.size());
+ assertEquals(2, children.size());
Node firstChildren = children.get(0);
// Checks that "ReferencedNode" is in the model.
- Assert.assertEquals(1, firstChildren.getContainmentRef1().size());
+ assertEquals(1, firstChildren.getContainmentRef1().size());
}
/**
@@ -152,26 +159,22 @@ public class TestBug434828_2 {
public void testAcceptConflictDiffWithConflictingDiffWithRequiredByProg() {
new BatchMerger(mergerRegistry).copyAllRightToLeft(Arrays.asList(refChangeDiff), new BasicMonitor());
- Assert.assertEquals(DifferenceState.MERGED, refChangeDiff.getState());
- Assert.assertEquals(DifferenceState.MERGED, holdingRefDeletionDiff.getState());
- Assert.assertEquals(DifferenceState.MERGED, deletedNodeDeletionDiff.getState());
+ assertEquals(MERGED, refChangeDiff.getState());
+ assertEquals(DISCARDED, holdingRefDeletionDiff.getState());
+ assertEquals(DISCARDED, deletedNodeDeletionDiff.getState());
// Checks that the content of the right resource is correct.
Resource leftResource = (Resource)scope.getLeft();
EList<EObject> content = leftResource.getContents();
- Assert.assertEquals(1, content.size());
+ assertEquals(1, content.size());
Node root = (Node)content.get(0);
EList<Node> children = root.getContainmentRef1();
// Checks that "DeletedNode" is in the model.
- Assert.assertEquals(2, children.size());
+ assertEquals(2, children.size());
Node firstChildren = children.get(0);
// Checks that "ReferencedNode" is in the model.
- Assert.assertEquals(1, firstChildren.getContainmentRef1().size());
- }
-
- private IMergeData getMergeData(Diff diff) {
- return (IMergeData)EcoreUtil.getExistingAdapter(diff, IMergeData.class);
+ assertEquals(1, firstChildren.getContainmentRef1().size());
}
/**
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug470503.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug470503.java
index 73f74ffa4..206048cb8 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug470503.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug470503.java
@@ -112,13 +112,13 @@ public class TestBug470503 extends AbstractTestUITreeNodeItemProviderAdapter {
action.updateSelection(new StructuredSelection(titledItemESuperTypesDelete));
setCascadingDifferencesFilterEnabled(cascadingFilter);
action.run();
- assertEquals(DifferenceState.MERGED, titledItemESuperTypesDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, titledItemESuperTypesDeleteDiff.getState());
Diff titledItemEClassifiersDeleteDiff = (Diff)titledItemEClassifiersDelete.getData();
- assertEquals(DifferenceState.MERGED, titledItemEClassifiersDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, titledItemEClassifiersDeleteDiff.getState());
Diff titleESFDeleteDiff = (Diff)titleESFDelete.getData();
- assertEquals(DifferenceState.MERGED, titleESFDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, titleESFDeleteDiff.getState());
}
@Test
@@ -139,10 +139,10 @@ public class TestBug470503 extends AbstractTestUITreeNodeItemProviderAdapter {
action.updateSelection(new StructuredSelection(titledItemESuperTypesDelete));
setCascadingDifferencesFilterEnabled(cascadingFilter);
action.run();
- assertEquals(DifferenceState.MERGED, titledItemESuperTypesDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, titledItemESuperTypesDeleteDiff.getState());
Diff titledItemEClassifiersDeleteDiff = (Diff)titledItemEClassifiersDelete.getData();
- assertEquals(DifferenceState.MERGED, titledItemEClassifiersDeleteDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, titledItemEClassifiersDeleteDiff.getState());
Diff titleESFDeleteDiff = (Diff)titleESFDelete.getData();
assertEquals(DifferenceState.UNRESOLVED, titleESFDeleteDiff.getState());
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug475586.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug475586.java
index 1102456a2..aaaf1d84c 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug475586.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/structuremergeviewer/actions/TestBug475586.java
@@ -139,7 +139,7 @@ public class TestBug475586 extends AbstractTestUITreeNodeItemProviderAdapter {
action.updateSelection(new StructuredSelection(nameSetC));
setCascadingDifferencesFilterEnabled(cascadingFilter);
action.run();
- assertEquals(DifferenceState.MERGED, nodeC.getState());
+ assertEquals(DifferenceState.DISCARDED, nodeC.getState());
Diff nodeA = (Diff)containmentRefDeleteA.getData();
assertEquals(DifferenceState.UNRESOLVED, nodeA.getState());
@@ -167,7 +167,7 @@ public class TestBug475586 extends AbstractTestUITreeNodeItemProviderAdapter {
assertEquals(DifferenceState.MERGED, nodeC.getState());
Diff nodeA = (Diff)containmentRefDeleteA.getData();
- assertEquals(DifferenceState.MERGED, nodeA.getState());
+ assertEquals(DifferenceState.DISCARDED, nodeA.getState());
Diff nodeB = (Diff)singleValuedReferenceUnsetB.getData();
assertEquals(DifferenceState.UNRESOLVED, nodeB.getState());
@@ -189,7 +189,7 @@ public class TestBug475586 extends AbstractTestUITreeNodeItemProviderAdapter {
action.updateSelection(new StructuredSelection(nameSetC));
setCascadingDifferencesFilterEnabled(cascadingFilter);
action.run();
- assertEquals(DifferenceState.MERGED, nodeC.getState());
+ assertEquals(DifferenceState.DISCARDED, nodeC.getState());
Diff nodeA = (Diff)containmentRefDeleteA.getData();
assertEquals(DifferenceState.UNRESOLVED, nodeA.getState());
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/provider/TreeMergeViewerItemContentProvider.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/provider/TreeMergeViewerItemContentProvider.java
index 76ddd0009..4a02b6039 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/provider/TreeMergeViewerItemContentProvider.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/tree/provider/TreeMergeViewerItemContentProvider.java
@@ -20,6 +20,7 @@ import static com.google.common.collect.Iterables.size;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.newArrayListWithCapacity;
import static java.util.Collections.emptyList;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.CONTAINMENT_REFERENCE_CHANGE;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.anyRefining;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
@@ -46,7 +47,6 @@ import org.eclipse.emf.compare.ConflictKind;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.graph.IGraphView;
@@ -343,7 +343,7 @@ public class TreeMergeViewerItemContentProvider implements IMergeViewerItemConte
Match match = comparison.getMatch(value);
if (!isPseudoAddConflict(diff) && (isAddOnOppositeSide(diff, side)
|| isDeleteOnSameSide(diff, side) || isInsertOnBothSides(diff, match))) {
- if (match == null && diff.getState() == DifferenceState.MERGED) {
+ if (match == null && isInTerminalState(diff)) {
EObject bestSideValue = (EObject)getBestSideValue(parent, configuration.getSide());
match = comparison.getMatch(bestSideValue);
match = getMatchWithNullValues(match);
@@ -520,7 +520,7 @@ public class TreeMergeViewerItemContentProvider implements IMergeViewerItemConte
Match match = comparison.getMatch(value);
if (isAddOnOppositeSide(diff, side) || isDeleteOnSameSide(diff, side)
|| isInsertOnBothSides(diff, match)) {
- if (match == null && diff.getState() == DifferenceState.MERGED) {
+ if (match == null && isInTerminalState(diff)) {
EObject bestSideValue = (EObject)getBestSideValue(parent, configuration.getSide());
match = comparison.getMatch(bestSideValue);
match = getMatchWithNullValues(match);
@@ -817,7 +817,7 @@ public class TreeMergeViewerItemContentProvider implements IMergeViewerItemConte
* {@code false} otherwise.
*/
private boolean isInsertOnBothSides(Diff diff, Match match) {
- return diff.getState() == DifferenceState.MERGED
+ return isInTerminalState(diff)
&& (match == null || (match.getLeft() == null && match.getRight() == null));
}
@@ -861,7 +861,7 @@ public class TreeMergeViewerItemContentProvider implements IMergeViewerItemConte
* otherwise.
*/
private boolean isAddOnOppositeSide(Diff diff, MergeViewerSide side) {
- if (diff.getState() != DifferenceState.MERGED && diff.getKind() == DifferenceKind.ADD) {
+ if (!isInTerminalState(diff) && diff.getKind() == DifferenceKind.ADD) {
DifferenceSource source = diff.getSource();
return (source == DifferenceSource.LEFT && side == MergeViewerSide.RIGHT)
|| (source == DifferenceSource.RIGHT && side == MergeViewerSide.LEFT);
@@ -880,7 +880,7 @@ public class TreeMergeViewerItemContentProvider implements IMergeViewerItemConte
* otherwise.
*/
private boolean isDeleteOnSameSide(Diff diff, MergeViewerSide side) {
- if (diff.getState() != DifferenceState.MERGED && diff.getKind() == DifferenceKind.DELETE) {
+ if (!isInTerminalState(diff) && diff.getKind() == DifferenceKind.DELETE) {
DifferenceSource source = diff.getSource();
return (source == DifferenceSource.LEFT && side == MergeViewerSide.LEFT)
|| (source == DifferenceSource.RIGHT && side == MergeViewerSide.RIGHT);
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/ide_ui_messages.properties b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/ide_ui_messages.properties
index 2f5eb787c..995c4e0dc 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/ide_ui_messages.properties
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/ide_ui_messages.properties
@@ -101,6 +101,7 @@ ComparisonScopeBuilder.right = right
ComparisonScopeBuilder.ancestor = ancestor
ComparisonScopeBuilder.resourceSetDiagnostic = Problems occurred while loading resources from the {0} side
ComparisonScopeBuilder.comparisonScopeDiagnostic = Problems occurred while creating the comparison scope
+DiffStateAdapter_WrongAdapterInstalled=Unknown adapter for DiffStateAdapter installed on comparison
SynchronizationModel.diagnosticMesg = Problems occurred while computing the synchronization model
SynchronizationModel.root = Synchronization (EMF Compare)
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
index a13d292fc..35e0f0f55 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/EMFCompareStructureMergeViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2016 Obeo and others.
+ * Copyright (c) 2013, 2017 Obeo and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -109,6 +109,7 @@ import org.eclipse.emf.compare.ide.ui.internal.util.CompareHandlerService;
import org.eclipse.emf.compare.ide.ui.internal.util.FilteredIterator;
import org.eclipse.emf.compare.ide.ui.internal.util.JFaceUtil;
import org.eclipse.emf.compare.ide.ui.internal.util.PlatformElementUtil;
+import org.eclipse.emf.compare.internal.merge.MergeDataImpl;
import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.merge.AbstractMerger;
import org.eclipse.emf.compare.merge.IMergeOptionAware;
@@ -1243,6 +1244,11 @@ public class EMFCompareStructureMergeViewer extends AbstractStructuredViewerWrap
}
// Bug 501569: The cascading filter does not hide merged cascading diffs
new MatchOfContainmentReferenceChangeProcessor().execute(compareResult);
+
+ // Add a MergeData to handle status decorations on Diffs
+ MergeDataImpl mergeData = new MergeDataImpl(getCompareConfiguration().isLeftEditable(),
+ getCompareConfiguration().isRightEditable());
+ compareResult.eAdapters().add(mergeData);
}
/**
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeRunnable.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeRunnable.java
index 851d36395..cdec275b8 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeRunnable.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/AbstractMergeRunnable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2015 Obeo.
+ * Copyright (c) 2014, 2017 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,19 +10,20 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.structuremergeviewer.actions;
+import static org.eclipse.emf.compare.DifferenceState.DISCARDED;
+import static org.eclipse.emf.compare.DifferenceState.MERGED;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isAccepting;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
+
import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.Set;
import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceState;
-import org.eclipse.emf.compare.internal.merge.IMergeData;
-import org.eclipse.emf.compare.internal.merge.MergeDataImpl;
import org.eclipse.emf.compare.internal.merge.MergeDependenciesUtil;
import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.merge.IMerger.Registry;
-import org.eclipse.emf.ecore.util.EcoreUtil;
/**
* Provides inheritable default behavior for the merge runnables.
@@ -99,60 +100,26 @@ public abstract class AbstractMergeRunnable {
*/
protected void markAsMerged(Diff diff, MergeMode mode, boolean mergeRightToLeft,
Registry mergerRegistry) {
- if (diff.getState() == DifferenceState.MERGED) {
+ if (isInTerminalState(diff)) {
return;
}
-
- final Set<Diff> implied = MergeDependenciesUtil.getAllResultingMerges(diff, mergerRegistry,
- mergeRightToLeft);
- final Set<Diff> rejections = MergeDependenciesUtil.getAllResultingRejections(diff, mergerRegistry,
- mergeRightToLeft);
- for (Diff impliedDiff : Sets.difference(implied, rejections)) {
- impliedDiff.setState(DifferenceState.MERGED);
- addOrUpdateMergeData(impliedDiff, mode);
- }
-
- for (Diff impliedRejection : rejections) {
- impliedRejection.setState(DifferenceState.MERGED);
- if (mergeMode == MergeMode.LEFT_TO_RIGHT || mergeMode == MergeMode.RIGHT_TO_LEFT) {
- addOrUpdateMergeData(impliedRejection, mode);
- } else {
- addOrUpdateMergeData(impliedRejection, mode.inverse());
+ if (isAccepting(diff, mergeRightToLeft)) {
+ final Set<Diff> implied = MergeDependenciesUtil.getAllResultingMerges(diff, mergerRegistry,
+ mergeRightToLeft);
+ final Set<Diff> rejections = MergeDependenciesUtil.getAllResultingRejections(diff, mergerRegistry,
+ mergeRightToLeft);
+ for (Diff impliedDiff : Sets.difference(implied, rejections)) {
+ impliedDiff.setState(MERGED);
+ }
+ for (Diff impliedRejection : rejections) {
+ impliedRejection.setState(DISCARDED);
}
- }
- }
-
- /**
- * Updates the IMergeData adapter for all of the given diffs.
- *
- * @param differences
- * The differences for which to set or update the IMergeData adapter.
- * @param mode
- * Merge mode we wish to keep track of.
- */
- protected void addOrUpdateMergeData(Collection<Diff> differences, MergeMode mode) {
- for (Diff difference : differences) {
- addOrUpdateMergeData(difference, mode);
- }
- }
-
- /**
- * Updates the IMergeData adapter for the given diff.
- *
- * @param diff
- * The difference for which to set or update the IMergeData adapter.
- * @param mode
- * Merge mode we wish to keep track of.
- */
- private void addOrUpdateMergeData(Diff diff, MergeMode mode) {
- IMergeData mergeData = (IMergeData)EcoreUtil.getExistingAdapter(diff, IMergeData.class);
- if (mergeData != null) {
- mergeData.setMergeMode(mode);
- mergeData.setLeftEditable(isLeftEditable);
- mergeData.setRightEditable(isRightEditable);
} else {
- mergeData = new MergeDataImpl(mode, isLeftEditable, isRightEditable);
- diff.eAdapters().add(mergeData);
+ final Set<Diff> implied = MergeDependenciesUtil.getAllResultingMerges(diff, mergerRegistry,
+ mergeRightToLeft);
+ for (Diff impliedDiff : implied) {
+ impliedDiff.setState(DISCARDED);
+ }
}
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeNonConflictingRunnable.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeNonConflictingRunnable.java
index 640982da7..de5972c33 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeNonConflictingRunnable.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeNonConflictingRunnable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2014, 2016 Obeo and others.
+ * Copyright (c) 2014, 2017 Obeo and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -35,7 +35,6 @@ import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -48,7 +47,6 @@ import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceSource;
import org.eclipse.emf.compare.domain.IMergeRunnable;
import org.eclipse.emf.compare.internal.domain.IMergeAllNonConflictingRunnable;
-import org.eclipse.emf.compare.internal.merge.MergeDependenciesUtil;
import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.internal.merge.MergeOperation;
import org.eclipse.emf.compare.internal.utils.ComparisonUtil;
@@ -58,7 +56,6 @@ import org.eclipse.emf.compare.merge.IBatchMerger;
import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.merge.IMerger.Registry;
import org.eclipse.emf.compare.merge.IMerger.Registry2;
-import org.eclipse.emf.compare.merge.IMerger2;
import org.eclipse.emf.compare.merge.MergeBlockedByConflictException;
/**
@@ -155,16 +152,15 @@ public class MergeNonConflictingRunnable extends AbstractMergeRunnable implement
Registry mergerRegistry) {
final List<Diff> affectedDiffs;
final IBatchMerger merger = new BatchMerger(mergerRegistry);
+
if (getMergeMode() == MergeMode.LEFT_TO_RIGHT) {
affectedDiffs = Lists
.newArrayList(Iterables.filter(differences, fromSide(DifferenceSource.LEFT)));
merger.copyAllLeftToRight(affectedDiffs, new BasicMonitor());
- addOrUpdateMergeData(affectedDiffs, getMergeMode());
} else if (getMergeMode() == MergeMode.RIGHT_TO_LEFT) {
affectedDiffs = Lists
.newArrayList(Iterables.filter(differences, fromSide(DifferenceSource.RIGHT)));
merger.copyAllRightToLeft(affectedDiffs, new BasicMonitor());
- addOrUpdateMergeData(affectedDiffs, getMergeMode());
} else if (getMergeMode() == MergeMode.ACCEPT || getMergeMode() == MergeMode.REJECT) {
affectedDiffs = acceptOrRejectWithoutConflicts(differences, leftToRight, mergerRegistry, merger);
} else {
@@ -210,12 +206,10 @@ public class MergeNonConflictingRunnable extends AbstractMergeRunnable implement
affectedDiffs = Lists
.newArrayList(Iterables.filter(differences, fromSide(DifferenceSource.LEFT)));
merger.copyAllLeftToRight(affectedDiffs, new BasicMonitor());
- addOrUpdateMergeData(affectedDiffs, getMergeMode());
} else if (getMergeMode() == MergeMode.RIGHT_TO_LEFT) {
affectedDiffs = Lists
.newArrayList(Iterables.filter(differences, fromSide(DifferenceSource.LEFT)));
merger.copyAllRightToLeft(affectedDiffs, new BasicMonitor());
- addOrUpdateMergeData(affectedDiffs, getMergeMode());
} else if (getMergeMode() == MergeMode.ACCEPT || getMergeMode() == MergeMode.REJECT) {
affectedDiffs = acceptOrRejectWithoutConflicts(differences, leftToRight, mergerRegistry, merger);
} else {
@@ -242,6 +236,7 @@ public class MergeNonConflictingRunnable extends AbstractMergeRunnable implement
final Monitor emfMonitor = new BasicMonitor();
ComputeDiffsToMerge computer = new ComputeDiffsToMerge(!leftToRight, (Registry2)mergerRegistry)
.failOnRealConflictUnless(alwaysFalse());
+
final Predicate<? super Diff> filter;
if (getMergeMode() == RIGHT_TO_LEFT) {
filter = fromSide(RIGHT);
@@ -265,7 +260,6 @@ public class MergeNonConflictingRunnable extends AbstractMergeRunnable implement
}
}
- addOrUpdateMergeData(affectedDiffs, getMergeMode());
return affectedDiffs;
}
@@ -378,26 +372,5 @@ public class MergeNonConflictingRunnable extends AbstractMergeRunnable implement
} else {
merger.copyAllRightToLeft(differences, emfMonitor);
}
-
- for (Diff difference : differences) {
- final IMerger diffMerger = mergerRegistry.getHighestRankingMerger(difference);
-
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("mergeAll - Selected merger for diff " + difference.hashCode() //$NON-NLS-1$
- + ": " + merger.getClass().getSimpleName()); //$NON-NLS-1$
- }
-
- if (diffMerger instanceof IMerger2) {
- final Set<Diff> resultingMerges = MergeDependenciesUtil.getAllResultingMerges(difference,
- mergerRegistry, !leftToRight);
- addOrUpdateMergeData(resultingMerges, getMergeMode());
-
- final Set<Diff> resultingRejections = MergeDependenciesUtil
- .getAllResultingRejections(difference, mergerRegistry, !leftToRight);
- addOrUpdateMergeData(resultingRejections, getMergeMode().inverse());
- } else {
- addOrUpdateMergeData(Collections.singleton(difference), getMergeMode());
- }
- }
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeRunnableImpl.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeRunnableImpl.java
index 46b70d23c..f692550b5 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeRunnableImpl.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/structuremergeviewer/actions/MergeRunnableImpl.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2014 Obeo.
+ * Copyright (c) 2013, 2017 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,21 +15,16 @@ import static com.google.common.collect.Lists.newArrayList;
import com.google.common.base.Preconditions;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
-import java.util.Set;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.domain.IMergeRunnable;
-import org.eclipse.emf.compare.internal.merge.MergeDependenciesUtil;
import org.eclipse.emf.compare.internal.merge.MergeMode;
import org.eclipse.emf.compare.internal.merge.MergeOperation;
import org.eclipse.emf.compare.merge.BatchMerger;
import org.eclipse.emf.compare.merge.IBatchMerger;
-import org.eclipse.emf.compare.merge.IMerger;
import org.eclipse.emf.compare.merge.IMerger.Registry;
-import org.eclipse.emf.compare.merge.IMerger2;
/**
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
@@ -45,7 +40,6 @@ public final class MergeRunnableImpl extends AbstractMergeRunnable implements IM
public void merge(List<? extends Diff> differences, boolean leftToRight, Registry mergerRegistry) {
Preconditions
.checkState(getMergeMode().isLeftToRight(isLeftEditable(), isRightEditable()) == leftToRight);
-
// Execute merge
if (getMergeMode() == MergeMode.LEFT_TO_RIGHT || getMergeMode() == MergeMode.RIGHT_TO_LEFT) {
mergeAll(differences, leftToRight, mergerRegistry);
@@ -82,24 +76,5 @@ public final class MergeRunnableImpl extends AbstractMergeRunnable implements IM
} else {
merger.copyAllRightToLeft(differences, new BasicMonitor());
}
-
- for (Diff difference : differences) {
- final IMerger diffMerger = mergerRegistry.getHighestRankingMerger(difference);
- if (diffMerger instanceof IMerger2) {
- final Set<Diff> resultingMerges = MergeDependenciesUtil.getAllResultingMerges(difference,
- mergerRegistry, !leftToRight);
- addOrUpdateMergeData(resultingMerges, getMergeMode());
-
- final Set<Diff> resultingRejections = MergeDependenciesUtil
- .getAllResultingRejections(difference, mergerRegistry, !leftToRight);
- if (getMergeMode() == MergeMode.LEFT_TO_RIGHT || getMergeMode() == MergeMode.RIGHT_TO_LEFT) {
- addOrUpdateMergeData(resultingRejections, getMergeMode());
- } else {
- addOrUpdateMergeData(resultingRejections, getMergeMode().inverse());
- }
- } else {
- addOrUpdateMergeData(Collections.singleton(difference), getMergeMode());
- }
- }
}
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ContainmentReferenceChangeAccessorImpl.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ContainmentReferenceChangeAccessorImpl.java
index 262045b68..1840be822 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ContainmentReferenceChangeAccessorImpl.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ContainmentReferenceChangeAccessorImpl.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.impl
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getFirst;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.CONTAINMENT_REFERENCE_CHANGE;
import com.google.common.collect.ImmutableList;
@@ -22,7 +23,6 @@ import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.TypeConstants;
@@ -77,8 +77,7 @@ public class ContainmentReferenceChangeAccessorImpl extends AbstractStructuralFe
EObject diffValue = (EObject)MergeViewerUtil.getDiffValue(initialDiff);
Match match = getComparison().getMatch(diffValue);
- if (match == null && DifferenceState.MERGED == initialDiff.getState()
- && MergeViewerSide.ANCESTOR != getSide()) {
+ if (match == null && isInTerminalState(initialDiff) && MergeViewerSide.ANCESTOR != getSide()) {
match = getMatchWithNullValues(initialDiff.getMatch());
}
if (match != null) {
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/FeatureMapKeyChangeAccessorImpl.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/FeatureMapKeyChangeAccessorImpl.java
index b9b631b45..a26658afe 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/FeatureMapKeyChangeAccessorImpl.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/FeatureMapKeyChangeAccessorImpl.java
@@ -10,14 +10,17 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.impl;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
+
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.eclipse.emf.common.notify.AdapterFactory;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.FeatureMapChange;
import org.eclipse.emf.compare.internal.merge.IMergeData;
+import org.eclipse.emf.compare.internal.merge.MergeMode;
+import org.eclipse.emf.compare.internal.utils.ComparisonUtil;
import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.item.impl.MergeViewerItem;
import org.eclipse.emf.compare.rcp.ui.mergeviewer.IMergeViewer.MergeViewerSide;
import org.eclipse.emf.compare.rcp.ui.mergeviewer.item.IMergeViewerItem;
@@ -88,9 +91,9 @@ public class FeatureMapKeyChangeAccessorImpl extends AbstractStructuralFeatureAc
final FeatureMapChange diff = (FeatureMapChange)getInitialDiff();
final FeatureMap.Entry entry = (FeatureMap.Entry)diff.getValue();
if ((side != MergeViewerSide.ANCESTOR && side.convertToDifferenceSource().equals(diff.getSource()))
- && diff.getState() != DifferenceState.MERGED) {
+ && !isInTerminalState(diff)) {
key = entry.getEStructuralFeature();
- } else if (diff.getState() == DifferenceState.MERGED && !isMergedTargetIsSource(diff)) {
+ } else if (isInTerminalState(diff) && !isMergedTargetIsSource(diff)) {
key = entry.getEStructuralFeature();
} else {
// The entry of the diff source side.
@@ -124,7 +127,14 @@ public class FeatureMapKeyChangeAccessorImpl extends AbstractStructuralFeatureAc
* source, false otherwise.
*/
private boolean isMergedTargetIsSource(FeatureMapChange diff) {
- IMergeData mergeData = (IMergeData)EcoreUtil.getExistingAdapter(diff, IMergeData.class);
- return diff.getSource() == mergeData.getMergeTarget();
+ IMergeData mergeData = (IMergeData)EcoreUtil.getExistingAdapter(ComparisonUtil.getComparison(diff),
+ IMergeData.class);
+ if (mergeData != null) {
+ MergeMode mode = MergeMode.getMergeMode(diff, mergeData.isLeftEditable(),
+ mergeData.isRightEditable());
+ return diff.getSource() == mode.getMergeTarget(mergeData.isLeftEditable(),
+ mergeData.isRightEditable());
+ }
+ return false;
}
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ResourceContentsAccessorImpl.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ResourceContentsAccessorImpl.java
index b62132a80..58747a68d 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ResourceContentsAccessorImpl.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ResourceContentsAccessorImpl.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.emf.compare.rcp.ui.internal.contentmergeviewer.accessor.impl;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
+
import com.google.common.collect.ImmutableList;
import org.eclipse.emf.common.notify.AdapterFactory;
@@ -17,7 +19,6 @@ import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.rcp.ui.contentmergeviewer.accessor.IResourceContentsAccessor;
@@ -86,7 +87,7 @@ public class ResourceContentsAccessorImpl extends AbstractTypedElementAdapter im
Diff initialDiff = fDiff;
EObject diffValue = (EObject)MergeViewerUtil
.getResourceAttachmentChangeValue((ResourceAttachmentChange)initialDiff, getSide());
- if (DifferenceState.MERGED == initialDiff.getState()) {
+ if (isInTerminalState(initialDiff)) {
Object left = MergeViewerUtil.getValueFromResourceAttachmentChange(
(ResourceAttachmentChange)initialDiff, getComparison(), MergeViewerSide.LEFT);
Object right = MergeViewerUtil.getValueFromResourceAttachmentChange(
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/mergeviewer/item/impl/MergeViewerItem.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/mergeviewer/item/impl/MergeViewerItem.java
index c454dd3b6..a65f13076 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/mergeviewer/item/impl/MergeViewerItem.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/mergeviewer/item/impl/MergeViewerItem.java
@@ -17,6 +17,7 @@ import static com.google.common.collect.Iterables.isEmpty;
import static com.google.common.collect.Iterables.size;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.newArrayListWithCapacity;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.CONTAINMENT_REFERENCE_CHANGE;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.onFeature;
@@ -47,7 +48,6 @@ import org.eclipse.emf.compare.ConflictKind;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.compare.ResourceAttachmentChange;
@@ -367,7 +367,7 @@ public class MergeViewerItem extends AdapterImpl implements IMergeViewerItem {
Match match = getComparison().getMatch(value);
if (!isPseudoAddConflict(diff) && (isAddOnOppositeSide(diff) || isDeleteOnSameSide(diff)
|| isInsertOnBothSides(diff, match))) {
- if (match == null && diff.getState() == DifferenceState.MERGED) {
+ if (match == null && isInTerminalState(diff)) {
EObject bestSideValue = (EObject)getBestSideValue();
match = getComparison().getMatch(bestSideValue);
match = getMatchWithNullValues(match);
@@ -410,7 +410,7 @@ public class MergeViewerItem extends AdapterImpl implements IMergeViewerItem {
}
private boolean isAddOnOppositeSide(Diff diff) {
- if (diff.getState() != DifferenceState.MERGED && diff.getKind() == DifferenceKind.ADD) {
+ if (!isInTerminalState(diff) && diff.getKind() == DifferenceKind.ADD) {
DifferenceSource source = diff.getSource();
MergeViewerSide side = getSide();
return (source == DifferenceSource.LEFT && side == MergeViewerSide.RIGHT)
@@ -421,7 +421,7 @@ public class MergeViewerItem extends AdapterImpl implements IMergeViewerItem {
}
private boolean isDeleteOnSameSide(Diff diff) {
- if (diff.getState() != DifferenceState.MERGED && diff.getKind() == DifferenceKind.DELETE) {
+ if (!isInTerminalState(diff) && diff.getKind() == DifferenceKind.DELETE) {
DifferenceSource source = diff.getSource();
MergeViewerSide side = getSide();
return (source == DifferenceSource.LEFT && side == MergeViewerSide.LEFT)
@@ -432,7 +432,7 @@ public class MergeViewerItem extends AdapterImpl implements IMergeViewerItem {
}
private boolean isInsertOnBothSides(Diff diff, Match match) {
- return diff.getState() == DifferenceState.MERGED
+ return isInTerminalState(diff)
&& (match == null || (match.getLeft() == null && match.getRight() == null));
}
@@ -533,7 +533,7 @@ public class MergeViewerItem extends AdapterImpl implements IMergeViewerItem {
Match match = getComparison().getMatch(value);
if (isAddOnOppositeSide(diff) || isDeleteOnSameSide(diff)
|| isInsertOnBothSides(diff, match)) {
- if (match == null && diff.getState() == DifferenceState.MERGED) {
+ if (match == null && isInTerminalState(diff)) {
EObject bestSideValue = (EObject)getBestSideValue();
match = getComparison().getMatch(bestSideValue);
match = getMatchWithNullValues(match);
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/mergeviewer/item/impl/ResourceAttachmentChangeMergeViewerItem.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/mergeviewer/item/impl/ResourceAttachmentChangeMergeViewerItem.java
index fcc24a51a..57a304838 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/mergeviewer/item/impl/ResourceAttachmentChangeMergeViewerItem.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/mergeviewer/item/impl/ResourceAttachmentChangeMergeViewerItem.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.item.impl;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.getFirst;
import static com.google.common.collect.Lists.newArrayList;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
@@ -26,7 +27,6 @@ import org.eclipse.emf.compare.ConflictKind;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ResourceAttachmentChange;
import org.eclipse.emf.compare.internal.utils.DiffUtil;
@@ -106,7 +106,7 @@ public class ResourceAttachmentChangeMergeViewerItem extends MergeViewerItem.Con
Object ancestor = getAncestor();
for (ResourceAttachmentChange resourceAttachmentChange : racs) {
// filter out merged reference changes
- if (resourceAttachmentChange.getState() == DifferenceState.MERGED) {
+ if (isInTerminalState(resourceAttachmentChange)) {
// Remove resource attachment changes that are not linked with the current resources.
resourceAttachmentChanges.remove(resourceAttachmentChange);
} else if (isUnrelated(resourceAttachmentChange, left)
@@ -195,23 +195,22 @@ public class ResourceAttachmentChangeMergeViewerItem extends MergeViewerItem.Con
DifferenceSource source = diff.getSource();
DifferenceKind kind = diff.getKind();
- DifferenceState state = diff.getState();
boolean b1 = source == DifferenceSource.LEFT && kind == DifferenceKind.DELETE
- && getSide() == MergeViewerSide.LEFT && DifferenceState.MERGED != state;
+ && getSide() == MergeViewerSide.LEFT && !isInTerminalState(diff);
boolean b2 = source == DifferenceSource.LEFT && kind == DifferenceKind.ADD
- && getSide() == MergeViewerSide.RIGHT && DifferenceState.MERGED != state;
+ && getSide() == MergeViewerSide.RIGHT && !isInTerminalState(diff);
boolean b3 = source == DifferenceSource.RIGHT && kind == DifferenceKind.ADD
- && getSide() == MergeViewerSide.LEFT && DifferenceState.MERGED != state;
+ && getSide() == MergeViewerSide.LEFT && !isInTerminalState(diff);
boolean b4 = source == DifferenceSource.RIGHT && kind == DifferenceKind.DELETE
- && getSide() == MergeViewerSide.RIGHT && DifferenceState.MERGED != state;
+ && getSide() == MergeViewerSide.RIGHT && !isInTerminalState(diff);
- boolean b5 = DifferenceState.MERGED == state && source == DifferenceSource.LEFT
+ boolean b5 = isInTerminalState(diff) && source == DifferenceSource.LEFT
&& kind == DifferenceKind.ADD && right == null;
- boolean b6 = DifferenceState.MERGED == state && source == DifferenceSource.LEFT
+ boolean b6 = isInTerminalState(diff) && source == DifferenceSource.LEFT
&& kind == DifferenceKind.DELETE && left == null;
- boolean b7 = DifferenceState.MERGED == state && source == DifferenceSource.RIGHT
+ boolean b7 = isInTerminalState(diff) && source == DifferenceSource.RIGHT
&& kind == DifferenceKind.ADD && left == null;
- boolean b8 = DifferenceState.MERGED == state && source == DifferenceSource.RIGHT
+ boolean b8 = isInTerminalState(diff) && source == DifferenceSource.RIGHT
&& kind == DifferenceKind.DELETE && right == null;
// do not duplicate insertion point for pseudo add conflict
// so we must only create one for pseudo delete conflict
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/util/MergeViewerUtil.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/util/MergeViewerUtil.java
index 9da9bf432..1d3fabc4c 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/util/MergeViewerUtil.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/util/MergeViewerUtil.java
@@ -11,6 +11,7 @@
package org.eclipse.emf.compare.rcp.ui.internal.util;
import static com.google.common.collect.Iterables.any;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
import com.google.common.base.Predicate;
@@ -23,7 +24,6 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.AttributeChange;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.FeatureMapChange;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.MatchResource;
@@ -411,7 +411,7 @@ public final class MergeViewerUtil {
*
* @see MergeOperation
* @param diff
- * the given Diff..
+ * the given Diff.
* @param item
* the given IMergeViewerItem associated with the diff.
* @param compareConfiguration
@@ -421,12 +421,12 @@ public final class MergeViewerUtil {
public static boolean isMarkAsMerged(Diff diff, IMergeViewerItem item,
IEMFCompareConfiguration compareConfiguration) {
final boolean markAsMerged;
- if (diff.getState() == DifferenceState.MERGED) {
+ if (isInTerminalState(diff)) {
IMergeData mergeData = (IMergeData)EcoreUtil.getExistingAdapter(diff, IMergeData.class);
if (mergeData != null) {
boolean leftEditable = compareConfiguration.isLeftEditable();
boolean rightEditable = compareConfiguration.isRightEditable();
- MergeMode mergeMode = mergeData.getMergeMode();
+ MergeMode mergeMode = MergeMode.getMergeMode(diff, leftEditable, rightEditable);
MergeOperation mergeAction = mergeMode.getMergeAction(diff, leftEditable, rightEditable);
if (mergeAction == MergeOperation.MARK_AS_MERGE) {
markAsMerged = true;
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/ResourceAttachmentChangeBug492261.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/ResourceAttachmentChangeBug492261.java
index 3be135c9b..fb501180b 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/ResourceAttachmentChangeBug492261.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/fragmentation/ResourceAttachmentChangeBug492261.java
@@ -178,8 +178,8 @@ public class ResourceAttachmentChangeBug492261 {
} else {
batchMerger.copyAllLeftToRight(Arrays.asList(rac), new BasicMonitor());
}
- assertEquals(DifferenceState.MERGED, rac.getState());
- assertEquals(DifferenceState.MERGED, container.getState());
+ assertEquals(DifferenceState.DISCARDED, rac.getState());
+ assertEquals(DifferenceState.DISCARDED, container.getState());
assertEquals(DifferenceState.UNRESOLVED, innerNode.getState());
if (fragmentedOnLeft) {
@@ -187,9 +187,9 @@ public class ResourceAttachmentChangeBug492261 {
} else {
batchMerger.copyAllLeftToRight(Arrays.asList(innerNode), new BasicMonitor());
}
- assertEquals(DifferenceState.MERGED, rac.getState());
- assertEquals(DifferenceState.MERGED, container.getState());
- assertEquals(DifferenceState.MERGED, innerNode.getState());
+ assertEquals(DifferenceState.DISCARDED, rac.getState());
+ assertEquals(DifferenceState.DISCARDED, container.getState());
+ assertEquals(DifferenceState.DISCARDED, innerNode.getState());
comparison = EMFCompare.builder().build().compare(scope);
assertEquals(0, comparison.getDifferences().size());
@@ -229,7 +229,7 @@ public class ResourceAttachmentChangeBug492261 {
} else {
batchMerger.copyAllLeftToRight(Arrays.asList(rac), new BasicMonitor());
}
- assertEquals(DifferenceState.MERGED, rac.getState());
+ assertEquals(DifferenceState.DISCARDED, rac.getState());
assertEquals(DifferenceState.UNRESOLVED, container.getState());
assertEquals(DifferenceState.UNRESOLVED, innerNode.getState());
@@ -238,9 +238,9 @@ public class ResourceAttachmentChangeBug492261 {
} else {
batchMerger.copyAllLeftToRight(Arrays.asList(container), new BasicMonitor());
}
- assertEquals(DifferenceState.MERGED, rac.getState());
- assertEquals(DifferenceState.MERGED, container.getState());
- assertEquals(DifferenceState.MERGED, innerNode.getState());
+ assertEquals(DifferenceState.DISCARDED, rac.getState());
+ assertEquals(DifferenceState.DISCARDED, container.getState());
+ assertEquals(DifferenceState.DISCARDED, innerNode.getState());
comparison = EMFCompare.builder().build().compare(scope);
assertEquals(0, comparison.getDifferences().size());
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/ConflictMergeTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/ConflictMergeTest.java
index 9662ce0e2..065df3985 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/ConflictMergeTest.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/ConflictMergeTest.java
@@ -12,6 +12,10 @@ package org.eclipse.emf.compare.tests.merge;
import static com.google.common.base.Predicates.and;
import static com.google.common.base.Predicates.not;
+import static org.eclipse.emf.compare.DifferenceState.DISCARDED;
+import static org.eclipse.emf.compare.DifferenceState.MERGED;
+import static org.eclipse.emf.compare.DifferenceState.UNRESOLVED;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.addedToAttribute;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.fromSide;
import static org.eclipse.emf.compare.utils.EMFComparePredicates.hasState;
@@ -39,7 +43,6 @@ import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceKind;
import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.EMFCompare;
import org.eclipse.emf.compare.merge.BatchMerger;
import org.eclipse.emf.compare.merge.IMerger;
@@ -119,12 +122,12 @@ public class ConflictMergeTest {
final EList<Node> bContainmentRef1s = ((Node)rightNodeB).getContainmentRef1();
assertFalse(bContainmentRef1s.contains(rightNodeC));
- assertEquals(DifferenceState.MERGED, diffNodeCLeft.getState());
- assertEquals(DifferenceState.MERGED, diffNodeCRight.getState());
- assertEquals(DifferenceState.MERGED, diffNodeDLeft.getState());
- assertEquals(DifferenceState.MERGED, diffNodeDRight.getState());
- assertEquals(DifferenceState.UNRESOLVED, diffNodeELeft.getState());
- assertEquals(DifferenceState.MERGED, diffNodeFRight.getState());
+ assertEquals(MERGED, diffNodeCLeft.getState());
+ assertEquals(DISCARDED, diffNodeCRight.getState());
+ assertEquals(MERGED, diffNodeDLeft.getState());
+ assertEquals(MERGED, diffNodeDRight.getState());
+ assertEquals(UNRESOLVED, diffNodeELeft.getState());
+ assertEquals(DISCARDED, diffNodeFRight.getState());
}
@SuppressWarnings("unchecked")
@@ -182,12 +185,12 @@ public class ConflictMergeTest {
final EList<Node> bContainmentRef1s = ((Node)rightNodeB).getContainmentRef1();
assertFalse(bContainmentRef1s.contains(rightNodeC));
- assertEquals(DifferenceState.UNRESOLVED, diffNodeCLeft.getState());
- assertEquals(DifferenceState.MERGED, diffNodeCRight.getState());
- assertEquals(DifferenceState.MERGED, diffNodeDLeft.getState());
- assertEquals(DifferenceState.MERGED, diffNodeDRight.getState());
- assertEquals(DifferenceState.UNRESOLVED, diffNodeELeft.getState());
- assertEquals(DifferenceState.MERGED, diffNodeFRight.getState());
+ assertEquals(UNRESOLVED, diffNodeCLeft.getState());
+ assertEquals(MERGED, diffNodeCRight.getState());
+ assertEquals(MERGED, diffNodeDLeft.getState());
+ assertEquals(MERGED, diffNodeDRight.getState());
+ assertEquals(UNRESOLVED, diffNodeELeft.getState());
+ assertEquals(MERGED, diffNodeFRight.getState());
}
@SuppressWarnings("unchecked")
@@ -245,12 +248,12 @@ public class ConflictMergeTest {
final EList<Node> bContainmentRef1s = ((Node)leftNodeB).getContainmentRef1();
assertFalse(bContainmentRef1s.contains(leftNodeC));
- assertEquals(DifferenceState.MERGED, diffNodeCLeft.getState());
- assertEquals(DifferenceState.UNRESOLVED, diffNodeCRight.getState());
- assertEquals(DifferenceState.MERGED, diffNodeDLeft.getState());
- assertEquals(DifferenceState.MERGED, diffNodeDRight.getState());
- assertEquals(DifferenceState.MERGED, diffNodeELeft.getState());
- assertEquals(DifferenceState.UNRESOLVED, diffNodeFRight.getState());
+ assertEquals(MERGED, diffNodeCLeft.getState());
+ assertEquals(UNRESOLVED, diffNodeCRight.getState());
+ assertEquals(MERGED, diffNodeDLeft.getState());
+ assertEquals(MERGED, diffNodeDRight.getState());
+ assertEquals(MERGED, diffNodeELeft.getState());
+ assertEquals(UNRESOLVED, diffNodeFRight.getState());
}
@SuppressWarnings("unchecked")
@@ -307,12 +310,12 @@ public class ConflictMergeTest {
final EList<Node> bContainmentRef1s = ((Node)leftNodeB).getContainmentRef1();
assertTrue(bContainmentRef1s.contains(leftNodeC));
- assertEquals(DifferenceState.MERGED, diffNodeCLeft.getState());
- assertEquals(DifferenceState.MERGED, diffNodeCRight.getState());
- assertEquals(DifferenceState.MERGED, diffNodeDLeft.getState());
- assertEquals(DifferenceState.MERGED, diffNodeDRight.getState());
- assertEquals(DifferenceState.MERGED, diffNodeELeft.getState());
- assertEquals(DifferenceState.UNRESOLVED, diffNodeFRight.getState());
+ assertEquals(DISCARDED, diffNodeCLeft.getState());
+ assertEquals(MERGED, diffNodeCRight.getState());
+ assertEquals(MERGED, diffNodeDLeft.getState());
+ assertEquals(MERGED, diffNodeDRight.getState());
+ assertEquals(DISCARDED, diffNodeELeft.getState());
+ assertEquals(UNRESOLVED, diffNodeFRight.getState());
}
@Test
@@ -345,7 +348,7 @@ public class ConflictMergeTest {
final EList<EClass> eSuperTypes = ((EClass)rightEClassA).getESuperTypes();
assertTrue(eSuperTypes.contains(rightEClassB));
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -379,9 +382,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.RIGHT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -420,7 +423,7 @@ public class ConflictMergeTest {
assertTrue(featureValue instanceof Collection<?>);
assertTrue(((Collection<?>)featureValue).containsAll(Lists.newArrayList(NodeEnum.A, NodeEnum.B)));
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -442,7 +445,7 @@ public class ConflictMergeTest {
final EObject rightElement = getNodeNamed(left, "origin");
assertNull(rightElement);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -476,9 +479,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.LEFT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -513,7 +516,7 @@ public class ConflictMergeTest {
final EList<EClass> eSuperTypes = ((EClass)leftEClassA).getESuperTypes();
assertTrue(eSuperTypes.isEmpty());
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -546,7 +549,7 @@ public class ConflictMergeTest {
final EList<EClass> eSuperTypes = ((EClass)rightEClassA).getESuperTypes();
assertTrue(eSuperTypes.isEmpty());
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -580,9 +583,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.RIGHT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -618,9 +621,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.LEFT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -655,7 +658,7 @@ public class ConflictMergeTest {
final EList<EClass> eSuperTypes = ((EClass)leftEClassA).getESuperTypes();
assertTrue(eSuperTypes.contains(leftEClassB));
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -682,7 +685,7 @@ public class ConflictMergeTest {
final EObject rightEClassA = getNodeNamed(right, "A");
assertNull(rightEClassA);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -722,9 +725,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.RIGHT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -757,9 +760,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.LEFT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -799,7 +802,7 @@ public class ConflictMergeTest {
assertTrue(((EClass)leftEClassA).isAbstract());
assertTrue(((EClass)leftEClassA).isInterface());
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -837,7 +840,7 @@ public class ConflictMergeTest {
assertTrue(((EClass)rightEClassA).isAbstract());
assertTrue(((EClass)rightEClassA).isInterface());
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -868,9 +871,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.RIGHT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -912,9 +915,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.LEFT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -943,7 +946,7 @@ public class ConflictMergeTest {
final EObject leftEClassA = getNodeNamed(left, "A");
assertNull(leftEClassA);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -976,7 +979,7 @@ public class ConflictMergeTest {
assertNotNull(eType);
assertEquals(eType.getName(), "EBoolean");
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -1011,9 +1014,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.RIGHT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -1050,9 +1053,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.LEFT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -1086,7 +1089,7 @@ public class ConflictMergeTest {
final EClassifier eType = ((EAttribute)leftEAttributeName).getEType();
assertNull(eType);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -1118,7 +1121,7 @@ public class ConflictMergeTest {
final EClassifier eType = ((EAttribute)rightEAttributeName).getEType();
assertNull(eType);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -1153,9 +1156,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.RIGHT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -1192,9 +1195,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.LEFT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -1229,7 +1232,7 @@ public class ConflictMergeTest {
assertNotNull(eType);
assertEquals(eType.getName(), "EBoolean");
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -1256,7 +1259,7 @@ public class ConflictMergeTest {
final EObject rightEClassB = getNodeNamed(right, "B");
assertNull(rightEClassB);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -1299,9 +1302,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.RIGHT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -1346,9 +1349,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.LEFT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -1390,7 +1393,7 @@ public class ConflictMergeTest {
.getEStructuralFeature("name");
assertNull(eStructuralFeatureNameA);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -1436,7 +1439,7 @@ public class ConflictMergeTest {
.getEStructuralFeature("name");
assertNotNull(eStructuralFeatureNameB);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -1484,9 +1487,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.RIGHT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -1536,9 +1539,9 @@ public class ConflictMergeTest {
for (Diff currentDiff : differences) {
if (currentDiff.getSource() == DifferenceSource.LEFT) {
- assertTrue(currentDiff.getState() == DifferenceState.MERGED);
+ assertTrue(isInTerminalState(currentDiff));
} else {
- assertTrue(currentDiff.getState() == DifferenceState.UNRESOLVED);
+ assertTrue(currentDiff.getState() == UNRESOLVED);
}
}
}
@@ -1581,7 +1584,7 @@ public class ConflictMergeTest {
.getEStructuralFeature("name");
assertNull(eStructuralFeatureNameA);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -1615,7 +1618,7 @@ public class ConflictMergeTest {
final Object leftValue = leftNode.eGet(feature);
assertEquals(NodeEnum.B, leftValue);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
@Test
@@ -1649,7 +1652,7 @@ public class ConflictMergeTest {
final Object leftValue = leftNode.eGet(feature);
assertEquals(NodeEnum.C, leftValue);
- assertFalse(Iterators.any(differences.iterator(), not(hasState(DifferenceState.MERGED))));
+ assertFalse(Iterators.any(differences.iterator(), not(hasState(MERGED, DISCARDED))));
}
private EObject getNodeNamed(Resource res, String name) {
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/MultipleMergeTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/MultipleMergeTest.java
index fe9e57c90..5fd092574 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/MultipleMergeTest.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/merge/MultipleMergeTest.java
@@ -441,17 +441,17 @@ public class MultipleMergeTest {
batchMerger.copyAllRightToLeft(Arrays.asList(diff1), new BasicMonitor());
// Check that diff1 got properly merged (we're unsetting values)
- assertMerged(comparison, diff1, true, true);
+ assertDiscarded(comparison, diff1, true, true);
// And validate that diff2 got merged as an equivalent diff
- assertMerged(comparison, diff2, true, true);
+ assertDiscarded(comparison, diff2, true, true);
batchMerger.copyAllRightToLeft(Arrays.asList(diff3), new BasicMonitor());
- assertMerged(comparison, diff3, true, true);
- assertMerged(comparison, diff4, true, true);
+ assertDiscarded(comparison, diff3, true, true);
+ assertDiscarded(comparison, diff4, true, true);
batchMerger.copyAllRightToLeft(Arrays.asList(diff5), new BasicMonitor());
- assertMerged(comparison, diff5, true, true);
- assertMerged(comparison, diff6, true, true);
+ assertDiscarded(comparison, diff5, true, true);
+ assertDiscarded(comparison, diff6, true, true);
comparison = EMFCompare.builder().build().compare(scope);
assertEquals(0, comparison.getDifferences().size());
@@ -520,12 +520,12 @@ public class MultipleMergeTest {
addedToReference("Requirements.A", "source", "Requirements.B"));
batchMerger.copyAllRightToLeft(Arrays.asList(diff1), new BasicMonitor());
- assertMerged(comparison, diff1, true, true);
- assertMerged(comparison, diff2, true, true);
+ assertDiscarded(comparison, diff1, true, true);
+ assertDiscarded(comparison, diff2, true, true);
batchMerger.copyAllRightToLeft(Arrays.asList(diff3), new BasicMonitor());
- assertMerged(comparison, diff3, true, true);
- assertMerged(comparison, diff4, true, true);
+ assertDiscarded(comparison, diff3, true, true);
+ assertDiscarded(comparison, diff4, true, true);
comparison = EMFCompare.builder().build().compare(scope);
assertEquals(0, comparison.getDifferences().size());
@@ -650,20 +650,20 @@ public class MultipleMergeTest {
// Removing the link between A and B does not necessarily means removing A and B
// The "required" diffs will ne be merged
batchMerger.copyAllRightToLeft(Arrays.asList(diff1), new BasicMonitor());
- assertMerged(comparison, diff1, true, true);
- assertMerged(comparison, diff2, true, true);
+ assertDiscarded(comparison, diff1, true, true);
+ assertDiscarded(comparison, diff2, true, true);
assertSame(DifferenceState.UNRESOLVED, diff7.getState());
assertSame(DifferenceState.UNRESOLVED, diff8.getState());
batchMerger.copyAllRightToLeft(Arrays.asList(diff3), new BasicMonitor());
- assertMerged(comparison, diff3, true, true);
- assertMerged(comparison, diff4, true, true);
+ assertDiscarded(comparison, diff3, true, true);
+ assertDiscarded(comparison, diff4, true, true);
assertSame(DifferenceState.UNRESOLVED, diff9.getState());
assertSame(DifferenceState.UNRESOLVED, diff10.getState());
batchMerger.copyAllRightToLeft(Arrays.asList(diff5), new BasicMonitor());
- assertMerged(comparison, diff5, true, true);
- assertMerged(comparison, diff6, true, true);
+ assertDiscarded(comparison, diff5, true, true);
+ assertDiscarded(comparison, diff6, true, true);
assertSame(DifferenceState.UNRESOLVED, diff11.getState());
assertSame(DifferenceState.UNRESOLVED, diff12.getState());
@@ -790,8 +790,8 @@ public class MultipleMergeTest {
batchMerger.copyAllRightToLeft(Arrays.asList(diff2), new BasicMonitor());
assertSame(DifferenceState.UNRESOLVED, diff1.getState());
- assertMerged(comparison, diff3, false, true);
- assertMerged(comparison, diff4, true, true);
+ assertDiscarded(comparison, diff3, false, true);
+ assertDiscarded(comparison, diff4, true, true);
/*
* Diff 2 is a little more complicated than the usual. We are on a mono-valued refrence, and the merge
* operation is actually resetting the value to its original state. We will need to check that.
@@ -898,18 +898,18 @@ public class MultipleMergeTest {
// 1 is required by 3, which is required by 2 and equivalent to 4 and 5.
// Resetting 1 should thus reset all other diffs.
batchMerger.copyAllRightToLeft(Arrays.asList(diff1), new BasicMonitor());
- assertMerged(comparison, diff1, true, true);
- assertMerged(comparison, diff2, false, true);
+ assertDiscarded(comparison, diff1, true, true);
+ assertDiscarded(comparison, diff2, false, true);
// C has been removed, thus the value match of diff3 has neither left nor right.
- assertSame(DifferenceState.MERGED, diff3.getState());
+ assertSame(DifferenceState.DISCARDED, diff3.getState());
final EObject nodeA = diff3.getMatch().getLeft();
final EObject nodeB = diff4.getMatch().getLeft();
assertSame(nodeB, nodeA.eGet(diff3.getReference()));
- assertMerged(comparison, diff4, false, true);
+ assertDiscarded(comparison, diff4, false, true);
- assertSame(DifferenceState.MERGED, diff5.getState());
+ assertSame(DifferenceState.DISCARDED, diff5.getState());
assertNull(diff5.getMatch().getLeft());
assertNull(diff5.getMatch().getRight());
@@ -1139,7 +1139,7 @@ public class MultipleMergeTest {
batchMerger.copyAllRightToLeft(Arrays.asList(setCSourceDiff), new BasicMonitor());
// Check if the non-equivalent diff is marked as merged
- assertEquals(DifferenceState.MERGED, setDSourceDiff.getState());
+ assertEquals(DifferenceState.DISCARDED, setDSourceDiff.getState());
// Check if no differences between models are left
comparison = EMFCompare.builder().build().compare(scope);
@@ -1345,7 +1345,18 @@ public class MultipleMergeTest {
private static void assertMerged(Comparison comparison, ReferenceChange referenceChange, boolean unset,
boolean rightToLeft) {
assertSame(referenceChange.getState(), DifferenceState.MERGED);
+ checkFinalState(comparison, referenceChange, unset, rightToLeft);
+ }
+ /* NOTE : not meant for containment changes */
+ private static void assertDiscarded(Comparison comparison, ReferenceChange referenceChange, boolean unset,
+ boolean rightToLeft) {
+ assertSame(referenceChange.getState(), DifferenceState.DISCARDED);
+ checkFinalState(comparison, referenceChange, unset, rightToLeft);
+ }
+
+ private static void checkFinalState(Comparison comparison, ReferenceChange referenceChange, boolean unset,
+ boolean rightToLeft) {
final EObject container;
if (rightToLeft) {
container = referenceChange.getMatch().getLeft();
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/stereotypes/AbstractStereotypedElementChangeTests.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/stereotypes/AbstractStereotypedElementChangeTests.java
index f0647fb82..71dbd0d12 100644
--- a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/stereotypes/AbstractStereotypedElementChangeTests.java
+++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/stereotypes/AbstractStereotypedElementChangeTests.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.compare.uml2.tests.stereotypes;
import static com.google.common.base.Predicates.and;
import static com.google.common.base.Predicates.instanceOf;
+import static org.eclipse.emf.compare.merge.AbstractMerger.isInTerminalState;
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.removed;
@@ -339,7 +340,7 @@ public abstract class AbstractStereotypedElementChangeTests extends AbstractUMLP
// Checks comparison model after merging
for (Diff diff : differences) {
- assertSame(DifferenceState.MERGED, diff.getState());
+ assertTrue(isInTerminalState(diff));
}
// Checks right model content after merging
@@ -402,7 +403,7 @@ public abstract class AbstractStereotypedElementChangeTests extends AbstractUMLP
// Merges
mergeRightToLeft(stereotypedElementChange);
for (Diff diff : differences) {
- assertSame(DifferenceState.MERGED, diff.getState());
+ assertTrue(isInTerminalState(diff));
}
// Checks right model content after merging
@@ -616,7 +617,7 @@ public abstract class AbstractStereotypedElementChangeTests extends AbstractUMLP
for (Diff diff : differences) {
final DifferenceState expectedDiffState;
if (expectedMergeDifferences.contains(diff) || stereotypedElementChange.equals(diff)) {
- expectedDiffState = DifferenceState.MERGED;
+ expectedDiffState = DifferenceState.DISCARDED;
} else {
expectedDiffState = DifferenceState.UNRESOLVED;
}
@@ -694,7 +695,7 @@ public abstract class AbstractStereotypedElementChangeTests extends AbstractUMLP
// Check comparison model
// Everything should be merged
for (Diff diff : differences) {
- assertSame(DifferenceState.MERGED, diff.getState());
+ assertTrue(isInTerminalState(diff));
}
// Checks left model content after merging
@@ -820,7 +821,7 @@ public abstract class AbstractStereotypedElementChangeTests extends AbstractUMLP
// Check comparison model
for (Diff diff : differences) {
- assertSame(DifferenceState.MERGED, diff.getState());
+ assertTrue(isInTerminalState(diff));
}
// Checks left model content after merging
@@ -912,7 +913,7 @@ public abstract class AbstractStereotypedElementChangeTests extends AbstractUMLP
mergeRightToLeft(stereotypedElementChange);
for (Diff diff : differences) {
- assertSame(DifferenceState.MERGED, diff.getState());
+ assertTrue(isInTerminalState(diff));
}
// Checks left model content after merging
assertEqualsM2(left);
@@ -1007,7 +1008,7 @@ public abstract class AbstractStereotypedElementChangeTests extends AbstractUMLP
if (leftConflictDiff.equals(diff)) {
assertSame(DifferenceState.UNRESOLVED, diff.getState());
} else {
- assertSame(DifferenceState.MERGED, diff.getState());
+ assertSame(DifferenceState.DISCARDED, diff.getState());
}
}
diff --git a/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/merge/OpaqueElementBodyChangeMerger.java b/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/merge/OpaqueElementBodyChangeMerger.java
index a74fc0f96..d042d1340 100644
--- a/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/merge/OpaqueElementBodyChangeMerger.java
+++ b/plugins/org.eclipse.emf.compare.uml2/src/org/eclipse/emf/compare/uml2/internal/merge/OpaqueElementBodyChangeMerger.java
@@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.emf.compare.uml2.internal.merge;
-import static org.eclipse.emf.compare.DifferenceState.MERGED;
import static org.eclipse.emf.compare.uml2.internal.postprocessor.util.UMLCompareUtil.getOpaqueElementLanguages;
import static org.eclipse.emf.compare.uml2.internal.postprocessor.util.UMLCompareUtil.isChangeOfOpaqueElementBodyAttribute;
import static org.eclipse.emf.compare.uml2.internal.postprocessor.util.UMLCompareUtil.isChangeOfOpaqueElementLanguageAttribute;
@@ -123,11 +122,11 @@ public class OpaqueElementBodyChangeMerger extends AttributeChangeMerger {
* @return true if the complete body change is merged, false otherwise.
*/
private boolean isFullyMerged(OpaqueElementBodyChange bodyChange) {
- if (bodyChange.getState() != MERGED) {
+ if (!isInTerminalState(bodyChange)) {
return false;
}
for (Diff refiningDiff : bodyChange.getRefinedBy()) {
- if (refiningDiff.getState() != MERGED) {
+ if (!isInTerminalState(refiningDiff)) {
return false;
}
}
@@ -171,7 +170,7 @@ public class OpaqueElementBodyChangeMerger extends AttributeChangeMerger {
}
// we set the whole refinement diff to merged
- setFullyMerged(bodyChange);
+ setFullyMerged(bodyChange, rightToLeft);
}
}
@@ -211,7 +210,7 @@ public class OpaqueElementBodyChangeMerger extends AttributeChangeMerger {
}
// we set the whole refinement diff to merged
- setFullyMerged(bodyChange);
+ setFullyMerged(bodyChange, rightToLeft);
}
}
@@ -589,11 +588,20 @@ public class OpaqueElementBodyChangeMerger extends AttributeChangeMerger {
*
* @param bodyChange
* The {@link OpaqueElementBodyChange} to set to merged.
+ * @param rightToLeft
+ * The direction of the merge
*/
- private void setFullyMerged(OpaqueElementBodyChange bodyChange) {
- bodyChange.setState(DifferenceState.MERGED);
- for (Diff refiningDiff : bodyChange.getRefinedBy()) {
- refiningDiff.setState(DifferenceState.MERGED);
+ private void setFullyMerged(OpaqueElementBodyChange bodyChange, boolean rightToLeft) {
+ if (isAccepting(bodyChange, rightToLeft)) {
+ bodyChange.setState(DifferenceState.MERGED);
+ for (Diff refiningDiff : bodyChange.getRefinedBy()) {
+ refiningDiff.setState(DifferenceState.MERGED);
+ }
+ } else {
+ bodyChange.setState(DifferenceState.DISCARDED);
+ for (Diff refiningDiff : bodyChange.getRefinedBy()) {
+ refiningDiff.setState(DifferenceState.DISCARDED);
+ }
}
}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IMergeData.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IMergeData.java
index eae86500e..69722ed46 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IMergeData.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/IMergeData.java
@@ -11,7 +11,6 @@
package org.eclipse.emf.compare.internal.merge;
import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.compare.DifferenceSource;
/**
* Interface implemented by {@link org.eclipse.emf.compare.internal.merge.MergeDataImpl}. It helps to know the
@@ -22,28 +21,6 @@ import org.eclipse.emf.compare.DifferenceSource;
public interface IMergeData extends Adapter {
/**
- * Returns the merge mode the {@link #getTarget() associated} diff has been merged with.
- *
- * @return the merge mode the {@link #getTarget() associated} diff has been merged with.
- */
- MergeMode getMergeMode();
-
- /**
- * Set the merge mode the {@link #getTarget() associated} diff has been merged with.
- *
- * @param mergeMode
- * the merge mode the {@link #getTarget() associated} diff has been merged with.
- */
- void setMergeMode(MergeMode mergeMode);
-
- /**
- * Returns the target side of the merge.
- *
- * @return the target side of the merge.
- */
- DifferenceSource getMergeTarget();
-
- /**
* Returns whether the left side of the comparison is editable.
*
* @return true if the left side of the comparison is editable, false otherwise.
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDataImpl.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDataImpl.java
index 305280bbb..2a9c666b0 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDataImpl.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeDataImpl.java
@@ -11,7 +11,6 @@
package org.eclipse.emf.compare.internal.merge;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.compare.DifferenceSource;
/**
* Adapter that help to know the way of merge and the editable sides of a difference.
@@ -27,21 +26,15 @@ public class MergeDataImpl extends AdapterImpl implements IMergeData {
/** Right side is editable. */
private boolean rightEditable;
- /** The merge mode used to merge the associated diff. */
- private MergeMode mergeMode;
-
/**
* Constructor.
*
- * @param mergeMode
- * The merge mode.
* @param leftEditable
* Left side editable.
* @param rightEditable
* Right side editable.
*/
- public MergeDataImpl(MergeMode mergeMode, boolean leftEditable, boolean rightEditable) {
- this.mergeMode = mergeMode;
+ public MergeDataImpl(boolean leftEditable, boolean rightEditable) {
this.leftEditable = leftEditable;
this.rightEditable = rightEditable;
}
@@ -49,24 +42,6 @@ public class MergeDataImpl extends AdapterImpl implements IMergeData {
/**
* {@inheritDoc}
*
- * @see org.eclipse.emf.compare.internal.merge.IMergeData#getMergeMode()
- */
- public MergeMode getMergeMode() {
- return mergeMode;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.internal.merge.IMergeData#getMergeTarget()
- */
- public DifferenceSource getMergeTarget() {
- return mergeMode.getMergeTarget(leftEditable, rightEditable);
- }
-
- /**
- * {@inheritDoc}
- *
* @see org.eclipse.emf.compare.internal.merge.IMergeData#isLeftEditable()
*/
public boolean isLeftEditable() {
@@ -105,12 +80,4 @@ public class MergeDataImpl extends AdapterImpl implements IMergeData {
this.rightEditable = rightEditable;
}
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.internal.merge.IMergeData#setMergeMode(org.eclipse.emf.compare.internal.merge.MergeMode)
- */
- public void setMergeMode(MergeMode mergeMode) {
- this.mergeMode = mergeMode;
- }
}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeMode.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeMode.java
index 6df16c72a..6154f092e 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeMode.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/merge/MergeMode.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.emf.compare.internal.merge;
+import static org.eclipse.emf.compare.internal.merge.MergeOperation.MARK_AS_MERGE;
+import static org.eclipse.emf.compare.internal.merge.MergeOperation.MERGE;
+
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceSource;
@@ -150,40 +153,40 @@ public enum MergeMode {
switch (this) {
case LEFT_TO_RIGHT:
case RIGHT_TO_LEFT:
- ret = MergeOperation.MERGE;
+ ret = MERGE;
break;
case ACCEPT:
if (isLeftEditable) {
if (difference.getSource() == DifferenceSource.LEFT) {
- ret = MergeOperation.MARK_AS_MERGE;
+ ret = MARK_AS_MERGE;
} else {
- ret = MergeOperation.MERGE;
+ ret = MERGE;
}
} else if (isRightEditable) {
if (difference.getSource() == DifferenceSource.LEFT) {
- ret = MergeOperation.MERGE;
+ ret = MERGE;
} else {
- ret = MergeOperation.MARK_AS_MERGE;
+ ret = MARK_AS_MERGE;
}
} else {
- throw new IllegalStateException();
+ throw new IllegalArgumentException();
}
break;
case REJECT:
if (isLeftEditable) {
if (difference.getSource() == DifferenceSource.LEFT) {
- ret = MergeOperation.MERGE;
+ ret = MERGE;
} else {
- ret = MergeOperation.MARK_AS_MERGE;
+ ret = MARK_AS_MERGE;
}
} else if (isRightEditable) {
if (difference.getSource() == DifferenceSource.LEFT) {
- ret = MergeOperation.MARK_AS_MERGE;
+ ret = MARK_AS_MERGE;
} else {
- ret = MergeOperation.MERGE;
+ ret = MERGE;
}
} else {
- throw new IllegalStateException();
+ throw new IllegalArgumentException();
}
break;
default:
@@ -191,4 +194,44 @@ public enum MergeMode {
}
return ret;
}
+
+ // CHECKSTYLE:OFF
+ public static MergeMode getMergeMode(Diff diff, boolean leftEditable, boolean rightEditable) {
+ if (leftEditable && rightEditable) {
+ switch (diff.getState()) {
+ case MERGED:
+ switch (diff.getSource()) {
+ case LEFT:
+ return RIGHT_TO_LEFT;
+ case RIGHT:
+ return LEFT_TO_RIGHT;
+ default:
+ throw new IllegalArgumentException();
+ }
+ case DISCARDED:
+ switch (diff.getSource()) {
+ case LEFT:
+ return LEFT_TO_RIGHT;
+ case RIGHT:
+ return RIGHT_TO_LEFT;
+ default:
+ throw new IllegalArgumentException();
+ }
+ default:
+ return null;
+ }
+ } else if (leftEditable || rightEditable) {
+ switch (diff.getState()) {
+ case MERGED:
+ return ACCEPT;
+ case DISCARDED:
+ return REJECT;
+ default:
+ return null;
+ }
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+ // CHECKSTYLE:ON
}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/AbstractMerger.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/AbstractMerger.java
index 80087d96e..2f3842c26 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/AbstractMerger.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/AbstractMerger.java
@@ -17,6 +17,7 @@ import static com.google.common.base.Predicates.not;
import static com.google.common.base.Predicates.or;
import static org.eclipse.emf.compare.ConflictKind.PSEUDO;
import static org.eclipse.emf.compare.DifferenceSource.RIGHT;
+import static org.eclipse.emf.compare.DifferenceState.DISCARDED;
import static org.eclipse.emf.compare.DifferenceState.MERGED;
import static org.eclipse.emf.compare.DifferenceState.MERGING;
import static org.eclipse.emf.compare.DifferenceState.UNRESOLVED;
@@ -758,7 +759,11 @@ public abstract class AbstractMerger implements IMerger2, IMergeOptionAware, IMe
Diff impliedMerge = impliedMerges.iterator().next();
// avoid implication circles
if (impliedMerge != target && !isInTerminalState(impliedMerge)) {
- impliedMerge.setState(MERGED);
+ if (isAccepting(impliedMerge, rightToLeft)) {
+ impliedMerge.setState(MERGED);
+ } else {
+ impliedMerge.setState(DISCARDED);
+ }
impliedMerges.addAll(getImpliedMerges(impliedMerge, rightToLeft));
}
impliedMerges.remove(impliedMerge);
@@ -766,10 +771,11 @@ public abstract class AbstractMerger implements IMerger2, IMergeOptionAware, IMe
}
if (isAccepting(target, rightToLeft)) {
accept(target, rightToLeft);
+ target.setState(MERGED);
} else {
reject(target, rightToLeft);
+ target.setState(DISCARDED);
}
- target.setState(MERGED);
if (LOGGER.isDebugEnabled()) {
long duration = System.currentTimeMillis() - start;
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ConflictMerger.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ConflictMerger.java
index c2038e3de..259086fdf 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ConflictMerger.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ConflictMerger.java
@@ -15,7 +15,7 @@ import static org.eclipse.emf.compare.DifferenceKind.DELETE;
import static org.eclipse.emf.compare.DifferenceKind.MOVE;
import static org.eclipse.emf.compare.DifferenceSource.LEFT;
import static org.eclipse.emf.compare.DifferenceSource.RIGHT;
-import static org.eclipse.emf.compare.DifferenceState.MERGED;
+import static org.eclipse.emf.compare.DifferenceState.DISCARDED;
import static org.eclipse.emf.compare.merge.IMergeCriterion.NONE;
import java.util.Iterator;
@@ -67,7 +67,7 @@ public class ConflictMerger extends AbstractMerger {
for (Diff conflictedDiff : conflict.getDifferences()) {
if (conflictedDiff.getSource() == RIGHT) {
if (isConflictVsMoveAndDelete(target, conflictedDiff, true)) {
- conflictedDiff.setState(MERGED);
+ conflictedDiff.setState(DISCARDED);
} else {
mergeConflictedDiff(conflictedDiff, true, monitor);
}
@@ -98,7 +98,7 @@ public class ConflictMerger extends AbstractMerger {
for (Diff conflictedDiff : conflict.getDifferences()) {
if (conflictedDiff.getSource() == LEFT) {
if (isConflictVsMoveAndDelete(target, conflictedDiff, false)) {
- conflictedDiff.setState(MERGED);
+ conflictedDiff.setState(DISCARDED);
} else {
mergeConflictedDiff(conflictedDiff, false, monitor);
}
@@ -193,7 +193,7 @@ public class ConflictMerger extends AbstractMerger {
delegate.copyRightToLeft(conflictedDiff, monitor);
}
} else {
- conflictedDiff.setState(MERGED);
+ conflictedDiff.setState(DISCARDED);
}
}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ReferenceChangeMerger.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ReferenceChangeMerger.java
index 8e4ad0801..0d890fe6e 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ReferenceChangeMerger.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ReferenceChangeMerger.java
@@ -26,7 +26,6 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.DifferenceState;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.ReferenceChange;
import org.eclipse.emf.compare.internal.utils.DiffUtil;
@@ -616,7 +615,7 @@ public class ReferenceChangeMerger extends AbstractMerger {
while (impliedReferenceChanges.hasNext()) {
final ReferenceChange implied = impliedReferenceChanges.next();
- if (implied != diff && implied.getState() == DifferenceState.MERGED) {
+ if (implied != diff && isInTerminalState(implied)) {
if (implied.getReference().isMany() && isAdd(implied, rightToLeft)) {
internalCheckOrdering(implied, rightToLeft);
checkImpliedDiffsOrdering(implied, rightToLeft);

Back to the top