final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == PARAMETER_PROPERTY) { if (get) { return getParameter(); } else { setParameter((SingleVariableDeclaration) child); return null; } } if (property == EXPRESSION_PROPERTY) { if (get) { return getExpression(); } else { setExpression((Expression) child); return null; } } if (property == BODY_PROPERTY) { if (get) { return getBody(); } else { setBody((Statement) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == PARAMETER_PROPERTY) { if (get) { return getParameter(); } else { setParameter((SingleVariableDeclaration) child); return null; } } if (property == EXPRESSION_PROPERTY) { if (get) { return getExpression(); } else { setExpression((Expression) child); return null; } } if (property == BODY_PROPERTY) { if (get) { return getBody(); } else { setBody((Statement) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
final ASTNode internalGetSetChildProperty(ChildPropertyDescriptor property, boolean get, ASTNode child) { if (property == PARAMETER_PROPERTY) { if (get) { return getParameter(); } else { setParameter((SingleVariableDeclaration) child); return null; } } if (property == EXPRESSION_PROPERTY) { if (get) { return getExpression(); } else { setExpression((Expression) child); return null; } } if (property == BODY_PROPERTY) { if (get) { return getBody(); } else { setBody((Statement) child); return null; } } // allow default implementation to flag the error return super.internalGetSetChildProperty(property, get, child); }
public Statement convert(ForeachStatement statement) { switch(this.ast.apiLevel) { case AST.JLS2_INTERNAL : return createFakeEmptyStatement(statement); default : EnhancedForStatement enhancedForStatement = new EnhancedForStatement(this.ast); enhancedForStatement.setParameter(convertToSingleVariableDeclaration(statement.elementVariable)); org.eclipse.jdt.internal.compiler.ast.Expression collection = statement.collection; if (collection == null) return null; enhancedForStatement.setExpression(convert(collection)); final Statement action = convert(statement.action); if (action == null) return null; enhancedForStatement.setBody(action); int start = statement.sourceStart; int end = statement.sourceEnd; enhancedForStatement.setSourceRange(start, end - start + 1); return enhancedForStatement; } }
/** * Append a Java 5 "enhanced" 'for' statement. * * @param name iteration variable name * @param type iteration variable type * @param expr iteration source expression * @param block statement body block */ public void addSugaredForStatement(String name, String type, ExpressionBuilderBase expr, BlockBuilder block) { EnhancedForStatement stmt = m_ast.newEnhancedForStatement(); stmt.setExpression(expr.getExpression()); SingleVariableDeclaration decl = m_ast.newSingleVariableDeclaration(); decl.setName(m_ast.newSimpleName(name)); decl.setType(m_source.createType(type)); stmt.setParameter(decl); stmt.setBody(block.getStatement()); m_block.statements().add(stmt); }
public Statement convert(ForeachStatement statement) { switch(this.ast.apiLevel) { case AST.JLS2_INTERNAL : return createFakeEmptyStatement(statement); default : EnhancedForStatement enhancedForStatement = new EnhancedForStatement(this.ast); enhancedForStatement.setParameter(convertToSingleVariableDeclaration(statement.elementVariable)); org.eclipse.jdt.internal.compiler.ast.Expression collection = statement.collection; if (collection == null) return null; enhancedForStatement.setExpression(convert(collection)); final Statement action = convert(statement.action); if (action == null) return null; enhancedForStatement.setBody(action); int start = statement.sourceStart; int end = statement.sourceEnd; enhancedForStatement.setSourceRange(start, end - start + 1); return enhancedForStatement; } }
public Statement convert(ForeachStatement statement) { switch(this.ast.apiLevel) { case AST.JLS2_INTERNAL : return createFakeEmptyStatement(statement); default : EnhancedForStatement enhancedForStatement = new EnhancedForStatement(this.ast); enhancedForStatement.setParameter(convertToSingleVariableDeclaration(statement.elementVariable)); org.eclipse.jdt.internal.compiler.ast.Expression collection = statement.collection; if (collection == null) return null; enhancedForStatement.setExpression(convert(collection)); final Statement action = convert(statement.action); if (action == null) return null; enhancedForStatement.setBody(action); int start = statement.sourceStart; int end = statement.sourceEnd; enhancedForStatement.setSourceRange(start, end - start + 1); return enhancedForStatement; } }
public Statement convert(ForeachStatement statement) { switch(this.ast.apiLevel) { case AST.JLS2_INTERNAL : return createFakeEmptyStatement(statement); default : EnhancedForStatement enhancedForStatement = new EnhancedForStatement(this.ast); enhancedForStatement.setParameter(convertToSingleVariableDeclaration(statement.elementVariable)); org.eclipse.jdt.internal.compiler.ast.Expression collection = statement.collection; if (collection == null) return null; enhancedForStatement.setExpression(convert(collection)); final Statement action = convert(statement.action); if (action == null) return null; enhancedForStatement.setBody(action); int start = statement.sourceStart; int end = statement.sourceEnd; enhancedForStatement.setSourceRange(start, end - start + 1); return enhancedForStatement; } }
public Statement convert(ForeachStatement statement) { switch(this.ast.apiLevel) { case AST.JLS2_INTERNAL : return createFakeEmptyStatement(statement); default : EnhancedForStatement enhancedForStatement = new EnhancedForStatement(this.ast); enhancedForStatement.setParameter(convertToSingleVariableDeclaration(statement.elementVariable)); org.eclipse.jdt.internal.compiler.ast.Expression collection = statement.collection; if (collection == null) return null; enhancedForStatement.setExpression(convert(collection)); final Statement action = convert(statement.action); if (action == null) return null; enhancedForStatement.setBody(action); int start = statement.sourceStart; int end = statement.sourceEnd; enhancedForStatement.setSourceRange(start, end - start + 1); return enhancedForStatement; } }
public Statement convert(ForeachStatement statement) { switch(this.ast.apiLevel) { case AST.JLS2_INTERNAL : return createFakeEmptyStatement(statement); case AST.JLS3 : EnhancedForStatement enhancedForStatement = new EnhancedForStatement(this.ast); enhancedForStatement.setParameter(convertToSingleVariableDeclaration(statement.elementVariable)); org.eclipse.jdt.internal.compiler.ast.Expression collection = statement.collection; if (collection == null) return null; enhancedForStatement.setExpression(convert(collection)); final Statement action = convert(statement.action); if (action == null) return null; enhancedForStatement.setBody(action); int start = statement.sourceStart; int end = statement.sourceEnd; enhancedForStatement.setSourceRange(start, end - start + 1); return enhancedForStatement; default: return createFakeEmptyStatement(statement); } }
@Override ASTNode clone0(AST target) { EnhancedForStatement result = new EnhancedForStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); result.setParameter((SingleVariableDeclaration) getParameter().clone(target)); result.setExpression((Expression) getExpression().clone(target)); result.setBody( (Statement) ASTNode.copySubtree(target, getBody())); return result; }
ASTNode clone0(AST target) { EnhancedForStatement result = new EnhancedForStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); result.setParameter((SingleVariableDeclaration) getParameter().clone(target)); result.setExpression((Expression) getExpression().clone(target)); result.setBody( (Statement) ASTNode.copySubtree(target, getBody())); return result; }
ASTNode clone0(AST target) { EnhancedForStatement result = new EnhancedForStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); result.setParameter((SingleVariableDeclaration) getParameter().clone(target)); result.setExpression((Expression) getExpression().clone(target)); result.setBody( (Statement) ASTNode.copySubtree(target, getBody())); return result; }
ASTNode clone0(AST target) { EnhancedForStatement result = new EnhancedForStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); result.setParameter((SingleVariableDeclaration) getParameter().clone(target)); result.setExpression((Expression) getExpression().clone(target)); result.setBody( (Statement) ASTNode.copySubtree(target, getBody())); return result; }
ASTNode clone0(AST target) { EnhancedForStatement result = new EnhancedForStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); result.setParameter((SingleVariableDeclaration) getParameter().clone(target)); result.setExpression((Expression) getExpression().clone(target)); result.setBody( (Statement) ASTNode.copySubtree(target, getBody())); return result; }
ASTNode clone0(AST target) { EnhancedForStatement result = new EnhancedForStatement(target); result.setSourceRange(getStartPosition(), getLength()); result.copyLeadingComment(this); result.setParameter((SingleVariableDeclaration) getParameter().clone(target)); result.setExpression((Expression) getExpression().clone(target)); result.setBody( (Statement) ASTNode.copySubtree(target, getBody())); return result; }
/** * Helper to generate a <code>foreach</code> loop to iterate over an {@link Iterable}. * * @param ast the {@link AST} instance to rewrite the loop to * @return the complete {@link ASTRewrite} object */ private ASTRewrite generateForEachRewrite(AST ast) { EnhancedForStatement loopStatement= ast.newEnhancedForStatement(); ASTRewrite rewrite= ASTRewrite.create(ast); ITypeBinding loopOverType= extractType(ast); // generate name proposals and add them to the variable declaration SimpleName forDeclarationName= resolveLinkedVariableNameWithProposals(rewrite, loopOverType.getName(), null, true); SingleVariableDeclaration forLoopInitializer= ast.newSingleVariableDeclaration(); forLoopInitializer.setType(getImportRewrite().addImport(loopOverType, ast, new ContextSensitiveImportRewriteContext(fCurrentStatement, getImportRewrite()), TypeLocation.LOCAL_VARIABLE)); forLoopInitializer.setName(forDeclarationName); loopStatement.setParameter(forLoopInitializer); loopStatement.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression)); Block forLoopBody= ast.newBlock(); forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite)); loopStatement.setBody(forLoopBody); replace(loopStatement, rewrite); return rewrite; }
/** * Helper to generate a <code>foreach</code> loop to iterate over an {@link Iterable}. * * @param ast the {@link AST} instance to rewrite the loop to * @return the complete {@link ASTRewrite} object */ private ASTRewrite generateForEachRewrite(AST ast) { EnhancedForStatement loopStatement= ast.newEnhancedForStatement(); ASTRewrite rewrite= ASTRewrite.create(ast); ITypeBinding loopOverType= extractType(ast); // generate name proposals and add them to the variable declaration SimpleName forDeclarationName= resolveLinkedVariableNameWithProposals(rewrite, loopOverType.getName(), null, true); SingleVariableDeclaration forLoopInitializer= ast.newSingleVariableDeclaration(); forLoopInitializer.setType(getImportRewrite().addImport(loopOverType, ast, new ContextSensitiveImportRewriteContext(fCurrentStatement, getImportRewrite()))); forLoopInitializer.setName(forDeclarationName); loopStatement.setParameter(forLoopInitializer); loopStatement.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression)); Block forLoopBody= ast.newBlock(); forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite)); loopStatement.setBody(forLoopBody); replace(loopStatement, rewrite); return rewrite; }
@Override protected Statement convert(CompilationUnitRewrite cuRewrite, TextEditGroup group, LinkedProposalModel positionGroups) throws CoreException { ASTRewrite rewrite= cuRewrite.getASTRewrite(); ImportRewrite importRewrite= cuRewrite.getImportRewrite(); ForStatement forStatement= getForStatement(); IJavaProject javaProject= ((CompilationUnit)forStatement.getRoot()).getJavaElement().getJavaProject(); String[] proposals= getVariableNameProposals(fArrayAccess.resolveTypeBinding(), javaProject); String parameterName; if (fElementDeclaration != null) { parameterName= fElementDeclaration.getName().getIdentifier(); } else { parameterName= proposals[0]; } LinkedProposalPositionGroup pg= positionGroups.getPositionGroup(parameterName, true); if (fElementDeclaration != null) pg.addProposal(parameterName, null, 10); for (int i= 0; i < proposals.length; i++) { pg.addProposal(proposals[i], null, 10); } AST ast= forStatement.getAST(); EnhancedForStatement result= ast.newEnhancedForStatement(); SingleVariableDeclaration parameterDeclaration= createParameterDeclaration(parameterName, fElementDeclaration, fArrayAccess, forStatement, importRewrite, rewrite, group, pg, fMakeFinal); result.setParameter(parameterDeclaration); result.setExpression((Expression)rewrite.createCopyTarget(fArrayAccess)); convertBody(forStatement.getBody(), fIndexBinding, fArrayBinding, parameterName, rewrite, group, pg); result.setBody(getBody(cuRewrite, group, positionGroups)); positionGroups.setEndPosition(rewrite.track(result)); return result; }
result.setBody(getBody(cuRewrite, group, positionGroups));