com.sun.source.tree.DoWhileLoopTree Java Examples

The following examples show how to use com.sun.source.tree.DoWhileLoopTree. 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: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitDoWhileLoop(DoWhileLoopTree node, Void unused) {
    sync(node);
    token("do");
    visitStatement(
            node.getStatement(),
            CollapseEmptyOrNot.YES,
            AllowLeadingBlankLine.YES,
            AllowTrailingBlankLine.YES);
    if (node.getStatement().getKind() == BLOCK) {
        builder.space();
    } else {
        builder.breakOp(" ");
    }
    token("while");
    builder.space();
    token("(");
    scan(skipParen(node.getCondition()), null);
    token(")");
    token(";");
    return null;
}
 
Example #2
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitDoWhileLoop(DoWhileLoopTree node, Void unused) {
  sync(node);
  token("do");
  visitStatement(
      node.getStatement(),
      CollapseEmptyOrNot.YES,
      AllowLeadingBlankLine.YES,
      AllowTrailingBlankLine.YES);
  if (node.getStatement().getKind() == BLOCK) {
    builder.space();
  } else {
    builder.breakOp(" ");
  }
  token("while");
  builder.space();
  token("(");
  scan(skipParen(node.getCondition()), null);
  token(")");
  token(";");
  return null;
}
 
Example #3
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Void visitDoWhileLoop(DoWhileLoopTree node, Void unused) {
    sync(node);
    token("do");
    visitStatement(
            node.getStatement(),
            CollapseEmptyOrNot.YES,
            AllowLeadingBlankLine.YES,
            AllowTrailingBlankLine.YES);
    if (node.getStatement().getKind() == BLOCK) {
        builder.space();
    } else {
        builder.breakOp(" ");
    }
    token("while");
    builder.space();
    token("(");
    scan(skipParen(node.getCondition()), null);
    token(")");
    token(";");
    return null;
}
 
Example #4
Source File: ScanStatement.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitDoWhileLoop(DoWhileLoopTree node, Void p) {
    super.visitDoWhileLoop(node, p);
    if (isMethodCode() && phase == PHASE_AFTER_SELECTION) {
        //#109663&#112552:
        //the selection was inside the do-while, the variables inside the
        //statement part of the do-while loop need to be considered to be used again after the loop:
        if (!secondPass) {
            secondPass = true;
            scan(node.getStatement(), p);
            secondPass = false;
            stopSecondPass = false;
        }
    }
    return null;
}
 
Example #5
Source File: TreeDuplicator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Tree visitDoWhileLoop(DoWhileLoopTree tree, Void p) {
    DoWhileLoopTree n = make.DoWhileLoop(tree.getCondition(), tree.getStatement());
    model.setType(n, model.getType(tree));
    comments.copyComments(tree, n);
    model.setPos(n, model.getPos(tree));
    return n;
}
 
Example #6
Source File: TreeDiffer.java    From compile-testing with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitDoWhileLoop(DoWhileLoopTree expected, Tree actual) {
  Optional<DoWhileLoopTree> 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 #7
Source File: CompletenessStressTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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 #8
Source File: ExpressionScanner.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public List<Tree> visitDoWhileLoop(DoWhileLoopTree node, ExpressionScanner.ExpressionsInfo p) {
    List<Tree> statements = scan(node.getStatement(), p);
    List<Tree> cond = null;
    if (acceptsTree(node.getCondition())) {
        cond = scan(node.getCondition(), p);
    }
    if (cond != null && cond.size() > 0 && statements != null && statements.size() > 0) {
        Tree lastCond = cond.get(cond.size() - 1);
        p.addNextExpression(lastCond, statements.get(0));
    }
    return reduce(statements, cond);
}
 
Example #9
Source File: ExpectedTypeResolver.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public List<? extends TypeMirror> visitDoWhileLoop(DoWhileLoopTree node, Object p) {
    if (theExpression == null) {
        initExpression(node.getCondition());
    } else if (theExpression.getLeaf() != node.getCondition()) {
        return null;
    }
    return booleanType();
}
 
Example #10
Source File: Flow.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
        public Boolean visitDoWhileLoop(DoWhileLoopTree node, ConstructorData p) {
            Map< Element, State> beforeLoop = variable2State;

            variable2State = new HashMap< Element, Flow.State>(beforeLoop);

            scan(node.getStatement(), null);
            Boolean condValue = scan(node.getCondition(), null);

            if (condValue != null) {
                if (condValue) {
                    //XXX: handle possibly infinite loop
                } else {
                    //will not run more than once, skip:
                    return null;
                }
            }

            variable2State = mergeOr(beforeLoop, variable2State);

            if (!doNotRecord) {
                boolean oldDoNotRecord = doNotRecord;
                doNotRecord = true;
                
                beforeLoop = new HashMap< Element, State>(variable2State);
                scan(node.getStatement(), null);
                scan(node.getCondition(), null);
                
                doNotRecord = oldDoNotRecord;
                variable2State = mergeOr(beforeLoop, variable2State);
//                variable2State = beforeLoop;
            }

            return null;
        }
 
Example #11
Source File: InfiniteRecursion.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public State visitDoWhileLoop(DoWhileLoopTree node, Void p) {
    State s;

    registerBreakTarget((node));
    if (returnIfRecurse(s = scan(node.getStatement(), p))) {
        return s;
    }
    returnIfRecurse(s = s.append(scan(node.getCondition(), p)));
    return s;
}
 
Example #12
Source File: CopyFinder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Boolean visitDoWhileLoop(DoWhileLoopTree node, TreePath p) {
    if (p == null) {
        super.visitDoWhileLoop(node, p);
        return false;
    }

    DoWhileLoopTree t = (DoWhileLoopTree) p.getLeaf();

    if (!scan(node.getStatement(), t.getStatement(), p))
        return false;

    return scan(node.getCondition(), t.getCondition(), p);
}
 
Example #13
Source File: TreeNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitDoWhileLoop(DoWhileLoopTree tree, List<Node> d) {
    List<Node> below = new ArrayList<Node>();
    
    addCorrespondingType(below);
    addCorrespondingComments(below);
    super.visitDoWhileLoop(tree, below);
    
    d.add(new TreeNode(info, getCurrentPath(), below));
    return null;
}
 
Example #14
Source File: DepthVisitor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Object visitDoWhileLoop(DoWhileLoopTree node, Object p) {
    depth++;
    Object o = super.visitDoWhileLoop(node, p); 
    depth--;
    return o;
}
 
Example #15
Source File: CyclomaticComplexityVisitor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Do-while loop adds: 
 * - no vertex, as it is a member of the linear code.
 * - an additional vertex for the code after the while
 * - one edge for unsatisfied condition that skips the cycle
 * - one edge for satisfied condition which at least re-evaluates the condition
 * - an additional vertex and an edge if the body contains a non-empty statement
 * = +1 to complexity
 */
@Override
public Object visitDoWhileLoop(DoWhileLoopTree node, Object p) {
    boolean saveFlag = switchCase;
    switchCase = false;
    complexity++;
    Object o = super.visitDoWhileLoop(node, p);
    this.switchCase = saveFlag;
    return o;
}
 
Example #16
Source File: MethodMetrics.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitDoWhileLoop(DoWhileLoopTree node, Object p) {
    loopCount++;
    return super.visitDoWhileLoop(node, p);
}
 
Example #17
Source File: UDoWhileLoop.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public Unifier visitDoWhileLoop(DoWhileLoopTree loop, @Nullable Unifier unifier) {
  unifier = getStatement().unify(loop.getStatement(), unifier);
  return getCondition().unify(loop.getCondition(), unifier);
}
 
Example #18
Source File: RefasterScanner.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public Void visitDoWhileLoop(DoWhileLoopTree node, Context context) {
  scan(node.getStatement(), context);
  scan(SKIP_PARENS.visit(node.getCondition(), null), context);
  return null;
}
 
Example #19
Source File: UTemplater.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public UDoWhileLoop visitDoWhileLoop(DoWhileLoopTree tree, Void v) {
  return UDoWhileLoop.create(template(tree.getStatement()), template(tree.getCondition()));
}
 
Example #20
Source File: VisitDoWhileLoopHook.java    From kan-java with Eclipse Public License 1.0 4 votes vote down vote up
void afterVisitCondition(DoWhileLoopTree node, List<ErrMsg> errMsgs, GlobalContext globalCtx, Closure<List<Map<String, Long>>> resolveRowAndCol,
Closure<Void> setError);
 
Example #21
Source File: VisitDoWhileLoopHook.java    From kan-java with Eclipse Public License 1.0 4 votes vote down vote up
void afterVisitStatementAndBeforeCondition(DoWhileLoopTree node, List<ErrMsg> errMsgs, GlobalContext globalCtx,
Closure<List<Map<String, Long>>> resolveRowAndCol, Closure<Void> setError);
 
Example #22
Source File: VisitDoWhileLoopHook.java    From kan-java with Eclipse Public License 1.0 4 votes vote down vote up
void beforeVisitStatement(DoWhileLoopTree node, List<ErrMsg> errMsgs, GlobalContext globalCtx, Closure<List<Map<String, Long>>> resolveRowAndCol,
Closure<Void> setError);
 
Example #23
Source File: TreeConverter.java    From j2objc with Apache License 2.0 4 votes vote down vote up
private TreeNode convertDoStatement(DoWhileLoopTree node, TreePath parent) {
  TreePath path = getTreePath(parent, node);
  return new DoStatement()
      .setExpression(convertWithoutParens(node.getCondition(), path))
      .setBody((Statement) convert(node.getStatement(), path));
}
 
Example #24
Source File: LocalVarScanner.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean visitDoWhileLoop(DoWhileLoopTree node, Element p) {
    return null;
}
 
Example #25
Source File: Braces.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void performRewrite(TransformationContext ctx) {
    WorkingCopy copy = ctx.getWorkingCopy();
    TreePath path = ctx.getPath();
    if ( path != null ) {

        TreeMaker make = copy.getTreeMaker();
        Tree oldTree = path.getLeaf();

        oldTree = GeneratorUtilities.get(copy).importComments(oldTree, copy.getCompilationUnit());

        switch( oldTree.getKind() ) {
        case FOR_LOOP:
            ForLoopTree oldFor = (ForLoopTree)oldTree;
            StatementTree oldBlock = oldFor.getStatement();
            BlockTree newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
            copy.rewrite(oldBlock, newBlock);
            break;
        case ENHANCED_FOR_LOOP:
            EnhancedForLoopTree oldEnhancedFor = (EnhancedForLoopTree)oldTree;
            oldBlock = oldEnhancedFor.getStatement();
            newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
            copy.rewrite(oldBlock, newBlock);
            break;
        case WHILE_LOOP:
            WhileLoopTree oldWhile = (WhileLoopTree)oldTree;
            oldBlock = oldWhile.getStatement();
            newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
            copy.rewrite(oldBlock, newBlock);
            break;
        case DO_WHILE_LOOP:
            DoWhileLoopTree oldDoWhile = (DoWhileLoopTree)oldTree;
            oldBlock = oldDoWhile.getStatement();
            newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
            copy.rewrite(oldBlock, newBlock);
            break;
        case IF:
            IfTree oldIf = (IfTree)oldTree;
            if ( fixThen ) {
                oldBlock = oldIf.getThenStatement();
                newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
                copy.rewrite(oldBlock, newBlock);
            }
            if ( fixElse ) {
                oldBlock = oldIf.getElseStatement();
                newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
                copy.rewrite(oldBlock, newBlock);
            }

        }
    }
}
 
Example #26
Source File: NCLOCVisitor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Object visitDoWhileLoop(DoWhileLoopTree node, Object p) {
    statements++;
    return super.visitDoWhileLoop(node, p);
}
 
Example #27
Source File: CanInterpretVisitor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean visitDoWhileLoop(DoWhileLoopTree node, EvaluationContext p) {
    return Boolean.FALSE;
}
 
Example #28
Source File: Utilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean visitDoWhileLoop(DoWhileLoopTree node, Void p) {
    return scan(node.getStatement(), p);
}
 
Example #29
Source File: Flow.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Boolean visitContinue(ContinueTree node, ConstructorData p) {
    StatementTree loop = info.getTreeUtilities().getBreakContinueTarget(getCurrentPath());

    if (loop == null) {
        super.visitContinue(node, p);
        return null;
    }

    Tree resumePoint;

    if (loop.getKind() == Kind.LABELED_STATEMENT) {
        loop = ((LabeledStatementTree) loop).getStatement();
    }
    
    switch (loop.getKind()) {
        case WHILE_LOOP:
            resumePoint = ((WhileLoopTree) loop).getCondition();
            break;
        case FOR_LOOP: {
                ForLoopTree flt = (ForLoopTree)loop;
                resumePoint = null;
                if (flt.getUpdate() != null && !flt.getUpdate().isEmpty()) {
                    // resume will react on the 1st Tree of the update statement (always processed left to right)
                    resumePoint = flt.getUpdate().get(0);
                } 
                if (resumePoint == null) {
                    resumePoint = flt.getCondition();
                }
                if (resumePoint == null) {
                    resumePoint = flt.getStatement();
                }
        }
            break;
        case DO_WHILE_LOOP:
            resumePoint = ((DoWhileLoopTree) loop).getCondition();
            break;
        case ENHANCED_FOR_LOOP:
            resumePoint = ((EnhancedForLoopTree) loop).getStatement();
            break;
        default:
            resumePoint = null;
            break;
    }

    if (resumePoint != null) {
        recordResume(resumeBefore, resumePoint, variable2State);
    }

    variable2State = new HashMap< Element, State>();

    super.visitContinue(node, p);
    return null;
}
 
Example #30
Source File: Braces.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Hint(displayName="#LBL_Braces_DoWhile", description="#DSC_Braces_DoWhile", category="braces", id=BRACES_ID + "DO_WHILE_LOOP", enabled=false, suppressWarnings={"", "ControlFlowStatementWithoutBraces"})
@TriggerTreeKind(Tree.Kind.DO_WHILE_LOOP)
public static ErrorDescription checkDoWhile(HintContext ctx) {
    DoWhileLoopTree dwlt = (DoWhileLoopTree) ctx.getPath().getLeaf();
    return checkStatement(ctx, "LBL_Braces_DoWhile", dwlt.getStatement(), ctx.getPath());
}