本文整理汇总了Java中org.eclipse.jdt.core.dom.ForStatement类的典型用法代码示例。如果您正苦于以下问题:Java ForStatement类的具体用法?Java ForStatement怎么用?Java ForStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ForStatement类属于org.eclipse.jdt.core.dom包,在下文中一共展示了ForStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: locationNeedsParentheses
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
return false;
}
if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
|| locationInParent == ForStatement.EXPRESSION_PROPERTY
|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
|| locationInParent == DoStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.MESSAGE_PROPERTY
|| locationInParent == IfStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
|| locationInParent == ArrayAccess.INDEX_PROPERTY
|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
return false;
}
return true;
}
示例2: getBlockType
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
private BlockInfo.Type getBlockType(ASTNode node) {
if(node instanceof TypeDeclaration)
return BlockInfo.Type.TYPE;
else if(node instanceof MethodDeclaration)
return BlockInfo.Type.METHOD;
else if(node instanceof WhileStatement)
return BlockInfo.Type.WHILE;
else if(node instanceof ForStatement)
return BlockInfo.Type.FOR;
else if(node instanceof IfStatement)
return BlockInfo.Type.IF;
else
return BlockInfo.Type.OTHER;
}
示例3: getStatementType
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
/**
* Method that check statement type.
* @author Mariana Azevedo
* @since 13/07/2014
* @param itStatement
*/
private void getStatementType(Object itStatement) {
if (itStatement instanceof CatchClause){
this.visitor.visit((CatchClause)itStatement);
}else if (itStatement instanceof ForStatement){
this.visitor.visit((ForStatement)itStatement);
}else if (itStatement instanceof IfStatement){
this.visitor.visit((IfStatement)itStatement);
}else if (itStatement instanceof WhileStatement){
this.visitor.visit((WhileStatement)itStatement);
}else if (itStatement instanceof TryStatement){
this.visitor.visit((TryStatement)itStatement);
}else if (itStatement instanceof ConditionalExpression){
this.visitor.visit((ConditionalExpression)itStatement);
}else if (itStatement instanceof SwitchCase){
this.visitor.visit((SwitchCase)itStatement);
}else if (itStatement instanceof DoStatement){
this.visitor.visit((DoStatement)itStatement);
}else if (itStatement instanceof ExpressionStatement){
this.visitor.visit((ExpressionStatement)itStatement);
}
}
示例4: getParentLoopBody
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
private Statement getParentLoopBody(ASTNode node) {
Statement stmt = null;
ASTNode start = node;
while (start != null && !(start instanceof ForStatement) && !(start instanceof DoStatement) && !(start instanceof WhileStatement) && !(start instanceof EnhancedForStatement) && !(start instanceof SwitchStatement)) {
start = start.getParent();
}
if (start instanceof ForStatement) {
stmt = ((ForStatement) start).getBody();
} else if (start instanceof DoStatement) {
stmt = ((DoStatement) start).getBody();
} else if (start instanceof WhileStatement) {
stmt = ((WhileStatement) start).getBody();
} else if (start instanceof EnhancedForStatement) {
stmt = ((EnhancedForStatement) start).getBody();
}
if (start != null && start.getParent() instanceof LabeledStatement) {
LabeledStatement labeledStatement = (LabeledStatement) start.getParent();
fEnclosingLoopLabel = labeledStatement.getLabel();
}
return stmt;
}
示例5: endVisit
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
@Override
public void endVisit(ForStatement node) {
ASTNode[] selectedNodes = getSelectedNodes();
if (doAfterValidation(node, selectedNodes)) {
boolean containsExpression = contains(selectedNodes, node.getExpression());
boolean containsUpdaters = contains(selectedNodes, node.updaters());
if (contains(selectedNodes, node.initializers()) && containsExpression) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_for_initializer_expression);
} else if (containsExpression && containsUpdaters) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_for_expression_updater);
} else if (containsUpdaters && contains(selectedNodes, node.getBody())) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_for_updater_body);
}
}
super.endVisit(node);
}
示例6: getForStatement
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
private static ForStatement getForStatement(ICompilationUnit cu) {
CompilationUnit ast =
SharedASTProvider.getAST(cu, SharedASTProvider.WAIT_YES, new NullProgressMonitor());
final ForStatement[] statement = new ForStatement[1];
ast.accept(
new GenericVisitor() {
protected boolean visitNode(ASTNode node) {
if (node instanceof ForStatement) {
statement[0] = (ForStatement) node;
return false;
} else {
return super.visitNode(node);
}
}
});
return statement[0];
}
示例7: locationNeedsParentheses
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
if (locationInParent instanceof ChildListPropertyDescriptor
&& locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation
// ...
return false;
}
if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
|| locationInParent == ForStatement.EXPRESSION_PROPERTY
|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
|| locationInParent == DoStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
|| locationInParent == AssertStatement.MESSAGE_PROPERTY
|| locationInParent == IfStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
|| locationInParent == ArrayAccess.INDEX_PROPERTY
|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
return false;
}
return true;
}
示例8: getConvertOperation
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
private ConvertLoopOperation getConvertOperation(ForStatement node) {
Collection<String> usedNamesCollection = fUsedNames.values();
String[] usedNames = usedNamesCollection.toArray(new String[usedNamesCollection.size()]);
ConvertLoopOperation convertForLoopOperation =
new ConvertForLoopOperation(node, usedNames, fMakeFinal);
if (convertForLoopOperation.satisfiesPreconditions().isOK()) {
if (fFindForLoopsToConvert) {
fUsedNames.put(node, convertForLoopOperation.getIntroducedVariableName());
return convertForLoopOperation;
}
} else if (fConvertIterableForLoops) {
ConvertLoopOperation iterableConverter =
new ConvertIterableLoopOperation(node, usedNames, fMakeFinal);
if (iterableConverter.satisfiesPreconditions().isOK()) {
fUsedNames.put(node, iterableConverter.getIntroducedVariableName());
return iterableConverter;
}
}
return null;
}
示例9: isSingleControlStatementWithoutBlock
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
private boolean isSingleControlStatementWithoutBlock() {
List<Statement> statements = fDeclaration.getBody().statements();
int size = statements.size();
if (size != 1) return false;
Statement statement = statements.get(size - 1);
int nodeType = statement.getNodeType();
if (nodeType == ASTNode.IF_STATEMENT) {
IfStatement ifStatement = (IfStatement) statement;
return !(ifStatement.getThenStatement() instanceof Block)
&& !(ifStatement.getElseStatement() instanceof Block);
} else if (nodeType == ASTNode.FOR_STATEMENT) {
return !(((ForStatement) statement).getBody() instanceof Block);
} else if (nodeType == ASTNode.WHILE_STATEMENT) {
return !(((WhileStatement) statement).getBody() instanceof Block);
}
return false;
}
示例10: getParentLoopBody
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
private Statement getParentLoopBody(ASTNode node) {
Statement stmt = null;
ASTNode start = node;
while (start != null
&& !(start instanceof ForStatement)
&& !(start instanceof DoStatement)
&& !(start instanceof WhileStatement)
&& !(start instanceof EnhancedForStatement)
&& !(start instanceof SwitchStatement)) {
start = start.getParent();
}
if (start instanceof ForStatement) {
stmt = ((ForStatement) start).getBody();
} else if (start instanceof DoStatement) {
stmt = ((DoStatement) start).getBody();
} else if (start instanceof WhileStatement) {
stmt = ((WhileStatement) start).getBody();
} else if (start instanceof EnhancedForStatement) {
stmt = ((EnhancedForStatement) start).getBody();
}
if (start != null && start.getParent() instanceof LabeledStatement) {
LabeledStatement labeledStatement = (LabeledStatement) start.getParent();
fEnclosingLoopLabel = labeledStatement.getLabel();
}
return stmt;
}
示例11: endVisit
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
@Override
public void endVisit(ForStatement node) {
ASTNode[] selectedNodes = getSelectedNodes();
if (doAfterValidation(node, selectedNodes)) {
boolean containsExpression = contains(selectedNodes, node.getExpression());
boolean containsUpdaters = contains(selectedNodes, node.updaters());
if (contains(selectedNodes, node.initializers()) && containsExpression) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_for_initializer_expression);
} else if (containsExpression && containsUpdaters) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_for_expression_updater);
} else if (containsUpdaters && contains(selectedNodes, node.getBody())) {
invalidSelection(RefactoringCoreMessages.StatementAnalyzer_for_updater_body);
}
}
super.endVisit(node);
}
示例12: 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;
}
示例13: 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;
}
示例14: preNext
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
@Override
public boolean preNext(Statement curElement) {
switch (curElement.getNodeType()) {
case ASTNode.WHILE_STATEMENT:
exportWhile((WhileStatement) curElement);
break;
case ASTNode.FOR_STATEMENT:
exportFor((ForStatement) curElement);
break;
case ASTNode.ENHANCED_FOR_STATEMENT:
exportForEach((EnhancedForStatement) curElement);
break;
case ASTNode.DO_STATEMENT:
exportDoWhileStatement((DoStatement) curElement);
break;
}
return true;
}
示例15: isSingleControlStatementWithoutBlock
import org.eclipse.jdt.core.dom.ForStatement; //导入依赖的package包/类
private boolean isSingleControlStatementWithoutBlock() {
List<Statement> statements= fDeclaration.getBody().statements();
int size= statements.size();
if (size != 1)
return false;
Statement statement= statements.get(size - 1);
int nodeType= statement.getNodeType();
if (nodeType == ASTNode.IF_STATEMENT) {
IfStatement ifStatement= (IfStatement) statement;
return !(ifStatement.getThenStatement() instanceof Block)
&& !(ifStatement.getElseStatement() instanceof Block);
} else if (nodeType == ASTNode.FOR_STATEMENT) {
return !(((ForStatement)statement).getBody() instanceof Block);
} else if (nodeType == ASTNode.WHILE_STATEMENT) {
return !(((WhileStatement)statement).getBody() instanceof Block);
}
return false;
}