本文整理汇总了Java中com.sun.source.tree.WhileLoopTree类的典型用法代码示例。如果您正苦于以下问题:Java WhileLoopTree类的具体用法?Java WhileLoopTree怎么用?Java WhileLoopTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WhileLoopTree类属于com.sun.source.tree包,在下文中一共展示了WhileLoopTree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ScanStatement.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:EvaluatorVisitor.java
示例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;
}
开发者ID:campolake,项目名称:openjdk9,代码行数:34,代码来源:CompletenessStressTest.java
示例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());
}
开发者ID:fundacionjala,项目名称:oblivion-netbeans-plugin,代码行数:17,代码来源:ReformatTreeVisitorTest.java
示例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());
}
开发者ID:fundacionjala,项目名称:oblivion-netbeans-plugin,代码行数:17,代码来源:ReformatTreeVisitorTest.java
示例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;
}
开发者ID:google,项目名称:error-prone,代码行数:17,代码来源:Reachability.java
示例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;
}
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:17,代码来源:ElementsCountedInLoop.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:TreeDuplicator.java
示例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);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:CopyFinder.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:CyclomaticComplexityVisitor.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:DepthVisitor.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:TreeNode.java
示例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;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:InfiniteRecursion.java
示例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();
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ExpectedTypeResolver.java
示例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);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ExpressionScanner.java
示例16: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Void visitWhileLoop(WhileLoopTree node, Void unused) {
sync(node);
token("while");
builder.space();
token("(");
scan(skipParen(node.getCondition()), null);
token(")");
visitStatement(
node.getStatement(),
CollapseEmptyOrNot.YES,
AllowLeadingBlankLine.YES,
AllowTrailingBlankLine.NO);
return null;
}
开发者ID:tranleduy2000,项目名称:javaide,代码行数:16,代码来源:JavaInputAstVisitor.java
示例17: testPositionBrokenSource126732b
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
void testPositionBrokenSource126732b() throws IOException {
String[] commands = new String[]{
"break",
"break A",
"continue ",
"continue A",};
for (String command : commands) {
String code = "package test;\n"
+ "public class Test {\n"
+ " public static void test() {\n"
+ " while (true) {\n"
+ " " + command + " {\n"
+ " new Runnable() {\n"
+ " };\n"
+ " }\n"
+ " }\n"
+ "}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null,
null, null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree method = (MethodTree) clazz.getMembers().get(0);
List<? extends StatementTree> statements =
((BlockTree) ((WhileLoopTree) method.getBody().getStatements().get(0)).getStatement()).getStatements();
StatementTree ret = statements.get(0);
StatementTree block = statements.get(1);
Trees t = Trees.instance(ct);
int len = code.indexOf(command + " {") + (command + " ").length();
assertEquals(command, len,
t.getSourcePositions().getEndPosition(cut, ret));
assertEquals(command, len,
t.getSourcePositions().getStartPosition(cut, block));
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:JavacParserTest.java
示例18: testPositionBrokenSource126732b
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
void testPositionBrokenSource126732b() throws IOException {
String[] commands = new String[]{
"break",
"break A",
"continue ",
"continue A",};
for (String command : commands) {
String code = "package test;\n"
+ "public class Test {\n"
+ " public static void test() {\n"
+ " while (true) {\n"
+ " " + command + " {\n"
+ " new Runnable() {\n"
+ " };\n"
+ " }\n"
+ " }\n"
+ "}";
JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null,
null, null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree method = (MethodTree) clazz.getMembers().get(0);
List<? extends StatementTree> statements =
((BlockTree) ((WhileLoopTree) method.getBody().getStatements().get(0)).getStatement()).getStatements();
StatementTree ret = statements.get(0);
StatementTree block = statements.get(1);
Trees t = Trees.instance(ct);
int len = code.indexOf(command + " {") + (command + " ").length();
assertEquals(command, len,
t.getSourcePositions().getEndPosition(cut, ret));
assertEquals(command, len,
t.getSourcePositions().getStartPosition(cut, block));
}
}
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:41,代码来源:JavacParserTest.java
示例19: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Void visitWhileLoop(WhileLoopTree whileLoopTree, List<ReformatOption> optionsToReformat) {
StatementTree statement = whileLoopTree.getStatement();
if (statement instanceof BlockTree) {
addLeftBraceToList(optionsToReformat, ((BlockTree) statement), PreferencesFormatOptions.BRACES_IN_OTHER_DECLARATION);
addRightBraceToList(optionsToReformat, ((CompoundTree) statement), PreferencesFormatOptions.AFTER_OTHER_DECLARATION);
}
return null;
}
开发者ID:fundacionjala,项目名称:oblivion-netbeans-plugin,代码行数:11,代码来源:ReformatTreeVisitor.java
示例20: visitWhileLoop
import com.sun.source.tree.WhileLoopTree; //导入依赖的package包/类
@Override
public Void visitWhileLoop(WhileLoopTree tree, VisitorState visitorState) {
VisitorState state = visitorState.withPath(getCurrentPath());
for (WhileLoopTreeMatcher matcher : whileLoopMatchers) {
if (!isSuppressed(matcher, state)) {
try {
reportMatch(matcher.matchWhileLoop(tree, state), tree, state);
} catch (Throwable t) {
handleError(matcher, t);
}
}
}
return super.visitWhileLoop(tree, state);
}
开发者ID:google,项目名称:error-prone,代码行数:15,代码来源:ErrorProneScanner.java
注:本文中的com.sun.source.tree.WhileLoopTree类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论