From 9a1182e29aa1014a0c5f94746dffbffe18ae6be3 Mon Sep 17 00:00:00 2001
From: dwagelaar
Date: Mon, 22 Apr 2013 23:01:03 +0200
Subject: Added fix + test code. 406128: ModelImpl.newElement() and
.deleteElement() do not update allInstances caches for supertypes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=406128
---
.../org/eclipse/m2m/atl/emftvm/impl/ModelImpl.java | 43 ++++++++++++++++++----
1 file changed, 35 insertions(+), 8 deletions(-)
(limited to 'plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse')
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/ModelImpl.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/ModelImpl.java
index 6411cd07..eaf13d2a 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/ModelImpl.java
+++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/ModelImpl.java
@@ -304,22 +304,35 @@ public class ModelImpl extends EObjectImpl implements Model {
* {@inheritDoc}
*
*/
- public EObject newElement(EClass type) {
+ public EObject newElement(final EClass type) {
final EObject instance = type.getEPackage().getEFactoryInstance().create(type);
getResource().getContents().add(instance);
assert instance.eResource() == getResource();
+ addElement(instance, type);
+ return instance;
+ }
+
+ /**
+ * Adds element
to the "allInstances" list for the given type and all its supertypes.
+ *
+ * @param element
+ * the element to add
+ * @param type
+ * the current type
+ */
+ private void addElement(final EObject element, final EClass type) {
if (allInstancesMap.containsKey(type)) {
- allInstancesMap.get(type).add(instance);
+ allInstancesMap.get(type).add(element);
+ }
+ for (EClass superType : type.getESuperTypes()) {
+ addElement(element, superType);
}
- return instance;
}
/**
- *
- * {@inheritDoc}
- *
+ * {@inheritDoc}
*/
- public void deleteElement(EObject element) {
+ public void deleteElement(final EObject element) {
assert getResource() == element.eResource();
final EList resContents = getResource().getContents();
EcoreUtil.delete(element);
@@ -328,10 +341,24 @@ public class ModelImpl extends EObjectImpl implements Model {
// adding children to a container removes them from their previous container
resContents.add(child);
}
- final EClass type = element.eClass();
+ deleteElement(element, element.eClass());
+ }
+
+ /**
+ * Deletes element
from the "allInstances" list for the given type and all its supertypes.
+ *
+ * @param element
+ * the element to delete
+ * @param type
+ * the current type
+ */
+ private void deleteElement(final EObject element, final EClass type) {
if (allInstancesMap.containsKey(type)) {
allInstancesMap.get(type).remove(element);
}
+ for (EClass superType : type.getESuperTypes()) {
+ deleteElement(element, superType);
+ }
}
/**
--
cgit v1.2.3