diff options
Diffstat (limited to 'plugins/org.eclipse.emf.compare/src')
13 files changed, 282 insertions, 317 deletions
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/emfcomparemessages.properties b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/emfcomparemessages.properties index 21ed24891..d12ec275a 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/emfcomparemessages.properties +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/emfcomparemessages.properties @@ -24,3 +24,6 @@ ResourceAttachmentChangeSpec.MissingMatch = Could not locate resource match for ResourceAttachmentChangeSpec.MissingRS = Could not locate resource set to create {0} IMerger.MissingMerger = No merger found for diff {0} + +ProximityEObjectMatcher.monitor.indexing = indexing objects +ProximityEObjectMatcher.monitor.matching = matching objects
\ No newline at end of file diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/postprocessor/factories/AbstractChangeFactory.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/postprocessor/factories/AbstractChangeFactory.java index 07573df9f..fae53a253 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/postprocessor/factories/AbstractChangeFactory.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/postprocessor/factories/AbstractChangeFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Obeo. + * Copyright (c) 2013, 2014 Obeo. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -32,7 +32,7 @@ import org.eclipse.emf.compare.utils.MatchUtil; import org.eclipse.emf.ecore.EObject; /** - * Factory of diagram difference extensions. + * Factory of difference extensions. * * @author <a href="mailto:cedric.notot@obeo.fr">Cedric Notot</a> */ diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/utils/DiffUtil.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/utils/DiffUtil.java index 718906a7a..5423d5e42 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/utils/DiffUtil.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/utils/DiffUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 Obeo. + * Copyright (c) 2012, 2014 Obeo. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -1060,25 +1060,6 @@ public final class DiffUtil { } /** - * Check if the given object is a Diff that is a prime refining of one of its refine diffs. - * - * @param data - * the given object. - * @return true if the given object is a Diff that is a prime refining of one of its refine diffs, false - * otherwise. - */ - public static boolean isPrimeRefining(EObject data) { - if (data instanceof Diff) { - for (Diff refine : ((Diff)data).getRefines()) { - if (refine.getPrimeRefining() == data) { - return true; - } - } - } - return false; - } - - /** * This can be used to check whether a given Diff affects a value for which we can find another, * unresolved Diff on a given Feature. * diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/CachingDistance.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/CachingDistance.java index b663540ec..c6d526977 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/CachingDistance.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/CachingDistance.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 Obeo and others. + * Copyright (c) 2012, 2014 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 @@ -22,6 +22,7 @@ import org.eclipse.emf.ecore.EObject; * same value will be returned to distance(b,a). * * @author <a href="mailto:cedric.brun@obeo.fr">Cedric Brun</a> + * @since 4.0 */ public class CachingDistance implements DistanceFunction { @@ -54,7 +55,7 @@ public class CachingDistance implements DistanceFunction { Double previousResult = distanceCache.get(key); if (previousResult == null) { double dist = wrapped.distance(inProgress, a, b); - distanceCache.put(key, dist); + distanceCache.put(key, Double.valueOf(dist)); // cache it return dist; } diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EUriFragmentFunction.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EUriFragmentFunction.java index b3bbcac17..04408babd 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EUriFragmentFunction.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EUriFragmentFunction.java @@ -1,5 +1,5 @@ /*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * Copyright (c) 2012, 2014 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -56,23 +56,26 @@ public class EUriFragmentFunction implements Function<EObject, String> { // TODO Comment the checkstyle suppression. Was that copy/pasted from somewhere?
public String eURIFragmentSegment(EObject container, EStructuralFeature eStructuralFeature,
EObject eObject) {
- if (eStructuralFeature == null) {
+ EStructuralFeature actualFeature = eStructuralFeature;
+ if (actualFeature == null) {
for (@SuppressWarnings("unchecked")
EContentsEList.FeatureIterator<EObject> crossReferences = (EContentsEList.FeatureIterator<EObject>)((InternalEList<?>)container
.eCrossReferences()).basicIterator(); crossReferences.hasNext();) {
EObject crossReference = crossReferences.next();
if (crossReference == eObject) {
- eStructuralFeature = crossReferences.feature();
+ actualFeature = crossReferences.feature();
}
}
}
+ assert actualFeature != null;
+
StringBuilder result = new StringBuilder();
result.append('@');
- result.append(eStructuralFeature.getName());
+ result.append(actualFeature.getName());
- if (eStructuralFeature instanceof EAttribute) {
- FeatureMap featureMap = (FeatureMap)container.eGet(eStructuralFeature, false);
+ if (actualFeature instanceof EAttribute) {
+ FeatureMap featureMap = (FeatureMap)container.eGet(actualFeature, false);
for (int i = 0, size = featureMap.size(); i < size; ++i) {
if (featureMap.getValue(i) == eObject) {
EStructuralFeature entryFeature = featureMap.getEStructuralFeature(i);
@@ -83,11 +86,11 @@ public class EUriFragmentFunction implements Function<EObject, String> { }
}
}
- result.append(".-1");
- } else if (eStructuralFeature.isMany()) {
- EList<EAttribute> eKeys = ((EReference)eStructuralFeature).getEKeys();
+ result.append(".-1"); //$NON-NLS-1$
+ } else if (actualFeature.isMany()) {
+ EList<EAttribute> eKeys = ((EReference)actualFeature).getEKeys();
if (eKeys.isEmpty()) {
- EList<?> eList = (EList<?>)container.eGet(eStructuralFeature, false);
+ EList<?> eList = (EList<?>)container.eGet(actualFeature, false);
int index = eList.indexOf(eObject);
result.append('.');
result.append(index);
@@ -133,7 +136,7 @@ public class EUriFragmentFunction implements Function<EObject, String> { private void eEncodeValue(StringBuilder result, EFactory eFactory, EDataType eDataType, Object value) {
String stringValue = eFactory.convertToString(eDataType, value);
if (stringValue == null) {
- result.append("null");
+ result.append("null"); //$NON-NLS-1$
} else {
int length = stringValue.length();
result.ensureCapacity(result.length() + length + 2);
@@ -153,36 +156,7 @@ public class EUriFragmentFunction implements Function<EObject, String> { }
}
- /**
- * Returns the encoded value or the original, if no encoding was needed.
- *
- * @param value
- * the value to be encoded.
- * @return the encoded value or the original, if no encoding was needed.
- */
- private String eEncodeValue(String value) {
- int length = value.length();
- StringBuilder result = null;
- for (int i = 0; i < length; ++i) {
- char character = value.charAt(i);
- if (character < ESCAPE.length) {
- String escape = ESCAPE[character];
- if (escape != null) {
- if (result == null) {
- result = new StringBuilder(length + 2);
- result.append(value, 0, i);
- }
- result.append(escape);
- continue;
- }
- }
- if (result != null) {
- result.append(character);
- }
- }
- return result == null ? value : result.toString();
- }
-
+ @SuppressWarnings("nls")
private final String[] ESCAPE = {"%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09",
"%0A", "%0B", "%0C", "%0D", "%0E", "%0F", "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",
"%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F", "%20", null, "%22", "%23", null, "%25",
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/ProximityEObjectMatcher.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/ProximityEObjectMatcher.java index 1eb2268e3..feda800a0 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/ProximityEObjectMatcher.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/ProximityEObjectMatcher.java @@ -1,5 +1,5 @@ /*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * Copyright (c) 2012, 2014 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -26,6 +26,7 @@ import org.eclipse.emf.common.util.BasicMonitor; import org.eclipse.emf.common.util.Monitor;
import org.eclipse.emf.compare.CompareFactory;
import org.eclipse.emf.compare.Comparison;
+import org.eclipse.emf.compare.EMFCompareMessages;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.match.eobject.EObjectIndex.Side;
import org.eclipse.emf.compare.match.eobject.internal.ByTypeIndex;
@@ -84,7 +85,7 @@ public class ProximityEObjectMatcher implements IEObjectMatcher, ScopeQuery { // FIXME: how to create an EMF submonitor
Monitor subMonitor = new BasicMonitor();
- subMonitor.beginTask("indexing objects", 1);
+ subMonitor.beginTask(EMFCompareMessages.getString("ProximityEObjectMatcher.monitor.indexing"), 1); //$NON-NLS-1$
int nbElements = 0;
int lastSegment = 0;
/*
@@ -123,7 +124,8 @@ public class ProximityEObjectMatcher implements IEObjectMatcher, ScopeQuery { // FIXME: how to create an EMF submonitor
subMonitor = new BasicMonitor();
- subMonitor.beginTask("matching objects", nbElements);
+ subMonitor.beginTask(EMFCompareMessages.getString("ProximityEObjectMatcher.monitor.matching"), //$NON-NLS-1$
+ nbElements);
matchIndexedObjects(comparison, subMonitor);
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ProximityMatchStats.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ProximityMatchStats.java index 080e707e4..798b2d064 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ProximityMatchStats.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ProximityMatchStats.java @@ -1,5 +1,5 @@ /*******************************************************************************
- * Copyright (c) 2013 Obeo.
+ * Copyright (c) 2013, 2014 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -118,6 +118,7 @@ public class ProximityMatchStats { * {@inheritDoc}
*/
@Override
+ @SuppressWarnings("nls")
public String toString() {
return "ProximityMatchStats [nbIndenticComparison=" + nbIndenticComparison + ", nbMaxDistComparison="
+ nbMaxDistComparison + ", nbnoMatch=" + nbNoMatch + ", nbSuccessIdenticComparison="
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ReflectiveWeightProvider.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ReflectiveWeightProvider.java index c0834d8cc..d785248fb 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ReflectiveWeightProvider.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/internal/ReflectiveWeightProvider.java @@ -1,5 +1,5 @@ /*******************************************************************************
- * Copyright (c) 2012 Obeo.
+ * Copyright (c) 2012, 2014 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -108,7 +108,7 @@ public class ReflectiveWeightProvider implements WeightProvider { * that it's important for matching the element. At some point I'll have to come up with something
* which is more extensible..
*/
- if ("name".equals(feature.getName()) || "id".equals(feature.getName())) { //$NON-NLS-1$
+ if ("name".equals(feature.getName()) || "id".equals(feature.getName())) { //$NON-NLS-1$ //$NON-NLS-2$
found = Integer.valueOf(SIGNIFICANT);
}
if (feature instanceof EReference && ((EReference)feature).isContainment()) {
@@ -116,11 +116,11 @@ public class ReflectiveWeightProvider implements WeightProvider { }
}
if (feature instanceof EReference) {
- found = referenceChangeCoef * found.intValue();
+ found = Integer.valueOf(referenceChangeCoef * found.intValue());
} else {
- found = attributeChangeCoef * found.intValue();
+ found = Integer.valueOf(attributeChangeCoef * found.intValue());
}
- return found;
+ return found.intValue();
}
/**
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 3d6e4cd1c..9579a1669 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 Obeo. + * Copyright (c) 2012, 2014 Obeo. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,19 +10,19 @@ *******************************************************************************/ package org.eclipse.emf.compare.merge; -import static com.google.common.base.Predicates.in;
-import static com.google.common.collect.Iterables.any;
-
+import static com.google.common.base.Predicates.in; +import static com.google.common.collect.Iterables.any; + import java.util.List; import org.eclipse.emf.common.util.Monitor; import org.eclipse.emf.compare.Diff; -import org.eclipse.emf.compare.DifferenceSource;
-import org.eclipse.emf.compare.DifferenceState;
-import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.compare.DifferenceSource; +import org.eclipse.emf.compare.DifferenceState; +import org.eclipse.emf.compare.ReferenceChange; import org.eclipse.emf.compare.utils.EMFCompareCopier; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.util.InternalEList; @@ -80,116 +80,120 @@ public abstract class AbstractMerger implements IMerger { } /** - * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.merge.IMerger#copyLeftToRight(org.eclipse.emf.compare.Diff,
- * org.eclipse.emf.common.util.Monitor)
- */
- public void copyLeftToRight(Diff target, Monitor monitor) {
- // Don't merge an already merged (or discarded) diff
- if (target.getState() != DifferenceState.UNRESOLVED) {
- return;
- }
-
- // Change the diff's state before we actually merge it : this allows us to avoid requirement cycles.
- target.setState(DifferenceState.MERGED);
-
- if (target.getSource() == DifferenceSource.LEFT) {
- // merge all "requires" diffs
- mergeRequires(target, false, monitor);
- handleImplies(target, false, monitor);
- } else {
- // merge all "required by" diffs
- mergeRequiredBy(target, false, monitor);
- handleImpliedBy(target, false, monitor);
- }
-
- for (Diff refining : target.getRefinedBy()) {
- mergeDiff(refining, false, monitor);
- }
-
- boolean hasToBeMerged = true;
- if (target.getEquivalence() != null) {
- hasToBeMerged = handleEquivalences(target, false, monitor);
- }
-
- if (hasToBeMerged) {
- if (target.getSource() == DifferenceSource.LEFT) {
- accept(target, false);
- } else {
- reject(target, false);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.emf.compare.merge.IMerger#copyRightToLeft(org.eclipse.emf.compare.Diff,
- * org.eclipse.emf.common.util.Monitor)
- */
- public void copyRightToLeft(Diff target, Monitor monitor) {
- // Don't merge an already merged (or discarded) diff
- if (target.getState() != DifferenceState.UNRESOLVED) {
- return;
- }
-
- // Change the diff's state before we actually merge it : this allows us to avoid requirement cycles.
- target.setState(DifferenceState.MERGED);
-
- if (target.getSource() == DifferenceSource.LEFT) {
- // merge all "required by" diffs
- mergeRequiredBy(target, true, monitor);
- handleImpliedBy(target, true, monitor);
- } else {
- // merge all "requires" diffs
- mergeRequires(target, true, monitor);
- handleImplies(target, true, monitor);
- }
-
- for (Diff refining : target.getRefinedBy()) {
- mergeDiff(refining, true, monitor);
- }
-
- boolean hasToBeMerged = true;
- if (target.getEquivalence() != null) {
- hasToBeMerged = handleEquivalences(target, true, monitor);
- }
-
- if (hasToBeMerged) {
- if (target.getSource() == DifferenceSource.LEFT) {
- reject(target, true);
- } else {
- accept(target, true);
- }
- }
- }
-
- /**
- * Accept the given difference. This may be overridden by clients.
- *
- * @param diff
- * the difference to merge
- * @param rightToLeft
- * the direction of the merge
- */
- protected void accept(final Diff diff, boolean rightToLeft) {
-
- }
-
- /**
- * Reject the given difference. This may be overridden by clients.
- *
- * @param diff
- * the difference to merge
- * @param rightToLeft
- * the direction of the merge
- */
- protected void reject(final Diff diff, boolean rightToLeft) {
-
- }
-
- /**
+ * {@inheritDoc} + * + * @see org.eclipse.emf.compare.merge.IMerger#copyLeftToRight(org.eclipse.emf.compare.Diff, + * org.eclipse.emf.common.util.Monitor) + * @since 4.0 + */ + public void copyLeftToRight(Diff target, Monitor monitor) { + // Don't merge an already merged (or discarded) diff + if (target.getState() != DifferenceState.UNRESOLVED) { + return; + } + + // Change the diff's state before we actually merge it : this allows us to avoid requirement cycles. + target.setState(DifferenceState.MERGED); + + if (target.getSource() == DifferenceSource.LEFT) { + // merge all "requires" diffs + mergeRequires(target, false, monitor); + handleImplies(target, false, monitor); + } else { + // merge all "required by" diffs + mergeRequiredBy(target, false, monitor); + handleImpliedBy(target, false, monitor); + } + + for (Diff refining : target.getRefinedBy()) { + mergeDiff(refining, false, monitor); + } + + boolean hasToBeMerged = true; + if (target.getEquivalence() != null) { + hasToBeMerged = handleEquivalences(target, false, monitor); + } + + if (hasToBeMerged) { + if (target.getSource() == DifferenceSource.LEFT) { + accept(target, false); + } else { + reject(target, false); + } + } + } + + /** + * {@inheritDoc} + * + * @see org.eclipse.emf.compare.merge.IMerger#copyRightToLeft(org.eclipse.emf.compare.Diff, + * org.eclipse.emf.common.util.Monitor) + * @since 4.0 + */ + public void copyRightToLeft(Diff target, Monitor monitor) { + // Don't merge an already merged (or discarded) diff + if (target.getState() != DifferenceState.UNRESOLVED) { + return; + } + + // Change the diff's state before we actually merge it : this allows us to avoid requirement cycles. + target.setState(DifferenceState.MERGED); + + if (target.getSource() == DifferenceSource.LEFT) { + // merge all "required by" diffs + mergeRequiredBy(target, true, monitor); + handleImpliedBy(target, true, monitor); + } else { + // merge all "requires" diffs + mergeRequires(target, true, monitor); + handleImplies(target, true, monitor); + } + + for (Diff refining : target.getRefinedBy()) { + mergeDiff(refining, true, monitor); + } + + boolean hasToBeMerged = true; + if (target.getEquivalence() != null) { + hasToBeMerged = handleEquivalences(target, true, monitor); + } + + if (hasToBeMerged) { + if (target.getSource() == DifferenceSource.LEFT) { + reject(target, true); + } else { + accept(target, true); + } + } + } + + /** + * Accept the given difference. This may be overridden by clients. + * + * @param diff + * the difference to merge + * @param rightToLeft + * the direction of the merge + * @since 4.0 + */ + protected void accept(final Diff diff, boolean rightToLeft) { + // Empty default implementation + } + + /** + * Reject the given difference. This may be overridden by clients. + * + * @param diff + * the difference to merge + * @param rightToLeft + * the direction of the merge + * @since 4.0 + */ + protected void reject(final Diff diff, boolean rightToLeft) { + // Empty default implementation + } + + /** * This will merge all {@link Diff#getRequiredBy() differences that require} {@code diff} in the given * direction. * @@ -210,42 +214,44 @@ public abstract class AbstractMerger implements IMerger { } /** - * Mark as {@link DifferenceState#MERGED merged} all the implied differences recursively from the given
- * one.
- *
- * @param diff
- * The difference from which the implications have to be marked.
- * @param rightToLeft
- * The direction of the merge.
- * @param monitor
- * Monitor.
- */
- protected void handleImplies(Diff diff, boolean rightToLeft, Monitor monitor) {
- for (Diff implied : diff.getImplies()) {
- implied.setState(DifferenceState.MERGED);
- handleImplies(implied, rightToLeft, monitor);
- }
- }
-
- /**
- * Mark as {@link DifferenceState#MERGED merged} all the implying differences recursively from the given
- * one.
- *
- * @param diff
- * The difference from which the implications have to be marked.
- * @param rightToLeft
- * The direction of the merge.
- * @param monitor
- * Monitor.
- */
- protected void handleImpliedBy(Diff diff, boolean rightToLeft, Monitor monitor) {
- for (Diff impliedBy : diff.getImpliedBy()) {
- impliedBy.setState(DifferenceState.MERGED);
- handleImpliedBy(impliedBy, rightToLeft, monitor);
- }
- }
-
- /**
+ * Mark as {@link DifferenceState#MERGED merged} all the implied differences recursively from the given + * one. + * + * @param diff + * The difference from which the implications have to be marked. + * @param rightToLeft + * The direction of the merge. + * @param monitor + * Monitor. + * @since 4.0 + */ + protected void handleImplies(Diff diff, boolean rightToLeft, Monitor monitor) { + for (Diff implied : diff.getImplies()) { + implied.setState(DifferenceState.MERGED); + handleImplies(implied, rightToLeft, monitor); + } + } + + /** + * Mark as {@link DifferenceState#MERGED merged} all the implying differences recursively from the given + * one. + * + * @param diff + * The difference from which the implications have to be marked. + * @param rightToLeft + * The direction of the merge. + * @param monitor + * Monitor. + * @since 4.0 + */ + protected void handleImpliedBy(Diff diff, boolean rightToLeft, Monitor monitor) { + for (Diff impliedBy : diff.getImpliedBy()) { + impliedBy.setState(DifferenceState.MERGED); + handleImpliedBy(impliedBy, rightToLeft, monitor); + } + } + + /** * This will merge all {@link Diff#getRequires() differences required by} {@code diff} in the given * direction. * @@ -287,71 +293,72 @@ public abstract class AbstractMerger implements IMerger { } /** - * Handles the equivalences of this difference.
- * <p>
- * Note that in certain cases, we'll merge our opposite instead of merging this diff. Specifically, we'll
- * do that for one-to-many eOpposites : we'll merge the 'many' side instead of the 'unique' one. This
- * allows us not to worry about the order of the references on that 'many' side.
- * </p>
- * <p>
- * This is called before the merge of <code>this</code>. In short, if this returns <code>false</code>, we
- * won't carry on merging <code>this</code> after returning.
- * </p>
- *
- * @param diff
- * The diff we are currently merging.
- * @param rightToLeft
- * Direction of the merge.
- * @param monitor
- * The monitor to use in order to report progress information.
- * @return <code>true</code> if the current difference should still be merged after handling its
- * equivalences, <code>false</code> if it should be considered "already merged".
- */
- protected boolean handleEquivalences(Diff diff, boolean rightToLeft, Monitor monitor) {
- boolean continueMerge = true;
- for (Diff equivalent : diff.getEquivalence().getDifferences()) {
- // For 1..*, merge diff on many-valued to preserve ordering
- if (diff instanceof ReferenceChange && equivalent instanceof ReferenceChange) {
- final EReference reference = ((ReferenceChange)diff).getReference();
- final EReference equivalentReference = ((ReferenceChange)equivalent).getReference();
-
- if (reference.getEOpposite() == equivalentReference
- && equivalent.getState() == DifferenceState.UNRESOLVED) {
- // This equivalence is on our eOpposite. Should we merge it instead of 'this'?
- final boolean mergeEquivalence = !reference.isMany()
- && ((ReferenceChange)equivalent).getReference().isMany();
- if (mergeEquivalence) {
- mergeDiff(equivalent, rightToLeft, monitor);
- continueMerge = false;
- }
- }
- }
-
- /*
- * If one of the equivalent differences is implied or implying (depending on the merge direction)
- * a merged diff, then we have a dependency loop : the "current" difference has already been
- * merged because of this implication. This will allow us to break out of that loop.
- */
- if (rightToLeft) {
- if (diff.getSource() == DifferenceSource.LEFT) {
- continueMerge = continueMerge && !any(equivalent.getImplies(), in(diff.getRequiredBy()));
- } else {
- continueMerge = continueMerge && !any(equivalent.getImpliedBy(), in(diff.getRequires()));
- }
- } else {
- if (diff.getSource() == DifferenceSource.LEFT) {
- continueMerge = continueMerge && !any(equivalent.getImpliedBy(), in(diff.getRequires()));
- } else {
- continueMerge = continueMerge && !any(equivalent.getImplies(), in(diff.getRequiredBy()));
- }
- }
-
- equivalent.setState(DifferenceState.MERGED);
- }
- return continueMerge;
- }
-
- /**
+ * Handles the equivalences of this difference. + * <p> + * Note that in certain cases, we'll merge our opposite instead of merging this diff. Specifically, we'll + * do that for one-to-many eOpposites : we'll merge the 'many' side instead of the 'unique' one. This + * allows us not to worry about the order of the references on that 'many' side. + * </p> + * <p> + * This is called before the merge of <code>this</code>. In short, if this returns <code>false</code>, we + * won't carry on merging <code>this</code> after returning. + * </p> + * + * @param diff + * The diff we are currently merging. + * @param rightToLeft + * Direction of the merge. + * @param monitor + * The monitor to use in order to report progress information. + * @return <code>true</code> if the current difference should still be merged after handling its + * equivalences, <code>false</code> if it should be considered "already merged". + * @since 4.0 + */ + protected boolean handleEquivalences(Diff diff, boolean rightToLeft, Monitor monitor) { + boolean continueMerge = true; + for (Diff equivalent : diff.getEquivalence().getDifferences()) { + // For 1..*, merge diff on many-valued to preserve ordering + if (diff instanceof ReferenceChange && equivalent instanceof ReferenceChange) { + final EReference reference = ((ReferenceChange)diff).getReference(); + final EReference equivalentReference = ((ReferenceChange)equivalent).getReference(); + + if (reference.getEOpposite() == equivalentReference + && equivalent.getState() == DifferenceState.UNRESOLVED) { + // This equivalence is on our eOpposite. Should we merge it instead of 'this'? + final boolean mergeEquivalence = !reference.isMany() + && ((ReferenceChange)equivalent).getReference().isMany(); + if (mergeEquivalence) { + mergeDiff(equivalent, rightToLeft, monitor); + continueMerge = false; + } + } + } + + /* + * If one of the equivalent differences is implied or implying (depending on the merge direction) + * a merged diff, then we have a dependency loop : the "current" difference has already been + * merged because of this implication. This will allow us to break out of that loop. + */ + if (rightToLeft) { + if (diff.getSource() == DifferenceSource.LEFT) { + continueMerge = continueMerge && !any(equivalent.getImplies(), in(diff.getRequiredBy())); + } else { + continueMerge = continueMerge && !any(equivalent.getImpliedBy(), in(diff.getRequires())); + } + } else { + if (diff.getSource() == DifferenceSource.LEFT) { + continueMerge = continueMerge && !any(equivalent.getImpliedBy(), in(diff.getRequires())); + } else { + continueMerge = continueMerge && !any(equivalent.getImplies(), in(diff.getRequiredBy())); + } + } + + equivalent.setState(DifferenceState.MERGED); + } + return continueMerge; + } + + /** * This will create a copy of the given EObject that can be used as the target of an addition (or the * reverting of a deletion). * <p> 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 7cba77e9b..15a7fe64b 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Obeo. + * Copyright (c) 2013, 2014 Obeo. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -25,7 +25,7 @@ import org.eclipse.emf.compare.EMFCompareMessages; * This specific implementation of {@link AbstractMerger} will be used to merge real conflicts. * * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> - * @since 3.1 + * @since 4.0 */ public class ConflictMerger extends AbstractMerger { 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 e4283c27a..400d3ee8a 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 @@ -1,5 +1,5 @@ /*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
+ * Copyright (c) 2012, 2014 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -26,7 +26,7 @@ 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.utils.DiffUtil;
+import org.eclipse.emf.compare.internal.utils.DiffUtil;
import org.eclipse.emf.compare.utils.IEqualityHelper;
import org.eclipse.emf.compare.utils.ReferenceUtil;
import org.eclipse.emf.ecore.EObject;
@@ -529,6 +529,7 @@ public class ReferenceChangeMerger extends AbstractMerger { * The diff we are currently merging.
* @param rightToLeft
* Direction of the merge.
+ * @since 4.0
*/
protected void checkImpliedDiffsOrdering(ReferenceChange diff, boolean rightToLeft) {
final EReference reference = diff.getReference();
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ResourceAttachmentChangeMerger.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ResourceAttachmentChangeMerger.java index a14620abe..d968db881 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ResourceAttachmentChangeMerger.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/merge/ResourceAttachmentChangeMerger.java @@ -1,5 +1,5 @@ /*******************************************************************************
- * Copyright (c) 2012, 2013 Obeo.
+ * Copyright (c) 2012, 2014 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -199,7 +199,7 @@ public class ResourceAttachmentChangeMerger extends AbstractMerger { if (targetURI == null) {
// We treat null as "no valid target". We'll cancel the merge operation.
// FIXME we need to rollback the current merge operation.
- throw new RuntimeException("Couldn't create a valid target resource for "
+ throw new RuntimeException("Couldn't create a valid target resource for " //$NON-NLS-1$
+ sourceRes.getURI());
}
@@ -224,8 +224,8 @@ public class ResourceAttachmentChangeMerger extends AbstractMerger { // This resource might already exists... in which case we cannot use it
if (targetSet.getURIConverter().exists(targetURI, Collections.emptyMap())) {
// FIXME we need to rollback the current merge operation.
- throw new RuntimeException("The resource '" + sourceRes.getURI()
- + "' already exists at that location.");
+ throw new RuntimeException("The resource '" + sourceRes.getURI() //$NON-NLS-1$
+ + "' already exists at that location."); //$NON-NLS-1$
} else {
target = targetSet.createResource(targetURI);
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java index 365608b00..dea79bb0d 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2013 Obeo. + * Copyright (c) 2012, 2014 Obeo. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -39,15 +39,22 @@ import org.eclipse.emf.ecore.EcorePackage; * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a> */ public final class EMFComparePredicates { - - /** This can be used to test whether a given Diff has no conflict object associated. */ + /** + * This can be used to test whether a given Diff has no conflict object associated. + * + * @since 4.0 + */ public static final Predicate<? super Diff> WITHOUT_CONFLICT = new Predicate<Diff>() { public boolean apply(Diff input) { return input != null && input.getConflict() == null; } }; - /** This can be used to check whether a given diff is a containment reference change. */ + /** + * This can be used to check whether a given diff is a containment reference change. + * + * @since 4.0 + */ public static final Predicate<? super Diff> CONTAINMENT_REFERENCE_CHANGE = new Predicate<Diff>() { public boolean apply(Diff input) { return input instanceof ReferenceChange @@ -774,18 +781,6 @@ public final class EMFComparePredicates { } /** - * This can be used to check whether a given diff is a containment move reference change. - * - * @return The created predicate. - * @since 3.0 - * @deprecated use and(CONTAINMENT_REFERENCE_CHANGE, ofKind(DifferenceKind.MOVE)) instead. - */ - @Deprecated - public static Predicate<? super Diff> containmentMoveReferenceChange() { - return and(CONTAINMENT_REFERENCE_CHANGE, ofKind(DifferenceKind.MOVE)); - } - - /** * This will be used to check that a given {@link EObject} corresponds to the given {@code qualifiedName}. * <p> * For example, {@code match("extlibrary.BookCategory.Encyclopedia")} will return {@code true} for an |