本文整理汇总了Java中com.sun.source.tree.WhileLoopTree类的典型用法代码示例。如果您正苦于以下问题:Java WhileLoopTree类的具体用法?Java WhileLoopTree怎么用?Java WhileLoopTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WhileLoopTree类属于com.sun.source.tree包,在下文中一共展示了WhileLoopTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Void visitWhileLoop(WhileLoopTree node, Void p) {
super.visitWhileLoop(node, p);
if (isMethodCode() && phase == PHASE_AFTER_SELECTION) {
//#109663𛞨:
//the selection was inside the while-loop, the variables inside the
//condition&statement of the while loop need to be considered to be used again after the loop:
if (!secondPass) {
secondPass = true;
scan(node.getCondition(), p);
scan(node.getStatement(), p);
secondPass = false;
stopSecondPass = false;
}
}
return null;
}
示例2: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Mirror visitWhileLoop(WhileLoopTree arg0, EvaluationContext evaluationContext) {
ExpressionTree condition = arg0.getCondition();
Tree statement = arg0.getStatement();
Mirror result = null;
while (evaluateCondition(arg0, evaluationContext, condition)) {
try {
evaluationContext.pushBlock();
Mirror res = statement.accept(this, evaluationContext);
if (res instanceof Break) {
break;
} else if (res instanceof Continue) {
continue;
}
if (res != null) {
result = res;
}
} finally {
evaluationContext.popBlock();
}
}
return result;
}
示例3: testBlock
import com.sun.source.tree.WhileLoopTree; //导入依赖的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;
}
示例4: testVisitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Test
public void testVisitWhileLoop() throws ParseException, BadLocationException, IOException {
List<ReformatOption> optionsToReformat = new ArrayList<>();
CompilationUnitTree unit = getCompilationUnitTree(INPUT_FILE);
MethodTree methodTree = TreeNavigationUtils.findMethodTreeByName("doSomething", unit).get(0);
WhileLoopTree whileLoopTree = (WhileLoopTree) getStatementTreeByClassName(WhileLoopTree.class, methodTree);
if (whileLoopTree == null) {
fail(ERROR_MESSAGE);
}
ReformatTreeVisitor reformatTreeVisitor = getReformatTreeVisitor(INPUT_FILE);
reformatTreeVisitor.visitWhileLoop(whileLoopTree, optionsToReformat);
assertFalse(optionsToReformat.isEmpty());
}
示例5: testVisitWhileLoopNotReformat
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Test
public void testVisitWhileLoopNotReformat() throws ParseException, BadLocationException, IOException {
List<ReformatOption> optionsToReformat = new ArrayList<>();
CompilationUnitTree unit = getCompilationUnitTree(INPUT_FILE);
MethodTree methodTree = TreeNavigationUtils.findMethodTreeByName("doSomething", unit).get(0);
WhileLoopTree whileLoopTree = (WhileLoopTree) getStatementTreeByClassName(WhileLoopTree.class, methodTree);
if (whileLoopTree == null) {
fail(ERROR_MESSAGE);
}
ReformatTreeVisitor reformatTreeVisitor = getReformatTreeVisitor(INPUT_FILE, 0, 10);
reformatTreeVisitor.visitWhileLoop(whileLoopTree, optionsToReformat);
assertTrue(optionsToReformat.isEmpty());
}
示例6: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Boolean visitWhileLoop(WhileLoopTree tree, Void unused) {
Boolean condValue = ASTHelpers.constValue(tree.getCondition(), Boolean.class);
if (!Objects.equals(condValue, false)) {
scan(tree.getStatement());
}
// (1)
if (!Objects.equals(condValue, true)) {
return true;
}
// (2)
if (breaks.contains(tree)) {
return true;
}
return false;
}
示例7: matchWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Description matchWhileLoop(WhileLoopTree tree, VisitorState state) {
JCWhileLoop whileLoop = (JCWhileLoop) tree;
JCExpression whileExpression = ((JCParens) whileLoop.getCondition()).getExpression();
if (whileExpression instanceof MethodInvocationTree) {
MethodInvocationTree methodInvocation = (MethodInvocationTree) whileExpression;
if (methodSelect(isDescendantOfMethod("java.util.Iterator", "hasNext()")).matches(
methodInvocation, state)) {
IdentifierTree identifier = getIncrementedIdentifer(extractSingleStatement(whileLoop.body));
if (identifier != null) {
return describeMatch(tree, new SuggestedFix());
}
}
}
return Description.NO_MATCH;
}
示例8: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Tree visitWhileLoop(WhileLoopTree tree, Void p) {
WhileLoopTree n = make.WhileLoop(tree.getCondition(), tree.getStatement());
model.setType(n, model.getType(tree));
comments.copyComments(tree, n);
model.setPos(n, model.getPos(tree));
return n;
}
示例9: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
public Boolean visitWhileLoop(WhileLoopTree node, TreePath p) {
if (p == null)
return super.visitWhileLoop(node, p);
WhileLoopTree t = (WhileLoopTree) p.getLeaf();
if (!scan(node.getCondition(), t.getCondition(), p))
return false;
return scan(node.getStatement(), t.getStatement(), p);
}
示例10: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Object visitWhileLoop(WhileLoopTree node, Object p) {
boolean saveFlag = switchCase;
switchCase = false;
complexity++;
Object o = super.visitWhileLoop(node, p);
this.switchCase = saveFlag;
return o;
}
示例11: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Object visitWhileLoop(WhileLoopTree node, Object p) {
depth++;
Object o = super.visitWhileLoop(node, p);
depth--;
return o;
}
示例12: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Void visitWhileLoop(WhileLoopTree tree, List<Node> d) {
List<Node> below = new ArrayList<Node>();
addCorrespondingType(below);
addCorrespondingComments(below);
super.visitWhileLoop(tree, below);
d.add(new TreeNode(info, getCurrentPath(), below));
return null;
}
示例13: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public State visitWhileLoop(WhileLoopTree node, Void p) {
State s;
registerBreakTarget((node));
returnIfRecurse(s = scan(node.getCondition(), p));
return s;
}
示例14: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public List<? extends TypeMirror> visitWhileLoop(WhileLoopTree node, Object p) {
if (theExpression == null) {
initExpression(node.getCondition());
}
return booleanType();
}
示例15: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public List<Tree> visitWhileLoop(WhileLoopTree node, ExpressionScanner.ExpressionsInfo p) {
List<Tree> cond = null;
if (acceptsTree(node.getCondition())) {
cond = scan(node.getCondition(), p);
}
List<Tree> statements = scan(node.getStatement(), p);
if (cond != null && statements != null && statements.size() > 0) {
p.addNextExpression(statements.get(statements.size() - 1), cond.get(0));
}
return reduce(cond, statements);
}