本文整理汇总了Java中com.sun.source.tree.ForLoopTree类的典型用法代码示例。如果您正苦于以下问题:Java ForLoopTree类的具体用法?Java ForLoopTree怎么用?Java ForLoopTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ForLoopTree类属于com.sun.source.tree包,在下文中一共展示了ForLoopTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
public Boolean visitForLoop(ForLoopTree node, TreePath p) {
if (p == null)
return super.visitForLoop(node, p);
ForLoopTree t = (ForLoopTree) p.getLeaf();
if (!checkLists(node.getInitializer(), t.getInitializer(), p)) {
return false;
}
if (!scan(node.getCondition(), t.getCondition(), p))
return false;
if (!checkLists(node.getUpdate(), t.getUpdate(), p))
return false;
return scan(node.getStatement(), t.getStatement(), p);
}
示例2: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Override
public Void visitForLoop(ForLoopTree node, Void p) {
super.visitForLoop(node, p);
if (isMethodCode() && phase == PHASE_AFTER_SELECTION) {
//#109663𛞨:
//the selection was inside the for-loop, the variables inside the
//condition, update and statement parts of the for loop need to be considered to be used again after the loop:
if (!secondPass) {
secondPass = true;
scan(node.getCondition(), p);
scan(node.getUpdate(), p);
scan(node.getStatement(), p);
secondPass = false;
stopSecondPass = false;
}
}
return null;
}
示例3: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Override
public List<? extends TypeMirror> visitForLoop(ForLoopTree node, Object p) {
if (theExpression == null) {
// ambigous
return null;
}
if (theExpression.getLeaf() == node.getCondition()) {
return booleanType();
} else {
if (!((node.getInitializer() != null && node.getInitializer().contains(theExpression.getLeaf())) || (node.getUpdate() != null && node.getUpdate().contains(theExpression.getLeaf())))) {
return null;
}
// initializer and update operation can have any result type, including none
TypeElement tel = info.getElements().getTypeElement("java.lang.Void");
if (tel == null) {
return null;
}
return Collections.singletonList(tel.asType()); // NOI18N
}
}
示例4: testBlock
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
private boolean testBlock(StringWriter writer, SourcePositions sp, String text, CompilationUnitTree cut, BlockTree blockTree) {
boolean success = true;
for (StatementTree st : blockTree.getStatements()) {
if (isLegal(st)) {
success &= testStatement(writer, sp, text, cut, st);
}
if (st instanceof IfTree) {
IfTree ifTree = (IfTree) st;
success &= testBranch(writer, sp, text, cut, ifTree.getThenStatement());
success &= testBranch(writer, sp, text, cut, ifTree.getElseStatement());
} else if (st instanceof WhileLoopTree) {
WhileLoopTree whileLoopTree = (WhileLoopTree) st;
success &= testBranch(writer, sp, text, cut, whileLoopTree.getStatement());
} else if (st instanceof DoWhileLoopTree) {
DoWhileLoopTree doWhileLoopTree = (DoWhileLoopTree) st;
success &= testBranch(writer, sp, text, cut, doWhileLoopTree.getStatement());
} else if (st instanceof ForLoopTree) {
ForLoopTree forLoopTree = (ForLoopTree) st;
success &= testBranch(writer, sp, text, cut, forLoopTree.getStatement());
} else if (st instanceof LabeledStatementTree) {
LabeledStatementTree labelTree = (LabeledStatementTree) st;
success &= testBranch(writer, sp, text, cut, labelTree.getStatement());
} else if (st instanceof SwitchTree) {
SwitchTree switchTree = (SwitchTree) st;
for (CaseTree caseTree : switchTree.getCases()) {
for (StatementTree statementTree : caseTree.getStatements()) {
success &= testBranch(writer, sp, text, cut, statementTree);
}
}
}
}
return success;
}
示例5: testVisitForLoop
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Test
public void testVisitForLoop() throws ParseException, BadLocationException, IOException {
List<ReformatOption> optionsToReformat = new ArrayList<>();
CompilationUnitTree unit = getCompilationUnitTree(INPUT_FILE);
MethodTree methodTree = TreeNavigationUtils.findMethodTreeByName("doSomething", unit).get(0);
ForLoopTree forLoopTree = (ForLoopTree) getStatementTreeByClassName(ForLoopTree.class, methodTree);
if (forLoopTree == null) {
fail(ERROR_MESSAGE);
}
ReformatTreeVisitor reformatTreeVisitor = getReformatTreeVisitor(INPUT_FILE);
reformatTreeVisitor.visitForLoop(forLoopTree, optionsToReformat);
assertFalse(optionsToReformat.isEmpty());
}
示例6: testVisitForLoopNotReformat
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Test
public void testVisitForLoopNotReformat() throws ParseException, BadLocationException, IOException {
List<ReformatOption> optionsToReformat = new ArrayList<>();
CompilationUnitTree unit = getCompilationUnitTree(INPUT_FILE);
MethodTree methodTree = TreeNavigationUtils.findMethodTreeByName("doSomething", unit).get(0);
ForLoopTree forLoopTree = (ForLoopTree) getStatementTreeByClassName(ForLoopTree.class, methodTree);
if (forLoopTree == null) {
fail(ERROR_MESSAGE);
}
ReformatTreeVisitor reformatTreeVisitor = getReformatTreeVisitor(INPUT_FILE, 0, 10);
reformatTreeVisitor.visitForLoop(forLoopTree, optionsToReformat);
assertTrue(optionsToReformat.isEmpty());
}
示例7: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Override
public Boolean visitForLoop(ForLoopTree that, Void unused) {
Boolean condValue = ASTHelpers.constValue(that.getCondition(), Boolean.class);
if (!Objects.equals(condValue, false)) {
scan(that.getStatement());
}
// (1)
if (that.getCondition() != null && !Objects.equals(condValue, true)) {
return true;
}
// (2)
if (breaks.contains(that)) {
return true;
}
return false;
}
示例8: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Override
public Tree visitForLoop(ForLoopTree tree, Void p) {
ForLoopTree n = make.ForLoop(tree.getInitializer(), tree.getCondition(), tree.getUpdate(), tree.getStatement());
model.setType(n, model.getType(tree));
comments.copyComments(tree, n);
model.setPos(n, model.getPos(tree));
return n;
}
示例9: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Override
public Void visitForLoop(ForLoopTree node, EnumSet<UseTypes> p) {
if (node.getCondition() != null && node.getCondition().getKind() == Kind.IDENTIFIER) {
handlePossibleIdentifier(new TreePath(getCurrentPath(), node.getCondition()), EnumSet.of(UseTypes.READ));
}
return super.visitForLoop(node, p);
}
示例10: visitVariable
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Override
public Object visitVariable(VariableTree node, Object p) {
TreePath path = getCurrentPath();
Tree parent = path.getParentPath().getLeaf();
if (parent instanceof StatementTree) {
boolean count = true;
if (parent instanceof ForLoopTree) {
count = !((ForLoopTree)parent).getInitializer().contains(node);
} else if (parent instanceof EnhancedForLoopTree) {
count = ((EnhancedForLoopTree)parent).getVariable() != node;
}
if (count) {
statements++;
}
}
return super.visitVariable(node, p);
}
示例11: visitExpressionStatement
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Override
public Object visitExpressionStatement(ExpressionStatementTree node, Object p) {
boolean count = true;
TreePath path = getCurrentPath();
Tree parent = path.getParentPath().getLeaf();
// do not count the update statement in a for-loop
if (parent instanceof ForLoopTree) {
count = !((ForLoopTree)parent).getUpdate().contains(node);
}
if (count) {
statements++;
}
return super.visitExpressionStatement(node, p);
}
示例12: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Override
public Object visitForLoop(ForLoopTree node, Object p) {
boolean saveFlag = switchCase;
switchCase = false;
complexity++;
Object o = super.visitForLoop(node, p);
this.switchCase = saveFlag;
return o;
}
示例13: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Override
public Object visitForLoop(ForLoopTree node, Object p) {
depth++;
Object o = super.visitForLoop(node, p);
depth--;
return o;
}
示例14: visitForLoop
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Override
public Void visitForLoop(ForLoopTree tree, List<Node> d) {
List<Node> below = new ArrayList<Node>();
addCorrespondingType(below);
addCorrespondingComments(below);
super.visitForLoop(tree, below);
d.add(new TreeNode(info, getCurrentPath(), below));
return null;
}
示例15: checkFor
import com.sun.source.tree.ForLoopTree; //导入依赖的package包/类
@Hint(displayName="#LBL_Braces_For", description="#DSC_Braces_For", category="braces", id=BRACES_ID + "FOR_LOOP", enabled=false, suppressWarnings={"", "ControlFlowStatementWithoutBraces"})
@TriggerTreeKind({Tree.Kind.FOR_LOOP, Tree.Kind.ENHANCED_FOR_LOOP})
public static ErrorDescription checkFor(HintContext ctx) {
StatementTree st;
switch (ctx.getPath().getLeaf().getKind()){
case FOR_LOOP: st = ((ForLoopTree) ctx.getPath().getLeaf()).getStatement(); break;
case ENHANCED_FOR_LOOP: st = ((EnhancedForLoopTree) ctx.getPath().getLeaf()).getStatement(); break;
default:
throw new IllegalStateException();
}
return checkStatement(ctx, "LBL_Braces_For", st, ctx.getPath());
}