Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Goubet2014-06-10 07:57:45 +0000
committerStephane Begaudeau2014-06-10 08:51:21 +0000
commit5474a24ac12c44a695c0d8aea05f6d3e5a8a013b (patch)
tree9593a802c2311ea1d16032ee29f81020c3a034ce
parentbb3f71c87b3325c12fcc1f5e2c404a161736f639 (diff)
downloadorg.eclipse.acceleo-5474a24ac12c44a695c0d8aea05f6d3e5a8a013b.tar.gz
org.eclipse.acceleo-5474a24ac12c44a695c0d8aea05f6d3e5a8a013b.tar.xz
org.eclipse.acceleo-5474a24ac12c44a695c0d8aea05f6d3e5a8a013b.zip
[436843] Allow OclAny-typed iteration variables3.5.0RC4
-rw-r--r--plugins/org.eclipse.acceleo.engine/src/org/eclipse/acceleo/engine/internal/evaluation/AcceleoEvaluationVisitor.java55
1 files changed, 38 insertions, 17 deletions
diff --git a/plugins/org.eclipse.acceleo.engine/src/org/eclipse/acceleo/engine/internal/evaluation/AcceleoEvaluationVisitor.java b/plugins/org.eclipse.acceleo.engine/src/org/eclipse/acceleo/engine/internal/evaluation/AcceleoEvaluationVisitor.java
index f4c501307..4cef40bdb 100644
--- a/plugins/org.eclipse.acceleo.engine/src/org/eclipse/acceleo/engine/internal/evaluation/AcceleoEvaluationVisitor.java
+++ b/plugins/org.eclipse.acceleo.engine/src/org/eclipse/acceleo/engine/internal/evaluation/AcceleoEvaluationVisitor.java
@@ -477,25 +477,18 @@ public class AcceleoEvaluationVisitor<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS,
// null typed loop variables will be the same as "Object" typed
// We could have no loop variables. In such cases, "self" will do
// TODO implicit loop variables (self) are non standard. provide a way to deactivate
- if (loopVariable != null && loopVariable.getType() != null
- && !loopVariable.getType().isInstance(o)) {
- if (!iterationCCE) {
- int line = getLineOf(forBlock);
- String actualType = "null"; //$NON-NLS-1$
- if (o != null) {
- actualType = o.getClass().getName();
+ if (loopVariable != null && loopVariable.getType() != null) {
+ // class cast check on each iteration value
+ // [436843] "OclAny" is a wild card such as "Object" would be in java.
+ if (!loopVariable.getType().isInstance(o)
+ && loopVariable.getType() != getAcceleoEnvironment().getOCLStandardLibrary()
+ .getOclAny()) {
+ if (!iterationCCE) {
+ logIterationError(forBlock, loopVariable, o);
+ iterationCCE = true;
}
- final String expectedType = loopVariable.getType().getName();
- final String message = AcceleoEngineMessages.getString(
- "AcceleoEvaluationVisitor.IterationClassCast", Integer.valueOf(line), //$NON-NLS-1$
- ((Module)EcoreUtil.getRootContainer(forBlock)).getName(),
- forBlock.toString(), actualType, expectedType);
- final AcceleoEvaluationException exception = new AcceleoEvaluationException(message);
- exception.setStackTrace(getContext().createAcceleoStackTrace());
- AcceleoEnginePlugin.log(exception, false);
- iterationCCE = true;
+ continue;
}
- continue;
}
if (loopVariable != null) {
// Do not remove previous values of the loop variable if this is the first iteration.
@@ -557,6 +550,34 @@ public class AcceleoEvaluationVisitor<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS,
}
/**
+ * Logs erroneous typing errors as they occur during for loop evaluations. This will only be called once
+ * per for block even if multiple values have the wrong type in a single iteration.
+ *
+ * @param forBlock
+ * The for loop on which a class cast occurred.
+ * @param loopVariable
+ * The iteration variable of this for block.
+ * @param iterationValue
+ * Current value of the iteration.
+ */
+ private void logIterationError(ForBlock forBlock, Variable loopVariable, Object iterationValue) {
+ int line = getLineOf(forBlock);
+ String actualType = "null"; //$NON-NLS-1$
+ if (iterationValue != null) {
+ actualType = iterationValue.getClass().getName();
+ }
+ final String expectedType = loopVariable.getType().getName();
+ final String message = AcceleoEngineMessages.getString(
+ "AcceleoEvaluationVisitor.IterationClassCast", Integer.valueOf(line), //$NON-NLS-1$
+ ((Module)EcoreUtil.getRootContainer(forBlock)).getName(), forBlock.toString(), actualType,
+ expectedType);
+ final AcceleoEvaluationException exception = new AcceleoEvaluationException(message);
+ exception.setStackTrace(getContext().createAcceleoStackTrace());
+ AcceleoEnginePlugin.log(exception, false);
+
+ }
+
+ /**
* Handles the evaluation of an Acceleo {@link IfBlock}.
*
* @param ifBlock

Back to the top