Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordwagelaar2013-04-22 21:01:03 +0000
committerdwagelaar2013-04-22 21:01:03 +0000
commit9a1182e29aa1014a0c5f94746dffbffe18ae6be3 (patch)
treedc6b272037929aaf1b45f3586952a74dbc57f53a /plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse
parentb720bb36218f08b5bde5ea5bc220413426ad47f7 (diff)
downloadorg.eclipse.atl-9a1182e29aa1014a0c5f94746dffbffe18ae6be3.tar.gz
org.eclipse.atl-9a1182e29aa1014a0c5f94746dffbffe18ae6be3.tar.xz
org.eclipse.atl-9a1182e29aa1014a0c5f94746dffbffe18ae6be3.zip
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
Diffstat (limited to 'plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse')
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/impl/ModelImpl.java43
1 files changed, 35 insertions, 8 deletions
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}
* <!-- end-user-doc -->
*/
- 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 <code>element</code> 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;
}
/**
- * <!-- begin-user-doc. -->
- * {@inheritDoc}
- * <!-- end-user-doc -->
+ * <!-- begin-user-doc. --> {@inheritDoc} <!-- end-user-doc -->
*/
- public void deleteElement(EObject element) {
+ public void deleteElement(final EObject element) {
assert getResource() == element.eResource();
final EList<EObject> 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 <code>element</code> 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);
+ }
}
/**

Back to the top