Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStéphane Thibaudeau2018-06-20 21:04:43 +0000
committerlgoubet2018-06-22 11:46:11 +0000
commit852f6705de1c21387ec3cde415b54ad1c9868cc0 (patch)
tree87b745a7303b8a4d512014866612fa1f24d9308d
parent31d4e31c8a6b88b9f7e60a7c29df31b47c707ebd (diff)
downloadorg.eclipse.emf.compare-852f6705de1c21387ec3cde415b54ad1c9868cc0.tar.gz
org.eclipse.emf.compare-852f6705de1c21387ec3cde415b54ad1c9868cc0.tar.xz
org.eclipse.emf.compare-852f6705de1c21387ec3cde415b54ad1c9868cc0.zip
Extension point to provide specific matching rules for equality helper
Change-Id: Ib3f7204339ff983994ba6bcfec435649928c9f29 Signed-off-by: Stéphane Thibaudeau <stephane.thibaudeau@obeo.fr>
-rw-r--r--plugins/org.eclipse.emf.compare.egit/src/org/eclipse/emf/compare/egit/internal/match/EGitMatchEngineFactory.java4
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/AbstractCompareHandler.java3
-rw-r--r--plugins/org.eclipse.emf.compare.rcp/plugin.xml1
-rw-r--r--plugins/org.eclipse.emf.compare.rcp/schema/equalityHelperExtensionProvider.exsd154
-rw-r--r--plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java38
-rw-r--r--plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/DefaultRCPMatchEngineFactory.java3
-rw-r--r--plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/EqualityHelperExtensionProviderDescriptorRCPImpl.java84
-rw-r--r--plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/EqualityHelperExtensionProviderDescriptorRegistryListener.java126
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/DefaultMatchEngine.java58
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java27
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EqualityHelperExtensionProvider.java143
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EqualityHelperExtensionProviderDescriptorRegistryImpl.java184
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/impl/MatchEngineFactoryImpl.java50
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EqualityHelper.java52
14 files changed, 908 insertions, 19 deletions
diff --git a/plugins/org.eclipse.emf.compare.egit/src/org/eclipse/emf/compare/egit/internal/match/EGitMatchEngineFactory.java b/plugins/org.eclipse.emf.compare.egit/src/org/eclipse/emf/compare/egit/internal/match/EGitMatchEngineFactory.java
index ea07a3093..9d9c30f12 100644
--- a/plugins/org.eclipse.emf.compare.egit/src/org/eclipse/emf/compare/egit/internal/match/EGitMatchEngineFactory.java
+++ b/plugins/org.eclipse.emf.compare.egit/src/org/eclipse/emf/compare/egit/internal/match/EGitMatchEngineFactory.java
@@ -70,7 +70,9 @@ public class EGitMatchEngineFactory extends DefaultRCPMatchEngineFactory {
final Collection<IResourceMatchingStrategy> strategies = Sets.newLinkedHashSet();
strategies.add(new LocationMatchingStrategy());
return DefaultMatchEngine.create(useUdentifier,
- EMFCompareRCPPlugin.getDefault().getWeightProviderRegistry(), strategies);
+ EMFCompareRCPPlugin.getDefault().getWeightProviderRegistry(),
+ EMFCompareRCPPlugin.getDefault().getEqualityHelperExtensionProviderRegistry(),
+ strategies);
}
/**
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/AbstractCompareHandler.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/AbstractCompareHandler.java
index 5d3e0aedf..494632cff 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/AbstractCompareHandler.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/AbstractCompareHandler.java
@@ -176,7 +176,8 @@ public abstract class AbstractCompareHandler extends AbstractHandler {
public MatchEObjectEngine() {
// never use id in EObjects comparison
super(DefaultMatchEngine.createDefaultEObjectMatcher(UseIdentifiers.NEVER,
- EMFCompareRCPPlugin.getDefault().getWeightProviderRegistry()),
+ EMFCompareRCPPlugin.getDefault().getWeightProviderRegistry(),
+ EMFCompareRCPPlugin.getDefault().getEqualityHelperExtensionProviderRegistry()),
new DefaultComparisonFactory(new DefaultEqualityHelperFactory()));
}
diff --git a/plugins/org.eclipse.emf.compare.rcp/plugin.xml b/plugins/org.eclipse.emf.compare.rcp/plugin.xml
index 7cf71d082..c68c495b2 100644
--- a/plugins/org.eclipse.emf.compare.rcp/plugin.xml
+++ b/plugins/org.eclipse.emf.compare.rcp/plugin.xml
@@ -23,6 +23,7 @@
<extension-point id="conflictsDetector" name="Conflicts Detector" schema="schema/conflictsDetector.exsd"/>
<extension-point id="reqEngine" name="Requirements Engine" schema="schema/reqEngine.exsd"/>
<extension-point id="weightProvider" name="Weight Provider" schema="schema/weightProvider.exsd"/>
+ <extension-point id="equalityHelperExtensionProvider" name="Equality Helper Extension Provider" schema="schema/equalityHelperExtensionProvider.exsd"/>
<extension point="org.eclipse.emf.ecore.generated_package">
<package
diff --git a/plugins/org.eclipse.emf.compare.rcp/schema/equalityHelperExtensionProvider.exsd b/plugins/org.eclipse.emf.compare.rcp/schema/equalityHelperExtensionProvider.exsd
new file mode 100644
index 000000000..5a432282a
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp/schema/equalityHelperExtensionProvider.exsd
@@ -0,0 +1,154 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.emf.compare.rcp" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.emf.compare.rcp" id="equalityHelperExtensionProvider" name="Equality Helper Extension Provider"/>
+ </appinfo>
+ <documentation>
+ This extension point can be used for customizing the equality helper extension provider used for comparison.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="provider" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="provider">
+ <complexType>
+ <attribute name="label" type="string" use="required">
+ <annotation>
+ <documentation>
+ Label of the provider.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="description" type="string" use="required">
+ <annotation>
+ <documentation>
+ Description of the provider.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ Unique identifier of the provider.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+ Implementation of the equality helper extension provider.
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProvider"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="ranking" type="string" use="required">
+ <annotation>
+ <documentation>
+ Rank of the provider. The provider with the highest rank is used by default. (integer value)
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="nsURI" type="string" use="required">
+ <annotation>
+ <documentation>
+ The pattern of namespace URI on which this provider can be applied.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ &lt;extension point=&quot;org.eclipse.emf.compare.rcp.equalityHelperExtensionProvider&quot;&gt;
+ &lt;provider
+ description=&quot;Example implementation of specific equality helper extension provider.&quot;
+ id=&quot;org.eclipse.emf.compare.rcp.example.myEqualityHelperExtensionProvider&quot;
+ impl=&quot;org.eclipse.emf.compare.match.example.MyEqualityHelperExtensionProvider&quot;
+ label=&quot;Example Equality helper extension Provider&quot;
+ nsURI=&quot;.*&quot;
+ ranking=&quot;100&quot;&gt;
+ &lt;/provider&gt;
+&lt;/extension&gt;
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ Copyright (c) 2018 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 http://www.eclipse.org/legal/epl-v10.html
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java
index 38b7da5e2..9f203e0f2 100644
--- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java
+++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java
@@ -57,6 +57,8 @@ import org.eclipse.emf.compare.internal.adapterfactory.RankedAdapterFactoryDescr
import org.eclipse.emf.compare.internal.adapterfactory.RankedAdapterFactoryDescriptorRegistryImpl;
import org.eclipse.emf.compare.internal.utils.Graph;
import org.eclipse.emf.compare.match.IMatchEngine;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProvider;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProviderDescriptorRegistryImpl;
import org.eclipse.emf.compare.match.eobject.WeightProvider;
import org.eclipse.emf.compare.match.eobject.WeightProviderDescriptorRegistryImpl;
import org.eclipse.emf.compare.merge.IMerger;
@@ -69,6 +71,7 @@ import org.eclipse.emf.compare.rcp.internal.adapterfactory.AdapterFactoryDescrip
import org.eclipse.emf.compare.rcp.internal.extension.IItemRegistry;
import org.eclipse.emf.compare.rcp.internal.extension.impl.DescriptorRegistryEventListener;
import org.eclipse.emf.compare.rcp.internal.extension.impl.ItemRegistry;
+import org.eclipse.emf.compare.rcp.internal.match.EqualityHelperExtensionProviderDescriptorRegistryListener;
import org.eclipse.emf.compare.rcp.internal.match.MatchEngineFactoryRegistryListener;
import org.eclipse.emf.compare.rcp.internal.match.MatchEngineFactoryRegistryWrapper;
import org.eclipse.emf.compare.rcp.internal.match.WeightProviderDescriptorRegistryListener;
@@ -111,6 +114,9 @@ public class EMFCompareRCPPlugin extends Plugin {
/** The id of the weight provider extension point. */
public static final String WEIGHT_PROVIDER_PPID = "weightProvider"; //$NON-NLS-1$
+ /** The id of the equality helper extension provider extension point. */
+ public static final String EQUALITY_HELPER_EXTENSION_PROVIDER_PPID = "equalityHelperExtensionProvider"; //$NON-NLS-1$
+
/** The id of the load on demand policy extension point. */
public static final String LOAD_ON_DEMAND_POLICY_PPID = "loadOnDemandPolicy"; //$NON-NLS-1$
@@ -152,6 +158,9 @@ public class EMFCompareRCPPlugin extends Plugin {
/** The registry that will hold references to all weight providers. */
private WeightProvider.Descriptor.Registry weightProviderRegistry;
+ /** The registry that will hold references to all equality helper extension providers. */
+ private EqualityHelperExtensionProvider.Descriptor.Registry equalityHelperExtensionProviderRegistry;
+
/** The registry listener that will be used to react to merger changes. */
private AbstractRegistryEventListener mergerRegistryListener;
@@ -203,6 +212,9 @@ public class EMFCompareRCPPlugin extends Plugin {
/** The registry listener that will be used to react to weight provider changes. */
private WeightProviderDescriptorRegistryListener weightProviderListener;
+ /** The registry listener that will be used to react to equality helper extension provider changes. */
+ private EqualityHelperExtensionProviderDescriptorRegistryListener equalityHelperExtensionProviderListener;
+
/** Will listen to preference changes and update log4j configuration accordingly. */
private LoggingPreferenceChangeListener preferenceChangeListener;
@@ -242,6 +254,8 @@ public class EMFCompareRCPPlugin extends Plugin {
setUpConflictDetectorRegistry(registry);
+ setUpEqualityHelperExtensionProviderRegistry(registry);
+
initLogging();
}
@@ -394,6 +408,21 @@ public class EMFCompareRCPPlugin extends Plugin {
weightProviderListener.readRegistry(registry);
}
+ /**
+ * Set the Matching And Distance Provider Registry.
+ *
+ * @param registry
+ * {@link IExtensionRegistry} to listen in order to fill the registry
+ */
+ private void setUpEqualityHelperExtensionProviderRegistry(final IExtensionRegistry registry) {
+ equalityHelperExtensionProviderRegistry = new EqualityHelperExtensionProviderDescriptorRegistryImpl();
+ equalityHelperExtensionProviderListener = new EqualityHelperExtensionProviderDescriptorRegistryListener(
+ PLUGIN_ID, EQUALITY_HELPER_EXTENSION_PROVIDER_PPID, getLog(),
+ equalityHelperExtensionProviderRegistry);
+ registry.addListener(equalityHelperExtensionProviderListener);
+ equalityHelperExtensionProviderListener.readRegistry(registry);
+ }
+
/*
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
@@ -689,6 +718,15 @@ public class EMFCompareRCPPlugin extends Plugin {
}
/**
+ * Returns the registry of equality helper extension providers.
+ *
+ * @return the registry of equality helper extension providers
+ */
+ public EqualityHelperExtensionProvider.Descriptor.Registry getEqualityHelperExtensionProviderRegistry() {
+ return equalityHelperExtensionProviderRegistry;
+ }
+
+ /**
* Returns the match engine factory registry to which extension will be registered.
*
* @return the match engine factory registry to which extension will be registered
diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/DefaultRCPMatchEngineFactory.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/DefaultRCPMatchEngineFactory.java
index f94fc982a..b5a82878d 100644
--- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/DefaultRCPMatchEngineFactory.java
+++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/DefaultRCPMatchEngineFactory.java
@@ -68,7 +68,8 @@ public class DefaultRCPMatchEngineFactory implements IMatchEngine.Factory {
public IMatchEngine getMatchEngine() {
final UseIdentifiers useUdentifier = getUseIdentifierValue();
return DefaultMatchEngine.create(useUdentifier,
- EMFCompareRCPPlugin.getDefault().getWeightProviderRegistry());
+ EMFCompareRCPPlugin.getDefault().getWeightProviderRegistry(),
+ EMFCompareRCPPlugin.getDefault().getEqualityHelperExtensionProviderRegistry(), null);
}
/**
diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/EqualityHelperExtensionProviderDescriptorRCPImpl.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/EqualityHelperExtensionProviderDescriptorRCPImpl.java
new file mode 100644
index 000000000..c44bf860a
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/EqualityHelperExtensionProviderDescriptorRCPImpl.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.rcp.internal.match;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProvider;
+import org.eclipse.emf.compare.rcp.extension.PluginClassDescriptor;
+
+/**
+ * Describes an extension as contributed to the "org.eclipse.emf.compare.rcp.equalityHelperExtensionProvider"
+ * extension point.
+ *
+ * @author <a href="mailto:stephane.thibaudeau@obeo.fr">Stephane Thibaudeau</a>
+ */
+public class EqualityHelperExtensionProviderDescriptorRCPImpl extends PluginClassDescriptor<EqualityHelperExtensionProvider> implements EqualityHelperExtensionProvider.Descriptor {
+
+ /** The wrapped equality helper extension provider. */
+ private EqualityHelperExtensionProvider instance;
+
+ /** The ranking of the equality helper extension provider. */
+ private int ranking;
+
+ /** The pattern of namespace URI on which this equality helper extension provider can be applied. */
+ private Pattern nsURI;
+
+ /**
+ * Creates a descriptor corresponding to the information of the given <em>element</em>.
+ *
+ * @param element
+ * Configuration element from which to create this descriptor.
+ * @param ranking
+ * the ranking of the equality helper extension provider.
+ * @param nsURI
+ * The pattern of namespace URI on which this equality helper extension can be applied.
+ */
+ public EqualityHelperExtensionProviderDescriptorRCPImpl(IConfigurationElement element, int ranking,
+ Pattern nsURI) {
+ super(element, EqualityHelperExtensionProviderDescriptorRegistryListener.ATT_CLASS);
+ this.ranking = ranking;
+ this.nsURI = nsURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Pattern getNsURI() {
+ return nsURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getRanking() {
+ return ranking;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EqualityHelperExtensionProvider getEqualityHelperExtensionProvider() {
+ if (instance == null) {
+ instance = createInstance();
+ }
+ return instance;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getInstanceClassName() {
+ return element.getAttribute(attributeName);
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/EqualityHelperExtensionProviderDescriptorRegistryListener.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/EqualityHelperExtensionProviderDescriptorRegistryListener.java
new file mode 100644
index 000000000..ececed2cd
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/EqualityHelperExtensionProviderDescriptorRegistryListener.java
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.rcp.internal.match;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProvider;
+import org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener;
+import org.eclipse.emf.compare.rcp.internal.EMFCompareRCPMessages;
+
+/**
+ * Listener for contributions to the match engine extension.
+ *
+ * @author <a href="mailto:stephane.thibaudeau@obeo.fr">Stephane Thibaudeau</a>
+ */
+public class EqualityHelperExtensionProviderDescriptorRegistryListener extends AbstractRegistryEventListener {
+
+ /** Attribute name for the equality helper extension provider implementation. */
+ public static final String ATT_CLASS = "class"; //$NON-NLS-1$
+
+ /** TAG_EQUALITY_HELPER_EXTENSION_PROVIDER. */
+ private static final String TAG_EQUALITY_HELPER_EXTENSION_PROVIDER = "provider"; //$NON-NLS-1$
+
+ /** ATT_RANKING. */
+ private static final String ATT_RANKING = "ranking"; //$NON-NLS-1$
+
+ /** ATT_NS_URI. */
+ private static final String ATT_NS_URI = "nsURI"; //$NON-NLS-1$
+
+ /** The equality helper extension provider registry to which extension will be registered. */
+ private final EqualityHelperExtensionProvider.Descriptor.Registry equalityHelperExtensionProviderRegistry;
+
+ /**
+ * Creates a new registry listener with the given equality helper extension provider registry to which
+ * extension will be registered.
+ *
+ * @param pluginID
+ * The pluginID of the extension point to be monitored.
+ * @param extensionPointID
+ * The extension point ID to be monitored.
+ * @param log
+ * The log object to be used to log error and/or warning.
+ * @param registry
+ * the equality helper extension provider registry to which extension will be registered.
+ */
+ public EqualityHelperExtensionProviderDescriptorRegistryListener(String pluginID, String extensionPointID,
+ ILog log, EqualityHelperExtensionProvider.Descriptor.Registry registry) {
+ super(pluginID, extensionPointID, log);
+ this.equalityHelperExtensionProviderRegistry = registry;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean validateExtensionElement(IConfigurationElement element) {
+ final boolean ret;
+ if (TAG_EQUALITY_HELPER_EXTENSION_PROVIDER.equals(element.getName())) {
+ if (element.getAttribute(ATT_CLASS) == null) {
+ logMissingAttribute(element, ATT_CLASS);
+ ret = false;
+ } else if (element.getAttribute(ATT_RANKING) == null) {
+ logMissingAttribute(element, ATT_RANKING);
+ ret = false;
+ } else if (element.getAttribute(ATT_NS_URI) == null) {
+ logMissingAttribute(element, ATT_NS_URI);
+ ret = false;
+ } else if (element.getAttribute(ATT_RANKING) != null) {
+ String rankingStr = element.getAttribute(ATT_RANKING);
+ try {
+ Integer.parseInt(rankingStr);
+ } catch (NumberFormatException nfe) {
+ log(IStatus.ERROR, element,
+ EMFCompareRCPMessages.getString("malformed.extension.attribute", //$NON-NLS-1$
+ ATT_RANKING));
+ return false;
+ }
+ ret = true;
+ } else {
+ ret = true;
+ }
+ } else {
+ ret = false;
+ }
+ return ret;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean addedValid(IConfigurationElement element) {
+ String className = element.getAttribute(ATT_CLASS);
+ String nsURI = element.getAttribute(ATT_NS_URI);
+ int rank = Integer.parseInt(element.getAttribute(ATT_RANKING));
+ EqualityHelperExtensionProvider.Descriptor descriptor = new EqualityHelperExtensionProviderDescriptorRCPImpl(
+ element, rank, Pattern.compile(nsURI));
+ EqualityHelperExtensionProvider.Descriptor previous = equalityHelperExtensionProviderRegistry
+ .put(className, descriptor);
+ if (previous != null) {
+ log(IStatus.WARNING, element, EMFCompareRCPMessages.getString("duplicate.extension", //$NON-NLS-1$
+ equalityHelperExtensionProviderRegistry.getClass().getName()));
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean removedValid(IConfigurationElement element) {
+ equalityHelperExtensionProviderRegistry.remove(element.getAttribute(ATT_CLASS));
+ return true;
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/DefaultMatchEngine.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/DefaultMatchEngine.java
index 3aae2aeea..65f660d78 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/DefaultMatchEngine.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/DefaultMatchEngine.java
@@ -32,6 +32,8 @@ import org.eclipse.emf.compare.EMFCompareMessages;
import org.eclipse.emf.compare.MatchResource;
import org.eclipse.emf.compare.match.eobject.CachingDistance;
import org.eclipse.emf.compare.match.eobject.EditionDistance;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProvider;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProviderDescriptorRegistryImpl;
import org.eclipse.emf.compare.match.eobject.IEObjectMatcher;
import org.eclipse.emf.compare.match.eobject.IdentifierEObjectMatcher;
import org.eclipse.emf.compare.match.eobject.ProximityEObjectMatcher;
@@ -415,7 +417,8 @@ public class DefaultMatchEngine implements IMatchEngine {
* @return a new {@link DefaultMatchEngine} instance.
*/
public static IMatchEngine create(UseIdentifiers useIDs) {
- return create(useIDs, WeightProviderDescriptorRegistryImpl.createStandaloneInstance());
+ return create(useIDs, WeightProviderDescriptorRegistryImpl.createStandaloneInstance(),
+ EqualityHelperExtensionProviderDescriptorRegistryImpl.createStandaloneInstance(), null);
}
/**
@@ -430,7 +433,8 @@ public class DefaultMatchEngine implements IMatchEngine {
*/
public static IMatchEngine create(UseIdentifiers useIDs,
WeightProvider.Descriptor.Registry weightProviderRegistry) {
- return create(useIDs, weightProviderRegistry, null);
+ return create(useIDs, weightProviderRegistry,
+ EqualityHelperExtensionProviderDescriptorRegistryImpl.createStandaloneInstance(), null);
}
/**
@@ -448,9 +452,32 @@ public class DefaultMatchEngine implements IMatchEngine {
public static IMatchEngine create(UseIdentifiers useIDs,
WeightProvider.Descriptor.Registry weightProviderRegistry,
Collection<IResourceMatchingStrategy> strategies) {
+ return create(useIDs, weightProviderRegistry,
+ EqualityHelperExtensionProviderDescriptorRegistryImpl.createStandaloneInstance(), strategies);
+ }
+
+ /**
+ * Helper creator method that instantiate a {@link DefaultMatchEngine} that will use identifiers as
+ * specified by the given {@code useIDs} enumeration.
+ *
+ * @param useIDs
+ * the kinds of matcher to use.
+ * @param weightProviderRegistry
+ * the match engine needs a WeightProvider in case of this match engine do not use identifiers.
+ * @param equalityHelperExtensionProviderRegistry
+ * the match engine may need a Equality Helper Extension
+ * @param strategies
+ * the matching strategies you want to use for the match step.
+ * @return a new {@link DefaultMatchEngine} instance.
+ */
+ public static IMatchEngine create(UseIdentifiers useIDs,
+ WeightProvider.Descriptor.Registry weightProviderRegistry,
+ EqualityHelperExtensionProvider.Descriptor.Registry equalityHelperExtensionProviderRegistry,
+ Collection<IResourceMatchingStrategy> strategies) {
final IComparisonFactory comparisonFactory = new DefaultComparisonFactory(
new DefaultEqualityHelperFactory());
- final IEObjectMatcher eObjectMatcher = createDefaultEObjectMatcher(useIDs, weightProviderRegistry);
+ final IEObjectMatcher eObjectMatcher = createDefaultEObjectMatcher(useIDs, weightProviderRegistry,
+ equalityHelperExtensionProviderRegistry);
final IResourceMatcher resourceMatcher;
if (strategies == null || strategies.isEmpty()) {
@@ -474,7 +501,8 @@ public class DefaultMatchEngine implements IMatchEngine {
*/
public static IEObjectMatcher createDefaultEObjectMatcher(UseIdentifiers useIDs) {
return createDefaultEObjectMatcher(useIDs,
- WeightProviderDescriptorRegistryImpl.createStandaloneInstance());
+ WeightProviderDescriptorRegistryImpl.createStandaloneInstance(),
+ EqualityHelperExtensionProviderDescriptorRegistryImpl.createStandaloneInstance());
}
/**
@@ -489,8 +517,28 @@ public class DefaultMatchEngine implements IMatchEngine {
*/
public static IEObjectMatcher createDefaultEObjectMatcher(UseIdentifiers useIDs,
WeightProvider.Descriptor.Registry weightProviderRegistry) {
+ return createDefaultEObjectMatcher(useIDs, weightProviderRegistry,
+ EqualityHelperExtensionProviderDescriptorRegistryImpl.createStandaloneInstance());
+ }
+
+ /**
+ * Creates and configures an {@link IEObjectMatcher} with the strategy given by {@code useIDs}. The
+ * {@code cache} will be used to cache some expensive computation (should better a LoadingCache).
+ *
+ * @param useIDs
+ * which strategy the return IEObjectMatcher must follow.
+ * @param weightProviderRegistry
+ * the match engine needs a WeightProvider in case of this match engine do not use identifiers.
+ * @param equalityHelperExtensionProviderRegistry
+ * the match engine may need a Equality helper extension.
+ * @return a new IEObjectMatcher.
+ */
+ public static IEObjectMatcher createDefaultEObjectMatcher(UseIdentifiers useIDs,
+ WeightProvider.Descriptor.Registry weightProviderRegistry,
+ EqualityHelperExtensionProvider.Descriptor.Registry equalityHelperExtensionProviderRegistry) {
final IEObjectMatcher matcher;
- final EditionDistance editionDistance = new EditionDistance(weightProviderRegistry);
+ final EditionDistance editionDistance = new EditionDistance(weightProviderRegistry,
+ equalityHelperExtensionProviderRegistry);
final CachingDistance cachedDistance = new CachingDistance(editionDistance);
switch (useIDs) {
case NEVER:
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java
index 683cf4da6..cb3cf2290 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EditionDistance.java
@@ -95,23 +95,40 @@ public class EditionDistance implements DistanceFunction {
* {@link WeightProviderDescriptorRegistryImpl#createStandaloneInstance()}.
*/
public EditionDistance() {
- this(WeightProviderDescriptorRegistryImpl.createStandaloneInstance());
+ this(WeightProviderDescriptorRegistryImpl.createStandaloneInstance(),
+ EqualityHelperExtensionProviderDescriptorRegistryImpl.createStandaloneInstance());
}
/**
* Instantiate a new Edition Distance.
*
- * @param registry
+ * @param weightProviderRegistry
* The registry of weight providers to use in this Edition Distance.
*/
- public EditionDistance(WeightProvider.Descriptor.Registry registry) {
- weightProviderRegistry = registry;
+
+ public EditionDistance(WeightProvider.Descriptor.Registry weightProviderRegistry) {
+ this(weightProviderRegistry,
+ EqualityHelperExtensionProviderDescriptorRegistryImpl.createStandaloneInstance());
+ }
+
+ /**
+ * Instantiate a new Edition Distance.
+ *
+ * @param weightProviderRegistry
+ * The registry of weight providers to use in this Edition Distance.
+ * @param equalityHelperExtensionProviderRegistry
+ * The registry of equality helper extension providers to use in this Edition Distance.
+ */
+
+ public EditionDistance(WeightProvider.Descriptor.Registry weightProviderRegistry,
+ final EqualityHelperExtensionProvider.Descriptor.Registry equalityHelperExtensionProviderRegistry) {
+ this.weightProviderRegistry = weightProviderRegistry;
IEqualityHelperFactory fakeEqualityHelperFactory = new DefaultEqualityHelperFactory() {
@Override
public IEqualityHelper createEqualityHelper() {
final LoadingCache<EObject, URI> cache = EqualityHelper.createDefaultCache(getCacheBuilder());
- return new EqualityHelper(cache) {
+ return new EqualityHelper(cache, equalityHelperExtensionProviderRegistry) {
@Override
protected boolean matchingURIs(EObject object1, EObject object2) {
/*
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EqualityHelperExtensionProvider.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EqualityHelperExtensionProvider.java
new file mode 100644
index 000000000..106c43b0a
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EqualityHelperExtensionProvider.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.match.eobject;
+
+import java.util.Collection;
+import java.util.regex.Pattern;
+
+import org.eclipse.emf.compare.utils.IEqualityHelper;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+
+/**
+ * Compute specific matching rules.This is used by the EqualityHelper
+ *
+ * @author <a href="mailto:stephane.thibaudeau@obeo.fr">Stephane Thibaudeau</a>
+ */
+public interface EqualityHelperExtensionProvider {
+
+ /**
+ * Enumeration used to return the result of a specific matching
+ *
+ * @author <a href="mailto:stephane.thibaudeau@obeo.fr">Stephane Thibaudeau</a>
+ */
+ public enum SpecificMatch {
+ UNKNOWN, MATCH, UNMATCH
+ }
+
+ /**
+ * Test whether two objects match.
+ *
+ * @param object1
+ * @param object2
+ * @param equalityHelper
+ * Calling equality helper
+ * @return MATCH if the objects match, UNMATCH if they do not match, UNKNOWN if the provider does not know
+ * how to handle these objects
+ */
+ public SpecificMatch matchingEObjects(EObject object1, EObject object2, IEqualityHelper equalityHelper);
+
+ /**
+ * Wrapper describing the given equality helper extension provider.
+ *
+ * @author <a href="mailto:stephane.thibaudeau@obeo.fr">Stephane Thibaudeau</a>
+ */
+ public interface Descriptor {
+
+ /**
+ * Returns the wrapped equality helper extension provider.
+ *
+ * @return the wrapped equality helper extension provider
+ */
+ EqualityHelperExtensionProvider getEqualityHelperExtensionProvider();
+
+ /**
+ * Returns the ranking of this equality helper extension provider.
+ *
+ * @return The ranking.
+ */
+ int getRanking();
+
+ /**
+ * Returns the pattern of namespace URI on which this equality helper extension provider can be
+ * applied.
+ *
+ * @return The namespace URI pattern.
+ */
+ Pattern getNsURI();
+
+ /**
+ * Registry of equality helper extension provider descriptors.
+ *
+ * @author <a href="mailto:stephane.thibaudeau@obeo.fr">Stephane Thibaudeau</a>
+ */
+ public interface Registry {
+ /**
+ * Adds a equality helper extension provider to the registry.
+ *
+ * @param key
+ * key with which the specified descriptor is to be associated
+ * @param descriptor
+ * equality helper extension provider that is to be added to this registry.
+ * @return the previous descriptor associated with <tt>key</tt>, or <tt>null</tt> if there was no
+ * mapping for <tt>key</tt>. (A <tt>null</tt> return can also indicate that the map
+ * previously associated <tt>null</tt> with <tt>key</tt>, if the implementation supports
+ * <tt>null</tt> values.)
+ */
+ EqualityHelperExtensionProvider.Descriptor put(String key,
+ EqualityHelperExtensionProvider.Descriptor descriptor);
+
+ /**
+ * Removes all extensions from this registry.
+ *
+ * @noreference This method is not intended to be referenced by clients.
+ */
+ void clear();
+
+ /**
+ * This will return a copy of the registered equality helper extension providers list.
+ *
+ * @return A copy of the registered equality helper extension providers list.
+ */
+ Collection<EqualityHelperExtensionProvider.Descriptor> getDescriptors();
+
+ /**
+ * Removes a equality helper extension provider from this registry.
+ *
+ * @param key
+ * key of the equality helper extension provider descriptor that is to be removed from
+ * the registry.
+ * @return the previous value associated with <tt>key</tt>, or <tt>null</tt> if there was no
+ * mapping for <tt>key</tt>.
+ */
+ EqualityHelperExtensionProvider.Descriptor remove(String key);
+
+ /**
+ * Retrieve the highest ranking equality helper extension provider from a given
+ * <code>ePackage</code>.
+ *
+ * @param ePackage
+ * The given ePackage.
+ * @return The associated equality helper extension provider with the highest ranking.
+ */
+ EqualityHelperExtensionProvider getHighestRankingEqualityHelperExtensionProvider(EPackage ePackage);
+
+ /**
+ * Retrieve the equality helper extension providers from a given <code>ePackage</code>.
+ *
+ * @param ePackage
+ * The given ePackage.
+ * @return The associated equality helper extension providers if any.
+ */
+ Collection<EqualityHelperExtensionProvider> getEqualityHelperExtensionProviders(EPackage ePackage);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EqualityHelperExtensionProviderDescriptorRegistryImpl.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EqualityHelperExtensionProviderDescriptorRegistryImpl.java
new file mode 100644
index 000000000..1fb7518bb
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/eobject/EqualityHelperExtensionProviderDescriptorRegistryImpl.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * Copyright (c) 2018 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.match.eobject;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Maps;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.eclipse.emf.ecore.EPackage;
+
+/**
+ * This will contain all of the EMF Compare equality helper extension provider descriptors.
+ *
+ * @author <a href="mailto:stephane.thibaudeau@obeo.fr">Stephane Thibaudeau</a>
+ */
+public class EqualityHelperExtensionProviderDescriptorRegistryImpl implements EqualityHelperExtensionProvider.Descriptor.Registry {
+
+ /**
+ * Map of all known {@link EqualityHelperExtensionProvider.Descriptor}s.
+ */
+ private final Map<String, EqualityHelperExtensionProvider.Descriptor> equalityHelperExtensionProviderDescriptors;
+
+ /**
+ * Cache (NsURI <-> highest ranking equality helper extension provider) associating each NsURI to his
+ * highest ranking equality helper extension provider.
+ */
+ private final Map<String, EqualityHelperExtensionProvider> cache;
+
+ /**
+ * Creates a new extension registry.
+ */
+ public EqualityHelperExtensionProviderDescriptorRegistryImpl() {
+ equalityHelperExtensionProviderDescriptors = Maps.newHashMap();
+ cache = Maps.newHashMap();
+ }
+
+ /**
+ * Returns a default registry i.e. an empty one
+ *
+ * @return A default empty registry
+ */
+ public static EqualityHelperExtensionProvider.Descriptor.Registry createStandaloneInstance() {
+ final EqualityHelperExtensionProviderDescriptorRegistryImpl registry = new EqualityHelperExtensionProviderDescriptorRegistryImpl();
+ return registry;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EqualityHelperExtensionProvider.Descriptor put(String key,
+ EqualityHelperExtensionProvider.Descriptor equalityHelperExtensionProvider) {
+ cache.clear();
+ return equalityHelperExtensionProviderDescriptors.put(key, equalityHelperExtensionProvider);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void clear() {
+ equalityHelperExtensionProviderDescriptors.clear();
+ cache.clear();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImmutableList<EqualityHelperExtensionProvider.Descriptor> getDescriptors() {
+ return ImmutableList.copyOf(equalityHelperExtensionProviderDescriptors.values());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EqualityHelperExtensionProvider.Descriptor remove(String key) {
+ cache.clear();
+ return equalityHelperExtensionProviderDescriptors.remove(key);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public EqualityHelperExtensionProvider getHighestRankingEqualityHelperExtensionProvider(
+ EPackage ePackage) {
+ EqualityHelperExtensionProvider equalityHelperExtensionProvider = cache.get(ePackage.getNsURI());
+ if (equalityHelperExtensionProvider == null) {
+ EqualityHelperExtensionProvider.Descriptor highestRankingEqualityHelperExtensionProviderDescriptor = getHighestRankingEqualityHelperExtensionProviderDescriptor(
+ ePackage.getNsURI());
+ if (highestRankingEqualityHelperExtensionProviderDescriptor != null) {
+ equalityHelperExtensionProvider = highestRankingEqualityHelperExtensionProviderDescriptor
+ .getEqualityHelperExtensionProvider();
+ cache.put(ePackage.getNsURI(), equalityHelperExtensionProvider);
+ }
+ }
+ return equalityHelperExtensionProvider;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ImmutableList<EqualityHelperExtensionProvider> getEqualityHelperExtensionProviders(
+ EPackage ePackage) {
+ final ImmutableList.Builder<EqualityHelperExtensionProvider> equalityHelperExtensionProvidersBuilder = ImmutableList
+ .builder();
+ for (EqualityHelperExtensionProvider.Descriptor descriptor : getEqualityHelperExtensionProviderDescriptors(
+ ePackage)) {
+ equalityHelperExtensionProvidersBuilder.add(descriptor.getEqualityHelperExtensionProvider());
+ }
+ return equalityHelperExtensionProvidersBuilder.build();
+ }
+
+ /**
+ * Retrieve the equality helper extension providers descriptors from a given ePackage.
+ *
+ * @param ePackage
+ * the given ePackage.
+ * @return the equality helper extension providers descriptors from a given ePackage.
+ */
+ private ImmutableList<EqualityHelperExtensionProvider.Descriptor> getEqualityHelperExtensionProviderDescriptors(
+ EPackage ePackage) {
+ return getEqualityHelperExtensionProviderDescriptors(ePackage.getNsURI());
+ }
+
+ /**
+ * Retrieve the equality helper extension providers descriptors from a given nsURI.
+ *
+ * @param nsURI
+ * the given nsURI.
+ * @return the equality helper extension providers descriptors from a given nsURI.
+ */
+ private ImmutableList<EqualityHelperExtensionProvider.Descriptor> getEqualityHelperExtensionProviderDescriptors(
+ String nsURI) {
+ final ImmutableList.Builder<EqualityHelperExtensionProvider.Descriptor> equalityHelperExtensionProvidersBuilder = ImmutableList
+ .builder();
+ for (EqualityHelperExtensionProvider.Descriptor descriptor : getDescriptors()) {
+ Pattern nsURIPattern = descriptor.getNsURI();
+ if (nsURIPattern != null) {
+ if (nsURIPattern.matcher(nsURI).matches()) {
+ equalityHelperExtensionProvidersBuilder.add(descriptor);
+ }
+ }
+ }
+ return equalityHelperExtensionProvidersBuilder.build();
+ }
+
+ /**
+ * Returns the highest ranking equality helper extension provider descriptor associated to the given
+ * nsURI.
+ *
+ * @param nsURI
+ * the nsURI for which we want to get the highest ranking equality helper extension provider
+ * descriptor.
+ * @return the highest ranking equality helper extension provider descriptor associated to the given
+ * nsURI.
+ */
+ private EqualityHelperExtensionProvider.Descriptor getHighestRankingEqualityHelperExtensionProviderDescriptor(
+ String nsURI) {
+ EqualityHelperExtensionProvider.Descriptor ret = null;
+ Iterator<EqualityHelperExtensionProvider.Descriptor> descriptors = getEqualityHelperExtensionProviderDescriptors(
+ nsURI).iterator();
+ if (descriptors.hasNext()) {
+ EqualityHelperExtensionProvider.Descriptor highestRanking = descriptors.next();
+ while (descriptors.hasNext()) {
+ EqualityHelperExtensionProvider.Descriptor desc = descriptors.next();
+ if (desc.getRanking() > highestRanking.getRanking()) {
+ highestRanking = desc;
+ }
+ }
+ ret = highestRanking;
+ }
+ return ret;
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/impl/MatchEngineFactoryImpl.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/impl/MatchEngineFactoryImpl.java
index 158b25c20..e0ca149fd 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/impl/MatchEngineFactoryImpl.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/impl/MatchEngineFactoryImpl.java
@@ -15,6 +15,8 @@ import org.eclipse.emf.compare.match.DefaultEqualityHelperFactory;
import org.eclipse.emf.compare.match.DefaultMatchEngine;
import org.eclipse.emf.compare.match.IComparisonFactory;
import org.eclipse.emf.compare.match.IMatchEngine;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProvider;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProviderDescriptorRegistryImpl;
import org.eclipse.emf.compare.match.eobject.IEObjectMatcher;
import org.eclipse.emf.compare.match.eobject.WeightProvider;
import org.eclipse.emf.compare.match.eobject.WeightProviderDescriptorRegistryImpl;
@@ -38,12 +40,16 @@ public class MatchEngineFactoryImpl implements IMatchEngine.Factory {
/** A match engine needs a WeightProvider in case of this match engine do not use identifiers. */
private WeightProvider.Descriptor.Registry weightProviderRegistry;
+ /** A match engine may need a specific equality helper extension provider. */
+ private EqualityHelperExtensionProvider.Descriptor.Registry equalityHelperExtensionProviderRegistry;
+
/**
* Constructor that instantiate a {@link DefaultMatchEngine}. This match engine will use a the standalone
* weight provider registry {@link WeightProviderDescriptorRegistryImpl.createStandaloneInstance()}.
*/
public MatchEngineFactoryImpl() {
- this(UseIdentifiers.WHEN_AVAILABLE, WeightProviderDescriptorRegistryImpl.createStandaloneInstance());
+ this(UseIdentifiers.WHEN_AVAILABLE, WeightProviderDescriptorRegistryImpl.createStandaloneInstance(),
+ EqualityHelperExtensionProviderDescriptorRegistryImpl.createStandaloneInstance());
}
/**
@@ -55,7 +61,8 @@ public class MatchEngineFactoryImpl implements IMatchEngine.Factory {
* the kinds of matcher to use.
*/
public MatchEngineFactoryImpl(UseIdentifiers useIDs) {
- this(useIDs, WeightProviderDescriptorRegistryImpl.createStandaloneInstance());
+ this(useIDs, WeightProviderDescriptorRegistryImpl.createStandaloneInstance(),
+ EqualityHelperExtensionProviderDescriptorRegistryImpl.createStandaloneInstance());
}
/**
@@ -64,15 +71,35 @@ public class MatchEngineFactoryImpl implements IMatchEngine.Factory {
*
* @param useIDs
* the kinds of matcher to use.
- * @param registry
+ * @param weightProviderRegistry
* A match engine needs a WeightProvider in case of this match engine do not use identifiers.
*/
- public MatchEngineFactoryImpl(UseIdentifiers useIDs, WeightProvider.Descriptor.Registry registry) {
+ public MatchEngineFactoryImpl(UseIdentifiers useIDs,
+ WeightProvider.Descriptor.Registry weightProviderRegistry) {
+ this(useIDs, weightProviderRegistry,
+ EqualityHelperExtensionProviderDescriptorRegistryImpl.createStandaloneInstance());
+ }
+
+ /**
+ * Constructor that instantiate a {@link DefaultMatchEngine} that will use identifiers as specified by the
+ * given {@code useIDs} enumeration.
+ *
+ * @param useIDs
+ * the kinds of matcher to use.
+ * @param weightProviderRegistry
+ * A match engine needs a WeightProvider in case of this match engine do not use identifiers.
+ * @param equalityHelperExtensionProviderRegistry
+ * A match engine may need a Equality Helper Extension.
+ */
+ public MatchEngineFactoryImpl(UseIdentifiers useIDs,
+ WeightProvider.Descriptor.Registry weightProviderRegistry,
+ EqualityHelperExtensionProvider.Descriptor.Registry equalityHelperExtensionProviderRegistry) {
final IComparisonFactory comparisonFactory = new DefaultComparisonFactory(
new DefaultEqualityHelperFactory());
- weightProviderRegistry = registry;
+ this.weightProviderRegistry = weightProviderRegistry;
+ this.equalityHelperExtensionProviderRegistry = equalityHelperExtensionProviderRegistry;
final IEObjectMatcher matcher = DefaultMatchEngine.createDefaultEObjectMatcher(useIDs,
- weightProviderRegistry);
+ weightProviderRegistry, equalityHelperExtensionProviderRegistry);
matchEngine = new DefaultMatchEngine(matcher, comparisonFactory);
}
@@ -134,4 +161,15 @@ public class MatchEngineFactoryImpl implements IMatchEngine.Factory {
this.weightProviderRegistry = registry;
}
+ /**
+ * The match engine may need a Equality Helper Extension
+ *
+ * @param registry
+ * the registry to associate with the match engine.
+ */
+ public void setEqualityHelperExtensionProviderRegistry(
+ EqualityHelperExtensionProvider.Descriptor.Registry equalityHelperExtensionProviderRegistry) {
+ this.equalityHelperExtensionProviderRegistry = equalityHelperExtensionProviderRegistry;
+ }
+
}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EqualityHelper.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EqualityHelper.java
index 256875c3d..f814aebc6 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EqualityHelper.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EqualityHelper.java
@@ -28,6 +28,10 @@ import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.internal.spec.MatchSpec;
import org.eclipse.emf.compare.match.DefaultMatchEngine;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProvider;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProvider.Descriptor.Registry;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProvider.SpecificMatch;
+import org.eclipse.emf.compare.match.eobject.EqualityHelperExtensionProviderDescriptorRegistryImpl;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
@@ -49,6 +53,9 @@ public class EqualityHelper extends AdapterImpl implements IEqualityHelper {
/** The record of the most recently used {@link #matchingEObjects(EObject, EObject) match}. */
private MatchSpec eObjectMatch;
+ /** Registry of equality helper extension computations provider. */
+ private EqualityHelperExtensionProvider.Descriptor.Registry equalityHelperExtensionProviderRegistry = null;
+
/**
* Creates a new EqualityHelper.
*
@@ -71,6 +78,20 @@ public class EqualityHelper extends AdapterImpl implements IEqualityHelper {
}
/**
+ * Creates a new EqualityHelper with the given cache and registry
+ *
+ * @param uriCache
+ * the cache to be used for {@link EcoreUtil#getURI(EObject)} calls.
+ * @param equalityHelperExtensionProviderRegistry
+ * Registry ofequality helper extension provider
+ */
+ public EqualityHelper(LoadingCache<EObject, URI> uriCache,
+ EqualityHelperExtensionProvider.Descriptor.Registry equalityHelperExtensionProviderRegistry) {
+ this.uriCache = uriCache;
+ this.equalityHelperExtensionProviderRegistry = equalityHelperExtensionProviderRegistry;
+ }
+
+ /**
* {@inheritDoc}
*
* @see org.eclipse.emf.common.notify.impl.AdapterImpl#getTarget()
@@ -190,6 +211,37 @@ public class EqualityHelper extends AdapterImpl implements IEqualityHelper {
protected boolean matchingEObjects(EObject object1, EObject object2) {
final boolean matching;
MatchSpec match = (MatchSpec)getMatch(object1);
+
+ if (match != null) {
+ if (match.getLeft() == object2 || match.getRight() == object2 || match.getOrigin() == object2) {
+ return true;
+ }
+ }
+
+ // Call to specific matcher if one was provided
+ if (equalityHelperExtensionProviderRegistry != null && object1 != null && object2 != null) {
+ EqualityHelperExtensionProvider equalityHelperExtensionProvider = equalityHelperExtensionProviderRegistry
+ .getHighestRankingEqualityHelperExtensionProvider(object1.eClass().getEPackage());
+
+ if (equalityHelperExtensionProvider != null) {
+ SpecificMatch specificMatch = equalityHelperExtensionProvider.matchingEObjects(object1,
+ object2, this);
+ if (specificMatch != null) {
+ switch (specificMatch) {
+ case MATCH:
+ return true;
+ case UNMATCH:
+ return false;
+ case UNKNOWN:
+ // Fall through
+ default:
+ break;
+ }
+ }
+ }
+ }
+
+ // Match could be null if the value is out of the scope
if (match != null) {
eObjectMatch = match;
matching = match.matches(object2);

Back to the top