Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlgoubet2008-07-09 15:52:26 +0000
committerlgoubet2008-07-09 15:52:26 +0000
commit91b96bb4264637a50a7d455d77b5135887a39064 (patch)
tree21bb5b9b7def398f0b6f0a300ebe18789383f650
parent8173ecb31c8c2783b6e4bbb76c7de49b1e5e1c45 (diff)
downloadorg.eclipse.emf.compare-91b96bb4264637a50a7d455d77b5135887a39064.tar.gz
org.eclipse.emf.compare-91b96bb4264637a50a7d455d77b5135887a39064.tar.xz
org.eclipse.emf.compare-91b96bb4264637a50a7d455d77b5135887a39064.zip
Fixing potential NPE and Negative window size
-rw-r--r--plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/api/MatchOptions.java4
-rwxr-xr-xplugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/engine/GenericMatchEngine.java8
-rw-r--r--plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/service/MatchService.java52
3 files changed, 32 insertions, 32 deletions
diff --git a/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/api/MatchOptions.java b/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/api/MatchOptions.java
index f743ae706..80da78abc 100644
--- a/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/api/MatchOptions.java
+++ b/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/api/MatchOptions.java
@@ -22,7 +22,7 @@ package org.eclipse.emf.compare.match.api;
* <tr>
* <td>{@link #OPTION_DISTINCT_METAMODEL}</td>
* <td>Specifies whether the models to compare are of the same meta-model. This mainly impact performance by
- * allowing faster check to match elements (no use trying to match an interface and a class).</td>
+ * allowing faster checks to match elements (no use trying to match an interface and a class).</td>
* <td>Boolean, defaults to <code>false</code></td>
* </tr>
* <tr>
@@ -44,7 +44,7 @@ package org.eclipse.emf.compare.match.api;
* <td>{@link #OPTION_SEARCH_WINDOW}</td>
* <td>Specifies the number of siblings the match procedure will consider to find similar objects. Higher
* values increase comparison time, lower values decrease comparison accuracy.</td>
- * <td>Positive integer, defaults to <code>100</code></td>
+ * <td>Positive integer, defaults to <code>100</code>. A negative value will be reset to the default.</td>
* </tr>
* </table>
* </p>
diff --git a/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/engine/GenericMatchEngine.java b/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/engine/GenericMatchEngine.java
index 970a33cc8..2e8eee8ea 100755
--- a/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/engine/GenericMatchEngine.java
+++ b/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/engine/GenericMatchEngine.java
@@ -1134,7 +1134,7 @@ public class GenericMatchEngine implements IMatchEngine {
/**
* Workaround for bug #235606 : elements held by a reference with containment=true and derived=true are
- * not match since not returned by {@link EObject#eContents()}. This allows us to return the list of all
+ * not matched since not returned by {@link EObject#eContents()}. This allows us to return the list of all
* contents from an EObject <u>including</u> those references.
*
* @param eObject
@@ -1208,6 +1208,8 @@ public class GenericMatchEngine implements IMatchEngine {
EMFComparePreferenceKeys.PREFERENCES_KEY_SEARCH_WINDOW) > 0)
searchWindow = EMFComparePlugin.getDefault().getInt(
EMFComparePreferenceKeys.PREFERENCES_KEY_SEARCH_WINDOW);
+ if (searchWindow < 0)
+ searchWindow = 0;
return searchWindow;
}
@@ -1259,6 +1261,8 @@ public class GenericMatchEngine implements IMatchEngine {
*/
private void loadOptionMap(Map<String, Object> map) {
options.putAll(map);
+ if (this.<Integer> getOption(MatchOptions.OPTION_SEARCH_WINDOW) < 0)
+ options.put(MatchOptions.OPTION_SEARCH_WINDOW, getPreferenceSearchWindow());
}
/**
@@ -1491,7 +1495,7 @@ public class GenericMatchEngine implements IMatchEngine {
final Iterator<EStructuralFeature> features = eobj.eClass().getEAllStructuralFeatures().iterator();
while (features.hasNext()) {
final EStructuralFeature feature = features.next();
- if (eobj.eGet(feature) != null && !"".equals(eobj.eGet(feature).toString())) //$NON-NLS-1$
+ if (eobj.eGet(feature) != null && !eobj.eGet(feature).toString().equals("")) //$NON-NLS-1$
nonNullFeatures++;
}
return nonNullFeatures;
diff --git a/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/service/MatchService.java b/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/service/MatchService.java
index 1751dbe57..1bc205b5c 100644
--- a/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/service/MatchService.java
+++ b/plugins/org.eclipse.emf.compare.match/src/org/eclipse/emf/compare/match/service/MatchService.java
@@ -79,7 +79,8 @@ public final class MatchService {
*/
public static MatchModel doContentMatch(EObject leftObject, EObject rightObject, EObject ancestor,
Map<String, Object> options) throws InterruptedException {
- final String extension = getBestExtension(leftObject, rightObject, ancestor);
+ final String extension = getBestExtension(leftObject.eResource(), rightObject.eResource(), ancestor
+ .eResource());
final IMatchEngine engine = getBestMatchEngine(extension);
return engine.contentMatch(leftObject, rightObject, ancestor, options);
}
@@ -103,7 +104,7 @@ public final class MatchService {
*/
public static MatchModel doContentMatch(EObject leftObject, EObject rightObject,
Map<String, Object> options) throws InterruptedException {
- final String extension = getBestExtension(leftObject, rightObject);
+ final String extension = getBestExtension(leftObject.eResource(), rightObject.eResource());
final IMatchEngine engine = getBestMatchEngine(extension);
return engine.contentMatch(leftObject, rightObject, options);
}
@@ -127,7 +128,8 @@ public final class MatchService {
*/
public static MatchModel doMatch(EObject leftRoot, EObject rightRoot, EObject ancestor,
Map<String, Object> options) throws InterruptedException {
- final String extension = getBestExtension(leftRoot, rightRoot, ancestor);
+ final String extension = getBestExtension(leftRoot.eResource(), rightRoot.eResource(), ancestor
+ .eResource());
final IMatchEngine engine = getBestMatchEngine(extension);
return engine.modelMatch(leftRoot, rightRoot, ancestor, options);
}
@@ -149,7 +151,7 @@ public final class MatchService {
*/
public static MatchModel doMatch(EObject leftRoot, EObject rightRoot, Map<String, Object> options)
throws InterruptedException {
- final String extension = getBestExtension(leftRoot, rightRoot);
+ final String extension = getBestExtension(leftRoot.eResource(), rightRoot.eResource());
final IMatchEngine engine = getBestMatchEngine(extension);
return engine.modelMatch(leftRoot, rightRoot, options);
}
@@ -173,11 +175,7 @@ public final class MatchService {
*/
public static MatchModel doResourceMatch(Resource leftResource, Resource rightResource,
Map<String, Object> options) throws InterruptedException {
- String extension = DEFAULT_EXTENSION;
- if (leftResource.getURI() != null && leftResource.getURI().fileExtension() != null)
- extension = leftResource.getURI().fileExtension();
- else if (rightResource.getURI() != null && rightResource.getURI().fileExtension() != null)
- extension = rightResource.getURI().fileExtension();
+ final String extension = getBestExtension(leftResource, rightResource);
final IMatchEngine engine = getBestMatchEngine(extension);
return engine.resourceMatch(leftResource, rightResource, options);
}
@@ -201,13 +199,7 @@ public final class MatchService {
*/
public static MatchModel doResourceMatch(Resource leftResource, Resource rightResource,
Resource ancestorResource, Map<String, Object> options) throws InterruptedException {
- String extension = DEFAULT_EXTENSION;
- if (leftResource.getURI() != null && leftResource.getURI().fileExtension() != null)
- extension = leftResource.getURI().fileExtension();
- else if (rightResource.getURI() != null && rightResource.getURI().fileExtension() != null)
- extension = rightResource.getURI().fileExtension();
- else if (ancestorResource.getURI() != null && ancestorResource.getURI().fileExtension() != null)
- extension = ancestorResource.getURI().fileExtension();
+ final String extension = getBestExtension(leftResource, rightResource, ancestorResource);
final IMatchEngine engine = getBestMatchEngine(extension);
return engine.resourceMatch(leftResource, rightResource, ancestorResource, options);
}
@@ -245,21 +237,25 @@ public final class MatchService {
}
/**
- * This will try and find the file extension of the compared models. Left resource is considered before
- * the right one which in turns goes before the ancestor. If no file extension can be found, returns
- * {@link #DEFAULT_EXTENSION}.
+ * This will try and find the file extension of the compared models.
+ * <p>
+ * When the two extensions are distinct or empty, {@link #DEFAULT_EXTENSION} will be returned.
+ * </p>
*
- * @param eObjects
- * The EObjects that will be compared.
+ * @param resources
+ * The Resources that will be compared.
* @return The file extension to consider when searching for a match engine.
*/
- private static String getBestExtension(EObject... eObjects) {
- String extension = DEFAULT_EXTENSION;
- for (EObject eObj : eObjects) {
- final Resource resource = eObj.eResource();
- if (resource != null && resource.getURI() != null && resource.getURI().fileExtension() != null) {
- extension = resource.getURI().fileExtension();
- break;
+ private static String getBestExtension(Resource... resources) {
+ String extension = null;
+ for (int i = 0; i < resources.length; i++) {
+ if (resources[i].getURI() != null) {
+ if (extension == null)
+ extension = resources[i].getURI().fileExtension();
+ else if (!extension.equals(resources[i].getURI().fileExtension())) {
+ extension = DEFAULT_EXTENSION;
+ break;
+ }
}
}
return extension;

Back to the top