makeIndexType(),
lengthExpr));
}
// int i = 0;
JCStatement iVar = makeVar(indexName,
makeIndexType(),
makeIndexInit());
// i < length;
JCExpression iCond = makeCondition();
// i++
JCExpression iIncr = makeIncrement(stepName);
Tree.ControlClause prevControlClause = currentForClause;
currentForClause = stmt.getForClause();
List<JCStatement> transformedBlock = transformBlock(getBlock());
currentForClause = prevControlClause;
// FOO element = java.lang.reflect.Array.get(array, i);
JCExpression elementGet = makeIndexedAccess();
Tree.ForIterator forIterator = getForIterator();
if (forIterator instanceof Tree.ValueIterator) {
String varName = Naming.getVariableName(((Tree.ValueIterator)forIterator).getVariable());
JCStatement variable = makeVar(FINAL,
varName,
makeJavaType(elementType),
elementGet);
// Prepend to the block
transformedBlock = transformedBlock.prepend(variable);
} else if (forIterator instanceof Tree.KeyValueIterator) {
SyntheticName entryName = naming.alias("entry");
JCStatement entryVariable = makeVar(FINAL, entryName,
makeJavaType(typeFact().getEntryType(typeFact().getAnythingDeclaration().getType(), typeFact().getAnythingDeclaration().getType()), JT_RAW),
elementGet);
ProducedType entryType = elementType.getSupertype(typeFact().getEntryDeclaration());
ProducedType keyType = entryType.getTypeArgumentList().get(0);
String keyName = Naming.getVariableName(((Tree.KeyValueIterator)forIterator).getKeyVariable());
JCStatement keyVariable = makeVar(FINAL,
keyName,
makeJavaType(keyType),
expressionGen().applyErasureAndBoxing(
make().Apply(null, naming.makeQualIdent(entryName.makeIdent(), "getKey"), List.<JCExpression>nil()),
typeFact().getAnythingDeclaration().getType(), true, BoxingStrategy.UNBOXED, keyType));
ProducedType valueType = entryType.getTypeArgumentList().get(1);
String valueName = Naming.getVariableName(((Tree.KeyValueIterator)forIterator).getValueVariable());
JCStatement valueVariable = makeVar(FINAL,
valueName,
makeJavaType(valueType),
expressionGen().applyErasureAndBoxing(
make().Apply(null, naming.makeQualIdent(entryName.makeIdent(), "getItem"), List.<JCExpression>nil()),
typeFact().getAnythingDeclaration().getType(), true, BoxingStrategy.UNBOXED, valueType));
// Prepend to the block
transformedBlock = transformedBlock.prepend(valueVariable);
transformedBlock = transformedBlock.prepend(keyVariable);
transformedBlock = transformedBlock.prepend(entryVariable);
}
JCStatement block = make().Block(0, transformedBlock);
result.add(make().Labelled(this.label, make().ForLoop(
List.<JCStatement>of(iVar),
iCond,
List.<JCExpressionStatement>of(make().Exec(iIncr)),
block)));