Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDennis Wagelaar2016-08-19 10:08:08 -0400
committerDennis Wagelaar2016-08-19 10:08:17 -0400
commit7f4bff59785b140224ad037879dfd2ed05b7f296 (patch)
tree99a72f6109bab2585ba6d1c1ab89a60b81304ed4 /plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse
parent420327073fe40bbc473ef2c49e3da43f4ef2ca55 (diff)
downloadorg.eclipse.atl-7f4bff59785b140224ad037879dfd2ed05b7f296.tar.gz
org.eclipse.atl-7f4bff59785b140224ad037879dfd2ed05b7f296.tar.xz
org.eclipse.atl-7f4bff59785b140224ad037879dfd2ed05b7f296.zip
496434: Assigning a collection of collections to a many-valued property
results in a ClassCastException Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=496434
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/util/EMFTVMUtil.java29
1 files changed, 26 insertions, 3 deletions
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
index b17436a0..a624e43b 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
+++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/EMFTVMUtil.java
@@ -202,7 +202,9 @@ public final class EMFTVMUtil {
}
return eCls.getName();
} else if (type instanceof Class<?>) {
- return NATIVE + '!' + ((Class<?>) type).getName();
+ final Class<?> cls = (Class<?>) type;
+ final String nativeTypeName = NativeTypes.typeName(cls);
+ return cls.getName().equals(nativeTypeName) ? NATIVE + '!' + nativeTypeName : nativeTypeName;
} else {
return type.toString();
}
@@ -562,8 +564,8 @@ public final class EMFTVMUtil {
}
if (sf.isMany()) {
if (!(value instanceof Collection<?>)) {
- throw new IllegalArgumentException(String.format("Cannot assign %s to multi-valued field %s::%s", value, sf
- .getEContainingClass().getName(), sf.getName()));
+ throw new IllegalArgumentException(String.format("Cannot assign %s to multi-valued field %s::%s",
+ toPrettyString(value, env), sf.getEContainingClass().getName(), sf.getName()));
}
setMany(env, eo, sf, (Collection<?>) value);
} else {
@@ -772,10 +774,12 @@ public final class EMFTVMUtil {
if (index > -1) {
int currentIndex = index;
for (Object v : srcValues) {
+ checkValueTypeIsEObject(env, ref, v);
addRefValue(env, ref, eo, values, (EObject) v, currentIndex++, allowInterModelReferences);
}
} else {
for (Object v : srcValues) {
+ checkValueTypeIsEObject(env, ref, v);
addRefValue(env, ref, eo, values, (EObject) v, -1, allowInterModelReferences);
}
}
@@ -802,6 +806,24 @@ public final class EMFTVMUtil {
}
/**
+ * Checks that the value is an instance of {@link EObject}.
+ *
+ * @param env
+ * the current {@link ExecEnv}
+ * @param ref
+ * the {@link EReference} to assign to
+ * @param v
+ * the value to check
+ */
+ private static void checkValueTypeIsEObject(final ExecEnv env, final EReference ref, final Object v) {
+ if (!(v instanceof EObject)) {
+ throw new IllegalArgumentException(String.format(
+ "Cannot add/remove values of type %s to/from multi-valued field %s::%s",
+ getTypeName(env, v.getClass()), ref.getEContainingClass().getName(), ref.getName()));
+ }
+ }
+
+ /**
* Removes the <code>value</code> from <code>eo.sf</code>. Assumes <code>sf</code> has a multiplicity &gt; 1.
*
* @param env
@@ -843,6 +865,7 @@ public final class EMFTVMUtil {
final EReference ref = (EReference) sf;
final Collection<?> srcValues = ref.isContainment() ? new ArrayList<Object>(value) : value;
for (Object v : srcValues) {
+ checkValueTypeIsEObject(env, ref, v);
removeRefValue(ref, eo, values, (EObject) v);
}
} else {

Back to the top