Skip to content
Snippets Groups Projects
Commit 139edf9f authored by dgelessus's avatar dgelessus
Browse files

Match only based on Event-B names and qualified references, not EMF IDs

We don't care about generic EMF objects, only about EventBElement
(right..?). This noticeably improves performance when saving (almost
twice as fast for a medium-sized machine with 30 invariants).
parent 60758b18
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<description> <description>
A text editor for the Rodin platform to edit Event-B models A text editor for the Rodin platform to edit Event-B models
--- Release History --- --- Release History ---
3.6.0 - Improved performance when saving larger files.
3.5.1 - Fix "Empty label" error when adding a variant to a machine 3.5.1 - Fix "Empty label" error when adding a variant to a machine
3.5.0 - Compatibility with EventB-EMF 7.0.0 - fixes CamilleX dependency conflict. Fixed OOM error when top-level end keyword is missing. 3.5.0 - Compatibility with EventB-EMF 7.0.0 - fixes CamilleX dependency conflict. Fixed OOM error when top-level end keyword is missing.
3.4.1 - Internal updates to the build process - no visible changes. 3.4.1 - Internal updates to the build process - no visible changes.
......
...@@ -12,10 +12,7 @@ import org.eclipse.emf.compare.Comparison; ...@@ -12,10 +12,7 @@ import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Match; import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.match.eobject.IEObjectMatcher; import org.eclipse.emf.compare.match.eobject.IEObjectMatcher;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject; import org.eventb.emf.core.EventBElement;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.XMIResource;
import org.eventb.emf.core.EventBNamed; import org.eventb.emf.core.EventBNamed;
import org.eventb.emf.core.machine.Variant; import org.eventb.emf.core.machine.Variant;
...@@ -76,7 +73,8 @@ public class EventBEObjectMatcher implements IEObjectMatcher { ...@@ -76,7 +73,8 @@ public class EventBEObjectMatcher implements IEObjectMatcher {
return false; return false;
} }
/* /*
* Only one variant may exist in a model, so two variants are a match * Only one variant may exist in a model, so two variants are a match.
* TODO Rodin now allows multiple variants per model, but Camille doesn't support that properly yet...
*/ */
if (left instanceof Variant) { if (left instanceof Variant) {
assert candidate instanceof Variant; assert candidate instanceof Variant;
...@@ -84,51 +82,33 @@ public class EventBEObjectMatcher implements IEObjectMatcher { ...@@ -84,51 +82,33 @@ public class EventBEObjectMatcher implements IEObjectMatcher {
} }
/* /*
* Improve matching for event b named objects with same name * Match named elements based on only their name and not their fully qualified reference,
* so that renaming a component doesn't cause mismatches for all the elements in it.
*/ */
if (left instanceof EventBNamed) { if (left instanceof EventBNamed) {
assert candidate instanceof EventBNamed; assert candidate instanceof EventBNamed;
EventBNamed l = (EventBNamed) left; EventBNamed l = (EventBNamed) left;
EventBNamed c = (EventBNamed) candidate; EventBNamed c = (EventBNamed) candidate;
if (l.getName().equals(c.getName())) { return l.getName().equals(c.getName());
return true;
}
} }
/* /*
* rely on emf identifiers after the event-b specific code * Match unnamed objects based on their fully qualified reference,
* which includes a unique ID generated by Event-B EMF.
*/ */
String idLeft = getEMFId(left); if (left instanceof EventBElement) {
if (idLeft == null) { assert candidate instanceof EventBElement;
return false; EventBElement l = (EventBElement)left;
EventBElement c = (EventBElement)candidate;
return l.getReference().equals(c.getReference());
} }
String idCandidate = getEMFId(candidate);
return idLeft.equals(idCandidate); return false;
} }
private static boolean areSameType(final EObject obj1, final EObject obj2) { private static boolean areSameType(final EObject obj1, final EObject obj2) {
return obj1 != null && obj2 != null return obj1 != null && obj2 != null
&& obj1.eClass().equals(obj2.eClass()); && obj1.eClass().equals(obj2.eClass());
} }
private static String getEMFId(EObject eObject) {
final String identifier;
if (eObject.eIsProxy()) {
identifier = ((InternalEObject) eObject).eProxyURI().fragment();
} else {
String functionalId = EcoreUtil.getID(eObject);
if (functionalId != null) {
identifier = functionalId;
} else {
final Resource eObjectResource = eObject.eResource();
if (eObjectResource instanceof XMIResource) {
identifier = ((XMIResource) eObjectResource).getID(eObject);
} else {
identifier = null;
}
}
}
return identifier;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment