本文整理汇总了Java中org.eclipse.jdt.core.dom.EnhancedForStatement.setExpression方法的典型用法代码示例。如果您正苦于以下问题:Java EnhancedForStatement.setExpression方法的具体用法?Java EnhancedForStatement.setExpression怎么用?Java EnhancedForStatement.setExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.EnhancedForStatement
的用法示例。
在下文中一共展示了EnhancedForStatement.setExpression方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeReplacementForLoop
import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private EnhancedForStatement makeReplacementForLoop(EntrySetResolutionVisitor visitor) {
// this would be map.keySet().
// We need this to get the type of map and get the variable name of map
MethodInvocation oldLoopExpression = (MethodInvocation) visitor.ancestorForLoop.getExpression();
// for(Parameter : Expression)
EnhancedForStatement replacement = ast.newEnhancedForStatement();
replacement.setParameter(makeEntrySetParameter(oldLoopExpression));
replacement.setExpression(makeCallToEntrySet(oldLoopExpression));
List<Statement> replacementBlockStatements = ((Block) replacement.getBody()).statements();
// create new statement to replace the key object (e.g. the String s that used to be in the for each)
replacementBlockStatements.add(makeNewKeyStatement(visitor));
// replace the call to map.get() with a call to entry.getValue()
replacementBlockStatements.add(makeNewValueStatement(visitor));
// transfer the rest of the statements in the old block
copyRestOfBlock(replacementBlockStatements, visitor);
return replacement;
}
示例2: generateForEachRewrite
import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入方法依赖的package包/类
/**
* 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 = extractElementType(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(fCurrentNode, 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);
rewrite.replace(fCurrentNode, loopStatement, null);
return rewrite;
}
示例3: convert
import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入方法依赖的package包/类
@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;
}
示例4: convert
import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入方法依赖的package包/类
@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;
}
示例5: generateForEachRewrite
import org.eclipse.jdt.core.dom.EnhancedForStatement; //导入方法依赖的package包/类
/**
* 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= extractElementType(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(fCurrentNode, 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);
rewrite.replace(fCurrentNode, loopStatement, null);
return rewrite;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:33,代码来源:GenerateForLoopAssistProposal.java