Fix a potential ClassCastException (AnyType is not a subclass of Eclass)
so multiple templates with OclAny as the type of one of their parameter
would create a problem.
diff --git a/plugins/org.eclipse.acceleo.engine/src/org/eclipse/acceleo/engine/internal/environment/AcceleoEvaluationEnvironment.java b/plugins/org.eclipse.acceleo.engine/src/org/eclipse/acceleo/engine/internal/environment/AcceleoEvaluationEnvironment.java
index a514bac..b5c7d22 100644
--- a/plugins/org.eclipse.acceleo.engine/src/org/eclipse/acceleo/engine/internal/environment/AcceleoEvaluationEnvironment.java
+++ b/plugins/org.eclipse.acceleo.engine/src/org/eclipse/acceleo/engine/internal/environment/AcceleoEvaluationEnvironment.java
@@ -674,8 +674,7 @@
if (argumentType == NULL_ARGUMENT) {
isApplicable = true;
} else if (expectedType instanceof EClass && argumentType instanceof EClass) {
- isApplicable = expectedType == argumentType
- || isSubTypeOf((EClass)expectedType, (EClass)argumentType);
+ isApplicable = expectedType == argumentType || isSubTypeOf(expectedType, argumentType);
} else if (expectedType instanceof Class<?> && argumentType instanceof Class<?>) {
isApplicable = ((Class<?>)expectedType).isAssignableFrom((Class<?>)argumentType);
} else if (expectedType instanceof EDataType && argumentType instanceof Class<?>) {
@@ -699,13 +698,21 @@
* @return <code>true</code> if <code>eClass</code> is a sub-type of <code>superType</code>,
* <code>false</code> otherwise.
*/
- private boolean isSubTypeOf(EClass superType, EClass eClass) {
- for (final EClass candidate : eClass.getEAllSuperTypes()) {
- if (candidate == superType) {
- return true;
+ private boolean isSubTypeOf(Object superType, Object eClass) {
+ // if both types are EClass(es) then do the usual stuff
+ boolean result = false;
+ if (superType instanceof EClass && eClass instanceof EClass) {
+ for (final EClass candidate : ((EClass)eClass).getEAllSuperTypes()) {
+ if (candidate == superType) {
+ result = true;
+ break;
+ }
}
+ } else if (superType instanceof AnyType) {
+ result = true;
}
- return false;
+
+ return result;
}
/**
@@ -912,7 +919,7 @@
continue;
}
if (actualArgumentType instanceof EObject) {
- if (isSubTypeOf((EClass)template1Type, (EClass)template2Type)) {
+ if (isSubTypeOf(template1Type, template2Type)) {
template2SpecificArgumentCount++;
} else {
template1SpecificArgumentCount++;