Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Langer2015-02-28 19:20:24 +0000
committerAxel RICHARD2015-03-02 14:23:10 +0000
commit40d061bf59466ddfedbbdc4426aa7f74f3996c35 (patch)
treed66c0aa258e646b15e59cd6a6e6331831294f363
parent01ea4a0e47ca488514e9556921bfb343d2b25504 (diff)
downloadorg.eclipse.emf.compare-40d061bf59466ddfedbbdc4426aa7f74f3996c35.tar.gz
org.eclipse.emf.compare-40d061bf59466ddfedbbdc4426aa7f74f3996c35.tar.xz
org.eclipse.emf.compare-40d061bf59466ddfedbbdc4426aa7f74f3996c35.zip
[460778] Improves duplicate ID warning in IdentifierEObjectMatcher
We now add -- if available -- the URI of the resource containing the EObject that has the duplicate ID to the warning. Also, we externalized the warning String. Bug: 460778 Change-Id: I08f270910a2cc45eeffb77785402ae71498b67b6 Signed-off-by: Philip Langer <planger@eclipsesource.com>
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/emfcomparemessages.properties6
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/IdentifierEObjectMatcher.java58
2 files changed, 53 insertions, 11 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 5c696e52e..df835be7d 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
@@ -1,5 +1,5 @@
################################################################################
-# Copyright (c) 2006, 2015 Obeo.
+# Copyright (c) 2006, 2015 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
@@ -7,6 +7,7 @@
#
# Contributors:
# Obeo - initial API and implementation
+# Philip Langer - adds message for duplicate ID in IdentifierEObjectMatcher
################################################################################
## ! note ! double the apostrophes if you need one in the printed String
@@ -35,3 +36,6 @@ DefaultEquiEngine.monitor.eq = Computing equivalences...
DefaultMatchEngine.monitor.match.resourceSet = Matching given resource sets...
DefaultMatchEngine.monitor.match.resource = Matching given resources...
DefaultMatchEngine.monitor.match.eobject = Matching given EObjects...
+
+IdentifierEObjectMatcher.duplicateId = Duplicate ID {0} found on the {1} side.
+IdentifierEObjectMatcher.duplicateIdWithResource = Duplicate ID ''{0}'' found on the {1} side in resource ''{2}''.
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/IdentifierEObjectMatcher.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/IdentifierEObjectMatcher.java
index 3b4d08f7c..c30a6a11c 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/IdentifierEObjectMatcher.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/IdentifierEObjectMatcher.java
@@ -8,6 +8,7 @@
* Contributors:
* Obeo - initial API and implementation
* Alexandra Buzila - Bug 450360
+ * Philip Langer - Bug 460778
*******************************************************************************/
package org.eclipse.emf.compare.match.eobject;
@@ -26,9 +27,12 @@ import java.util.Set;
import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.Monitor;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.CompareFactory;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.ComparisonCanceledException;
+import org.eclipse.emf.compare.EMFCompare;
+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.ecore.EObject;
@@ -232,7 +236,7 @@ public class IdentifierEObjectMatcher implements IEObjectMatcher {
matches.add(match);
}
if (idToMatch.containsKey(identifier)) {
- reportDuplicateID(Side.LEFT, identifier);
+ reportDuplicateID(Side.LEFT, left);
}
idToMatch.put(identifier, match);
leftEObjectsToMatch.put(left, match);
@@ -250,7 +254,7 @@ public class IdentifierEObjectMatcher implements IEObjectMatcher {
Match match = idToMatch.get(identifier);
if (match != null) {
if (match.getRight() != null) {
- reportDuplicateID(Side.RIGHT, identifier);
+ reportDuplicateID(Side.RIGHT, right);
}
match.setRight(right);
@@ -286,7 +290,7 @@ public class IdentifierEObjectMatcher implements IEObjectMatcher {
Match match = idToMatch.get(identifier);
if (match != null) {
if (match.getOrigin() != null) {
- reportDuplicateID(Side.ORIGIN, identifier);
+ reportDuplicateID(Side.ORIGIN, origin);
}
match.setOrigin(origin);
@@ -316,17 +320,51 @@ public class IdentifierEObjectMatcher implements IEObjectMatcher {
}
/**
- * Adds a warning diagnostic to the comparison for the duplicate ID.
+ * Adds a warning diagnostic to the comparison for an object that has a duplicate ID.
*
* @param side
* the side where the duplicate ID was found
- * @param identifier
- * the ID that has a duplicate
+ * @param eObject
+ * the element with the duplicate ID
*/
- private void reportDuplicateID(Side side, String identifier) {
- diagnostic.add(new BasicDiagnostic(Diagnostic.WARNING, "org.eclipse.emf.compare", 0, //$NON-NLS-1$
- "Duplicate ID found on the " + side.name() + " side. (value = '" + identifier + "')", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- null));
+ private void reportDuplicateID(Side side, EObject eObject) {
+ final String duplicateID = idComputation.apply(eObject);
+ final String sideName = side.name().toLowerCase();
+ final String uriString = getUriString(eObject);
+ final String message;
+ if (uriString != null) {
+ message = EMFCompareMessages.getString("IdentifierEObjectMatcher.duplicateIdWithResource", //$NON-NLS-1$
+ duplicateID, sideName, uriString);
+ } else {
+ message = EMFCompareMessages.getString("IdentifierEObjectMatcher.duplicateId", //$NON-NLS-1$
+ duplicateID, sideName);
+ }
+ diagnostic
+ .add(new BasicDiagnostic(Diagnostic.WARNING, EMFCompare.DIAGNOSTIC_SOURCE, 0, message, null));
+ }
+
+ /**
+ * Returns a String representation of the URI of the given {@code eObject}'s resource.
+ * <p>
+ * If the {@code eObject}'s resource or its URI is <code>null</code>, this method returns
+ * <code>null</code>.
+ * </p>
+ *
+ * @param eObject
+ * @return A String representation of the given {@code eObject}'s resource URI.
+ */
+ private String getUriString(EObject eObject) {
+ String uriString = null;
+ final Resource resource = eObject.eResource();
+ if (resource != null && resource.getURI() != null) {
+ final URI uri = resource.getURI();
+ if (uri.isPlatform()) {
+ uriString = uri.toPlatformString(true);
+ } else {
+ uriString = uri.toString();
+ }
+ }
+ return uriString;
}
/**

Back to the top