com.sun.source.tree.WhileLoopTree Java Examples
The following examples show how to use
com.sun.source.tree.WhileLoopTree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScanStatement.java From netbeans with Apache License 2.0 | 6 votes |
@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; }
Example #2
Source File: JavacParserTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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)); } }
Example #3
Source File: TreeDiffer.java From compile-testing with Apache License 2.0 | 5 votes |
@Override public Void visitWhileLoop(WhileLoopTree expected, Tree actual) { Optional<WhileLoopTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getCondition(), other.get().getCondition()); scan(expected.getStatement(), other.get().getStatement()); return null; }
Example #4
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 5 votes |
@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; }
Example #5
Source File: JavacParserTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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)); } }
Example #6
Source File: JavacParserTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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)); } }
Example #7
Source File: JavacParserTest.java From hottub with GNU General Public License v2.0 | 5 votes |
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)); } }
Example #8
Source File: JavacParserTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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)); } }
Example #9
Source File: CompletenessStressTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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; }
Example #10
Source File: JavaInputAstVisitor.java From javaide with GNU General Public License v3.0 | 5 votes |
@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; }
Example #11
Source File: JavacParserTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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)); } }
Example #12
Source File: NullAway.java From NullAway with MIT License | 5 votes |
@Override public Description matchWhileLoop(WhileLoopTree tree, VisitorState state) { if (!matchWithinClass) { return Description.NO_MATCH; } return doUnboxingCheck(state, tree.getCondition()); }
Example #13
Source File: ExpressionScanner.java From netbeans with Apache License 2.0 | 5 votes |
@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); }
Example #14
Source File: ExpectedTypeResolver.java From netbeans with Apache License 2.0 | 5 votes |
@Override public List<? extends TypeMirror> visitWhileLoop(WhileLoopTree node, Object p) { if (theExpression == null) { initExpression(node.getCondition()); } return booleanType(); }
Example #15
Source File: InfiniteRecursion.java From netbeans with Apache License 2.0 | 5 votes |
@Override public State visitWhileLoop(WhileLoopTree node, Void p) { State s; registerBreakTarget((node)); returnIfRecurse(s = scan(node.getCondition(), p)); return s; }
Example #16
Source File: JavacParserTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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)); } }
Example #17
Source File: TreeNode.java From netbeans with Apache License 2.0 | 5 votes |
@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; }
Example #18
Source File: DepthVisitor.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Object visitWhileLoop(WhileLoopTree node, Object p) { depth++; Object o = super.visitWhileLoop(node, p); depth--; return o; }
Example #19
Source File: CyclomaticComplexityVisitor.java From netbeans with Apache License 2.0 | 5 votes |
@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; }
Example #20
Source File: JavaInputAstVisitor.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
@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; }
Example #21
Source File: JavacParserTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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)); } }
Example #22
Source File: TreeDuplicator.java From netbeans with Apache License 2.0 | 5 votes |
@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; }
Example #23
Source File: CopyFinder.java From netbeans with Apache License 2.0 | 5 votes |
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); }
Example #24
Source File: MoveTreeTest.java From netbeans with Apache License 2.0 | 4 votes |
public void test187616() throws Exception { testFile = new File(getWorkDir(), "Test.java"); TestUtilities.copyStringToFile(testFile, "package hierbas.del.litoral;\n\n" + "public class Test {\n" + " public void taragui(String str) {\n" + " //blabla\n" + "\twhile(path.getLeaf().getKind() != Kind.CLASS) {\n" + " }\n" + " }\n" + "}\n" ); String golden = "package hierbas.del.litoral;\n\n" + "public class Test {\n" + " public void taragui(String str) {\n" + " //blabla\n" + "\twhile(!TreeUtilities.SET.contains(path.getLeaf().getKind())) {\n" + " }\n" + " }\n" + "}\n"; JavaSource src = getJavaSource(testFile); Task<WorkingCopy> task = new Task<WorkingCopy>() { public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(Phase.PARSED); TreeMaker make = workingCopy.getTreeMaker(); CompilationUnitTree cut = workingCopy.getCompilationUnit(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); MethodTree method = (MethodTree) clazz.getMembers().get(0); BlockTree body = method.getBody(); WhileLoopTree loop = (WhileLoopTree)body.getStatements().get(0); BinaryTree origCond = (BinaryTree) ((ParenthesizedTree) loop.getCondition()).getExpression(); ExpressionTree nueCondition = make.Unary(Tree.Kind.LOGICAL_COMPLEMENT, make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.MemberSelect(make.MemberSelect(make.Identifier("TreeUtilities"), "SET"), "contains"), Collections.singletonList(origCond.getLeftOperand()))); workingCopy.rewrite(origCond, nueCondition); } }; src.runModificationTask(task).commit(); String res = TestUtilities.copyFileToString(testFile); //System.err.println(res); assertEquals(golden, res); }
Example #25
Source File: UWhileLoop.java From Refaster with Apache License 2.0 | 4 votes |
@Override @Nullable public Unifier visitWhileLoop(WhileLoopTree loop, @Nullable Unifier unifier) { unifier = getCondition().unify(loop.getCondition(), unifier); return getStatement().unify(loop.getStatement(), unifier); }
Example #26
Source File: RefasterScanner.java From Refaster with Apache License 2.0 | 4 votes |
@Override public Void visitWhileLoop(WhileLoopTree node, Context context) { scan(SKIP_PARENS.visit(node.getCondition(), null), context); scan(node.getStatement(), context); return null; }
Example #27
Source File: UTemplater.java From Refaster with Apache License 2.0 | 4 votes |
@Override public UWhileLoop visitWhileLoop(WhileLoopTree tree, Void v) { return UWhileLoop.create(template(tree.getCondition()), template(tree.getStatement())); }
Example #28
Source File: VisitWhileLoopHook.java From kan-java with Eclipse Public License 1.0 | 4 votes |
public void afterVisitStatement(WhileLoopTree node, List<ErrMsg> errMsgs, GlobalContext globalCtx, Closure<List<Map<String, Long>>> resolveRowAndCol, Closure<Void> setError);
Example #29
Source File: VisitWhileLoopHook.java From kan-java with Eclipse Public License 1.0 | 4 votes |
public void afterVisitConditionAndBeforeStatement(WhileLoopTree node, List<ErrMsg> errMsgs, GlobalContext globalCtx, Closure<List<Map<String, Long>>> resolveRowAndCol, Closure<Void> setError);
Example #30
Source File: VisitWhileLoopHook.java From kan-java with Eclipse Public License 1.0 | 4 votes |
public void beforeVisitCondition(WhileLoopTree node, List<ErrMsg> errMsgs, GlobalContext globalCtx, Closure<List<Map<String, Long>>> resolveRowAndCol, Closure<Void> setError);