public boolean visit(EnhancedForStatement node) {
if (!isActive()) {
return false;
}
push(new NoOp(fCounter));
ITypeBinding typeBinding = resolveTypeBinding(node.getExpression());
if (typeBinding == null) {
return false;
}
Type paramType = node.getParameter().getType();
ITypeBinding paramBinding = resolveTypeBinding(paramType);
if (paramBinding == null) {
return false;
}
String typeSignature = getTypeSignature(paramBinding);
int paramTypeId = getTypeId(paramType);
boolean isParamPrimitiveType = paramTypeId != Instruction.T_Object
&& paramTypeId != Instruction.T_String;
String paramIdentifier = node.getParameter().getName().getIdentifier();
if (typeBinding.isArray()) {
// the expression returns an array
int idIndex = fUniqueIdIndex++;
String arrayIdentifier = "#a" + idIndex; //$NON-NLS-1$
String varIdentifier = "#i" + idIndex; //$NON-NLS-1$
push(new LocalVariableCreation(arrayIdentifier, typeSignature, 1,
isParamPrimitiveType, true, fCounter));
node.getExpression().accept(this);
storeInstruction();
push(new LocalVariableCreation(varIdentifier,
"I", 0, true, true, fCounter)); //$NON-NLS-1$
push(new PushInt(0));
storeInstruction();
storeInstruction();
push(new LocalVariableCreation(paramIdentifier, typeSignature, 0,
isParamPrimitiveType, false, fCounter));
storeInstruction();
push(new LessOperator(Instruction.T_int, Instruction.T_int,
fCounter));
push(new PushLocalVariable(varIdentifier));
storeInstruction();
push(new PushArrayLength(fCounter));
push(new PushLocalVariable(arrayIdentifier));
storeInstruction();
storeInstruction();
storeInstruction();
// conditional jump will be added here
push(new NoOp(fCounter));
push(new AssignmentOperator(paramTypeId, paramTypeId, fCounter));
push(new PushLocalVariable(paramIdentifier));
storeInstruction();
push(new org.eclipse.jdt.internal.debug.eval.ast.instructions.ArrayAccess(
fCounter));
push(new PushLocalVariable(arrayIdentifier));
storeInstruction();
push(new PostfixPlusPlusOperator(Instruction.T_int, fCounter));
push(new PushLocalVariable(varIdentifier));
storeInstruction();
storeInstruction();
storeInstruction();
if (checkAutoBoxing(typeBinding.getElementType(), paramBinding)) {
storeInstruction();
}
storeInstruction();
addPopInstruction();
node.getBody().accept(this);
storeInstruction();
// jump will be added here
} else {
// the expression returns a collection
String iteratorIdentifier = "#i" + fUniqueIdIndex++; //$NON-NLS-1$
push(new LocalVariableCreation(iteratorIdentifier,
"Ljava/util/Iterator;", 0, false, true, fCounter)); //$NON-NLS-1$
push(new SendMessage(
"iterator", "()Ljava/util/Iterator;", 0, null, fCounter)); //$NON-NLS-1$//$NON-NLS-2$
node.getExpression().accept(this);
storeInstruction();
storeInstruction();
push(new LocalVariableCreation(paramIdentifier, typeSignature, 0,
isParamPrimitiveType, false, fCounter));
storeInstruction();
push(new SendMessage("hasNext", "()Z", 0, null, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$
push(new PushLocalVariable(iteratorIdentifier));
storeInstruction();
storeInstruction();
// conditional jump will be added here
push(new NoOp(fCounter));
push(new AssignmentOperator(paramTypeId, paramTypeId, fCounter));
push(new PushLocalVariable(paramIdentifier));
storeInstruction();
push(new SendMessage(
"next", "()Ljava/lang/Object;", 0, null, fCounter)); //$NON-NLS-1$ //$NON-NLS-2$