@Override public void visitLocal(EclipseNode localNode, LocalDeclaration local) { if (!EclipseHandlerUtil.typeMatches(val.class, localNode, local.type)) return; boolean variableOfForEach = false; if (localNode.directUp().get() instanceof ForeachStatement) { ForeachStatement fs = (ForeachStatement) localNode.directUp().get(); variableOfForEach = fs.elementVariable == local; } if (local.initialization == null && !variableOfForEach) { localNode.addError("'val' on a local variable requires an initializer expression"); return; } if (local.initialization instanceof ArrayInitializer) { localNode.addError("'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })"); return; } if (localNode.directUp().get() instanceof ForStatement) { localNode.addError("'val' is not allowed in old-style for loops"); return; } }
@Override public void visitLocal(EclipseNode localNode, LocalDeclaration local) { if (!EclipseHandlerUtil.typeMatches(val.class, localNode, local.type)) return; handleFlagUsage(localNode, ConfigurationKeys.VAL_FLAG_USAGE, "val"); boolean variableOfForEach = false; if (localNode.directUp().get() instanceof ForeachStatement) { ForeachStatement fs = (ForeachStatement) localNode.directUp().get(); variableOfForEach = fs.elementVariable == local; } if (local.initialization == null && !variableOfForEach) { localNode.addError("'val' on a local variable requires an initializer expression"); return; } if (local.initialization instanceof ArrayInitializer) { localNode.addError("'val' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })"); return; } if (localNode.directUp().get() instanceof ForStatement) { localNode.addError("'val' is not allowed in old-style for loops"); return; } if (local.initialization != null && local.initialization.getClass().getName().equals("org.eclipse.jdt.internal.compiler.ast.LambdaExpression")) { localNode.addError("'val' is not allowed with lambda expressions."); } }
@Override public void endVisit(ForStatement x, BlockScope scope) { try { SourceInfo info = makeSourceInfo(x); JStatement action = pop(x.action); List<JExpressionStatement> increments = pop(x.increments); JExpression condition = pop(x.condition); List<JStatement> initializations = pop(x.initializations); push(new JForStatement(info, initializations, condition, increments, action)); } catch (Throwable e) { throw translateException(x, e); } }
@Override public boolean visit(ForStatement x, BlockScope scope) { // SEE NOTE ON JDT FORCED OPTIMIZATIONS if (isOptimizedFalse(x.condition)) { x.action = null; } return true; }
@Override public boolean visit(ForStatement node, BlockScope scope) { fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); }
protected void consumeStatementFor() { // ForStatement ::= 'for' '(' ForInitopt ';' Expressionopt ';' ForUpdateopt ')' Statement // ForStatementNoShortIf ::= 'for' '(' ForInitopt ';' Expressionopt ';' ForUpdateopt ')' StatementNoShortIf int length; Expression cond = null; Statement[] inits, updates; boolean scope = true; //statements this.astLengthPtr--; Statement statement = (Statement) this.astStack[this.astPtr--]; //updates are on the expresion stack if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) == 0) { updates = null; } else { this.expressionPtr -= length; System.arraycopy( this.expressionStack, this.expressionPtr + 1, updates = new Statement[length], 0, length); } if (this.expressionLengthStack[this.expressionLengthPtr--] != 0) cond = this.expressionStack[this.expressionPtr--]; //inits may be on two different stacks if ((length = this.astLengthStack[this.astLengthPtr--]) == 0) { inits = null; scope = false; } else { if (length == -1) { //on this.expressionStack scope = false; length = this.expressionLengthStack[this.expressionLengthPtr--]; this.expressionPtr -= length; System.arraycopy( this.expressionStack, this.expressionPtr + 1, inits = new Statement[length], 0, length); } else { //on this.astStack this.astPtr -= length; System.arraycopy( this.astStack, this.astPtr + 1, inits = new Statement[length], 0, length); } } pushOnAstStack( new ForStatement( inits, cond, updates, statement, scope, this.intStack[this.intPtr--], this.endStatementPosition)); }
@Override public boolean visit(ForStatement node, BlockScope scope) { setGeneratedBy(node, source); applyOffsetASTNode(node); return super.visit(node, scope); }