本文整理汇总了Java中org.eclipse.jdt.core.dom.ForStatement.setBody方法的典型用法代码示例。如果您正苦于以下问题:Java ForStatement.setBody方法的具体用法?Java ForStatement.setBody怎么用?Java ForStatement.setBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.ForStatement
的用法示例。
在下文中一共展示了ForStatement.setBody方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateIteratorBasedForRewrite
import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
* Helper to generate an iterator based <code>for</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 generateIteratorBasedForRewrite(AST ast) {
ASTRewrite rewrite = ASTRewrite.create(ast);
ForStatement loopStatement = ast.newForStatement();
ITypeBinding loopOverType = extractElementType(ast);
SimpleName loopVariableName =
resolveLinkedVariableNameWithProposals(rewrite, "iterator", null, true); // $NON-NLS-1$
loopStatement.initializers().add(getIteratorBasedForInitializer(rewrite, loopVariableName));
MethodInvocation loopExpression = ast.newMethodInvocation();
loopExpression.setName(ast.newSimpleName("hasNext")); // $NON-NLS-1$
SimpleName expressionName = ast.newSimpleName(loopVariableName.getIdentifier());
addLinkedPosition(
rewrite.track(expressionName), LinkedPositionGroup.NO_STOP, expressionName.getIdentifier());
loopExpression.setExpression(expressionName);
loopStatement.setExpression(loopExpression);
Block forLoopBody = ast.newBlock();
Assignment assignResolvedVariable =
getIteratorBasedForBodyAssignment(rewrite, loopOverType, loopVariableName);
forLoopBody.statements().add(ast.newExpressionStatement(assignResolvedVariable));
forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
loopStatement.setBody(forLoopBody);
rewrite.replace(fCurrentNode, loopStatement, null);
return rewrite;
}
示例2: generateIndexBasedForRewrite
import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
* Helper to generate an index based <code>for</code> loop to iterate over a {@link List}
* implementation.
*
* @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
* @return an applicable {@link ASTRewrite} instance
*/
private ASTRewrite generateIndexBasedForRewrite(AST ast) {
ASTRewrite rewrite = ASTRewrite.create(ast);
ForStatement loopStatement = ast.newForStatement();
SimpleName loopVariableName =
resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); // $NON-NLS-1$
loopStatement.initializers().add(getForInitializer(ast, loopVariableName));
MethodInvocation listSizeExpression = ast.newMethodInvocation();
listSizeExpression.setName(ast.newSimpleName("size")); // $NON-NLS-1$
Expression listExpression = (Expression) rewrite.createCopyTarget(fCurrentExpression);
listSizeExpression.setExpression(listExpression);
loopStatement.setExpression(
getLinkedInfixExpression(
rewrite,
loopVariableName.getIdentifier(),
listSizeExpression,
InfixExpression.Operator.LESS));
loopStatement
.updaters()
.add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));
Block forLoopBody = ast.newBlock();
forLoopBody
.statements()
.add(ast.newExpressionStatement(getIndexBasedForBodyAssignment(rewrite, loopVariableName)));
forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
loopStatement.setBody(forLoopBody);
rewrite.replace(fCurrentNode, loopStatement, null);
return rewrite;
}
示例3: generateForRewrite
import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
* Helper to generate an index based <code>for</code> loop to iterate over an array.
*
* @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
* @return an applicable {@link ASTRewrite} instance
*/
private ASTRewrite generateForRewrite(AST ast) {
ASTRewrite rewrite= ASTRewrite.create(ast);
ForStatement loopStatement= ast.newForStatement();
SimpleName loopVariableName= resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); //$NON-NLS-1$
loopStatement.initializers().add(getForInitializer(ast, loopVariableName));
FieldAccess getArrayLengthExpression= ast.newFieldAccess();
getArrayLengthExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
getArrayLengthExpression.setName(ast.newSimpleName("length")); //$NON-NLS-1$
loopStatement.setExpression(getLinkedInfixExpression(rewrite, loopVariableName.getIdentifier(), getArrayLengthExpression, InfixExpression.Operator.LESS));
loopStatement.updaters().add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));
Block forLoopBody= ast.newBlock();
forLoopBody.statements().add(ast.newExpressionStatement(getForBodyAssignment(rewrite, loopVariableName)));
forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
loopStatement.setBody(forLoopBody);
rewrite.replace(fCurrentNode, loopStatement, null);
return rewrite;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:29,代码来源:GenerateForLoopAssistProposal.java
示例4: generateIndexBasedForRewrite
import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
* Helper to generate an index based <code>for</code> loop to iterate over a {@link List}
* implementation.
*
* @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
* @return an applicable {@link ASTRewrite} instance
*/
private ASTRewrite generateIndexBasedForRewrite(AST ast) {
ASTRewrite rewrite= ASTRewrite.create(ast);
ForStatement loopStatement= ast.newForStatement();
SimpleName loopVariableName= resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); //$NON-NLS-1$
loopStatement.initializers().add(getForInitializer(ast, loopVariableName));
MethodInvocation listSizeExpression= ast.newMethodInvocation();
listSizeExpression.setName(ast.newSimpleName("size")); //$NON-NLS-1$
Expression listExpression= (Expression) rewrite.createCopyTarget(fCurrentExpression);
listSizeExpression.setExpression(listExpression);
loopStatement.setExpression(getLinkedInfixExpression(rewrite, loopVariableName.getIdentifier(), listSizeExpression, InfixExpression.Operator.LESS));
loopStatement.updaters().add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));
Block forLoopBody= ast.newBlock();
forLoopBody.statements().add(ast.newExpressionStatement(getIndexBasedForBodyAssignment(rewrite, loopVariableName)));
forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
loopStatement.setBody(forLoopBody);
rewrite.replace(fCurrentNode, loopStatement, null);
return rewrite;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:31,代码来源:GenerateForLoopAssistProposal.java
示例5: generateForRewrite
import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
* Helper to generate an index based <code>for</code> loop to iterate over an array.
*
* @param ast the current {@link AST} instance to generate the {@link ASTRewrite} for
* @return an applicable {@link ASTRewrite} instance
*/
private ASTRewrite generateForRewrite(AST ast) {
ASTRewrite rewrite = ASTRewrite.create(ast);
ForStatement loopStatement = ast.newForStatement();
SimpleName loopVariableName =
resolveLinkedVariableNameWithProposals(rewrite, "int", null, true); // $NON-NLS-1$
loopStatement.initializers().add(getForInitializer(ast, loopVariableName));
FieldAccess getArrayLengthExpression = ast.newFieldAccess();
getArrayLengthExpression.setExpression(
(Expression) rewrite.createCopyTarget(fCurrentExpression));
getArrayLengthExpression.setName(ast.newSimpleName("length")); // $NON-NLS-1$
loopStatement.setExpression(
getLinkedInfixExpression(
rewrite,
loopVariableName.getIdentifier(),
getArrayLengthExpression,
InfixExpression.Operator.LESS));
loopStatement
.updaters()
.add(getLinkedIncrementExpression(rewrite, loopVariableName.getIdentifier()));
Block forLoopBody = ast.newBlock();
forLoopBody
.statements()
.add(ast.newExpressionStatement(getForBodyAssignment(rewrite, loopVariableName)));
forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
loopStatement.setBody(forLoopBody);
rewrite.replace(fCurrentNode, loopStatement, null);
return rewrite;
}
示例6: generateIteratorBasedForRewrite
import org.eclipse.jdt.core.dom.ForStatement; //导入方法依赖的package包/类
/**
* Helper to generate an iterator based <code>for</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 generateIteratorBasedForRewrite(AST ast) {
ASTRewrite rewrite= ASTRewrite.create(ast);
ForStatement loopStatement= ast.newForStatement();
ITypeBinding loopOverType= extractElementType(ast);
SimpleName loopVariableName= resolveLinkedVariableNameWithProposals(rewrite, "iterator", null, true); //$NON-NLS-1$
loopStatement.initializers().add(getIteratorBasedForInitializer(rewrite, loopVariableName));
MethodInvocation loopExpression= ast.newMethodInvocation();
loopExpression.setName(ast.newSimpleName("hasNext")); //$NON-NLS-1$
SimpleName expressionName= ast.newSimpleName(loopVariableName.getIdentifier());
addLinkedPosition(rewrite.track(expressionName), LinkedPositionGroup.NO_STOP, expressionName.getIdentifier());
loopExpression.setExpression(expressionName);
loopStatement.setExpression(loopExpression);
Block forLoopBody= ast.newBlock();
Assignment assignResolvedVariable= getIteratorBasedForBodyAssignment(rewrite, loopOverType, loopVariableName);
forLoopBody.statements().add(ast.newExpressionStatement(assignResolvedVariable));
forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));
loopStatement.setBody(forLoopBody);
rewrite.replace(fCurrentNode, loopStatement, null);
return rewrite;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:GenerateForLoopAssistProposal.java