Java 类com.sun.tools.javac.tree.JCTree.JCForLoop 实例源码

项目:java-code-templates    文件:AstSubstitutionProcessor.java   
@Override
public void visitForLoop(final JCForLoop node) {
    print("for (");
    if (node.init.nonEmpty()) {
        if (node.init.head instanceof JCVariableDecl) {
            handleVarDef((JCVariableDecl)node.init.head, false);
            for (List<JCStatement> l = node.init.tail; l.nonEmpty(); l = l.tail) {
                final JCVariableDecl decl = (JCVariableDecl)l.head;
                print(", " + decl.name + " = ");
                printExpr(decl.init);
            }
        } else {
            printExprs(node.init);
        }
    }

    print("; ");
    if (node.cond != null) {
        printExpr(node.cond);
    }

    print("; ");
    printExprs(node.step);
    print(") ");
    printStat(node.body);
}
项目:EasyMPermission    文件:PrettyCommentsPrinter.java   
public void visitForLoop(JCForLoop tree) {
    try {
        print("for (");
        if (tree.init.nonEmpty()) {
            if (VARDEF.equals(treeTag(tree.init.head))) {
                printExpr(tree.init.head);
                for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) {
                    JCVariableDecl vdef = (JCVariableDecl)l.head;
                    print(", " + vdef.name + " = ");
                    printExpr(vdef.init);
                }
            } else {
                printExprs(tree.init);
            }
        }
        print("; ");
        if (tree.cond != null) printExpr(tree.cond);
        print("; ");
        printExprs(tree.step);
        print(") ");
        printStat(tree.body);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:s4j    文件:Pretty.java   
public void visitForLoop(JCForLoop tree) {
    try {
        print("for (");
        if (tree.init.nonEmpty()) {
            if (tree.init.head.getTag() == JCTree.VARDEF) {
                printExpr(tree.init.head);
                for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) {
                    JCVariableDecl vdef = (JCVariableDecl)l.head;
                    print(", " + vdef.name + " = ");
                    printExpr(vdef.init);
                }
            } else {
                printExprs(tree.init);
            }
        }
        print("; ");
        if (tree.cond != null) printExpr(tree.cond);
        print("; ");
        printExprs(tree.step);
        print(") ");
        printStat(tree.body);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:lombok    文件:PrettyCommentsPrinter.java   
public void visitForLoop(JCForLoop tree) {
    try {
        print("for (");
        if (tree.init.nonEmpty()) {
            if (getTag(tree.init.head) == VARDEF) {
                printExpr(tree.init.head);
                for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) {
                    JCVariableDecl vdef = (JCVariableDecl)l.head;
                    print(", " + vdef.name + " = ");
                    printExpr(vdef.init);
                }
            } else {
                printExprs(tree.init);
            }
        }
        print("; ");
        if (tree.cond != null) printExpr(tree.cond);
        print("; ");
        printExprs(tree.step);
        print(") ");
        printStat(tree.body);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:javaparser2jctree    文件:PrintAstVisitor.java   
public void visitForLoop(JCForLoop that) {
    try {
        print("JCForLoop:");
    } catch (Exception e) {
    }
    super.visitForLoop(that);
}
项目:refactor-faster    文件:UForLoop.java   
@Override
public JCForLoop inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().ForLoop(
      inliner.inlineList(getInitializer()),
      (getCondition() == null) ? null : getCondition().inline(inliner), 
      com.sun.tools.javac.util.List.convert(
          JCExpressionStatement.class, inliner.inlineList(getUpdate())), 
      getStatement().inline(inliner));
}
项目:android-retrolambda-lombok    文件:JcTreePrinter.java   
@Override public void visitForLoop(JCForLoop tree) {
    printNode(tree);
    children("init", tree.init);
    child("cond", tree.cond);
    children("step", tree.step);
    child("body", tree.body);
    indent--;
}
项目:android-retrolambda-lombok    文件:JcTreeConverter.java   
@Override public void visitForLoop(JCForLoop node) {
    For f = new For();
    f.rawCondition(toTree(node.getCondition()));
    f.rawStatement(toTree(node.getStatement()));
    for (JCExpressionStatement upd : node.getUpdate()) {
        Node updateNode = toTree(upd.getExpression());
        setConversionPositionInfo(updateNode, "exec", getPosition(upd));
        f.rawUpdates().addToEnd(updateNode);
    }
    List<JCStatement> initializers = node.getInitializer();
    // Multiple vardefs in a row need to trigger the JCVD version AND be washed through fillList to be turned into 1 VD.
    if (!initializers.isEmpty() && initializers.get(0) instanceof JCVariableDecl) {
        Block tmp = new Block();
        fillList(initializers, tmp.rawContents(), FlagKey.VARDEF_IS_DEFINITION);
        Node varDecl = tmp.rawContents().first();
        if (varDecl != null) varDecl.unparent();
        f.rawVariableDeclaration(varDecl);
    } else {
        for (JCStatement init : initializers) {
            if (init instanceof JCExpressionStatement) {
                Node initNode = toTree(((JCExpressionStatement) init).getExpression());
                setConversionPositionInfo(initNode, "exec", getPosition(init));
                f.rawExpressionInits().addToEnd(initNode);
            } else {
                f.rawExpressionInits().addToEnd(toTree(init));
            }
        }
    }
    set(node, f);
}
项目:error-prone    文件:PlaceholderUnificationVisitor.java   
@Override
public Choice<State<JCForLoop>> visitForLoop(final ForLoopTree node, State<?> state) {
  return chooseSubtrees(
      state,
      s -> unifyStatements(node.getInitializer(), s),
      s -> unifyExpression(node.getCondition(), s),
      s -> unifyStatements(node.getUpdate(), s),
      s -> unifyStatement(node.getStatement(), s),
      (inits, cond, update, stmt) ->
          maker().ForLoop(inits, cond, List.convert(JCExpressionStatement.class, update), stmt));
}
项目:error-prone    文件:UForLoop.java   
@Override
public JCForLoop inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner
      .maker()
      .ForLoop(
          UBlock.inlineStatementList(getInitializer(), inliner),
          (getCondition() == null) ? null : getCondition().inline(inliner),
          com.sun.tools.javac.util.List.convert(
              JCExpressionStatement.class, inliner.<JCStatement>inlineList(getUpdate())),
          getStatement().inline(inliner));
}
项目:s4j    文件:Attr.java   
public void visitForLoop(JCForLoop tree) {
    Env<AttrContext> loopEnv =
        env.dup(env.tree, env.info.dup(env.info.scope.dup()));
    attribStats(tree.init, loopEnv);
    if (tree.cond != null) attribExpr(tree.cond, loopEnv, syms.booleanType);
    loopEnv.tree = tree; // before, we were not in loop!
    attribStats(tree.step, loopEnv);
    attribStat(tree.body, loopEnv);
    loopEnv.info.scope.leave();
    result = null;
}
项目:Refaster    文件:UForLoop.java   
@Override
public JCForLoop inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().ForLoop(
      inliner.inlineList(getInitializer()),
      (getCondition() == null) ? null : getCondition().inline(inliner), 
      com.sun.tools.javac.util.List.convert(
          JCExpressionStatement.class, inliner.inlineList(getUpdate())), 
      getStatement().inline(inliner));
}
项目:incubator-netbeans    文件:CasualDiff.java   
protected int diffForLoop(JCForLoop oldT, JCForLoop newT, int[] bounds) {
    int localPointer;

    // initializer
    if (oldT.init.nonEmpty()) {
        // there is something in the init section, using start offset
        localPointer = getOldPos(oldT.init.head);
    } else {
        moveFwdToToken(tokenSequence, bounds[0], JavaTokenId.SEMICOLON);
        localPointer = tokenSequence.offset();
    }
    copyTo(bounds[0], localPointer);
    if (!listsMatch(oldT.init, newT.init)) {
        boolean oldVariable = containsVariable(oldT.init);
        boolean newVariable = containsVariable(newT.init);

        if (oldVariable ^ newVariable) {
            int oldPrec = printer.setPrec(TreeInfo.noPrec);
            localPointer = diffParameterList(oldT.init, newT.init, null, localPointer, Measure.ARGUMENT);
            printer.setPrec(oldPrec);
        } else {
            if (oldVariable) {
                List<JCVariableDecl> oldInit = NbCollections.checkedListByCopy(oldT.init, JCVariableDecl.class, false);
                FieldGroupTree old = new FieldGroupTree(oldInit);
                List<JCVariableDecl> newInit = NbCollections.checkedListByCopy(newT.init, JCVariableDecl.class, false);
                FieldGroupTree nue = new FieldGroupTree(newInit);
                int[] initBounds = getBounds(oldT.init.head);

                JCTree last = oldT.init.get(oldT.init.size() - 1);

                long endPos = diffContext.trees.getSourcePositions().getEndPosition(oldTopLevel, last);

                initBounds[1] = (int) endPos;
                localPointer = diffTree(old, nue, initBounds);
            } else {
                localPointer = diffParameterList(oldT.init, newT.init, null, localPointer, Measure.ARGUMENT);
            }
        }
    }

    // condition
    if (oldT.cond != null) {
        copyTo(localPointer, localPointer = getOldPos(oldT.cond));
        localPointer = diffTree(oldT.cond, newT.cond, getBounds(oldT.cond));
    } else {
        moveFwdToToken(tokenSequence, localPointer, JavaTokenId.SEMICOLON);
        copyTo(localPointer, localPointer = tokenSequence.offset());
    }

    // steps
    if (oldT.step.nonEmpty())
        copyTo(localPointer, localPointer = getOldPos(oldT.step.head));
    else {
        moveFwdToToken(tokenSequence, localPointer, JavaTokenId.SEMICOLON);
        tokenSequence.moveNext();
        copyTo(localPointer, localPointer = tokenSequence.offset());
    }
    localPointer = diffParameterList(oldT.step, newT.step, null, localPointer, Measure.ARGUMENT);

    // body
    int[] bodyBounds = new int[] { localPointer, endPos(oldT.body) };
    int oldIndent = newT.body.hasTag(Tag.BLOCK) ? -1 : printer.indent();
    localPointer = diffTree(oldT.body, newT.body, bodyBounds, oldT.getKind());
    if (!newT.body.hasTag(Tag.BLOCK))
        printer.undent(oldIndent);

    copyTo(localPointer, bounds[1]);
    return bounds[1];
}
项目:incubator-netbeans    文件:CasualDiff.java   
private boolean matchForLoop(JCForLoop t1, JCForLoop t2) {
    return listsMatch(t1.init, t2.init) && treesMatch(t1.cond, t2.cond) &&
           listsMatch(t1.step, t2.step) && treesMatch(t1.body, t2.body);
}
项目:openjdk-jdk10    文件:Analyzer.java   
@Override
public void visitForLoop(JCForLoop tree) {
    //skip body and var decl (to prevents same statements to be analyzed twice)
    scan(tree.getCondition());
    scan(tree.getUpdate());
}
项目:openjdk9    文件:Analyzer.java   
@Override
public void visitForLoop(JCForLoop tree) {
    scan(tree.getInitializer());
    scan(tree.getCondition());
    scan(tree.getUpdate());
}
项目:lombok-ianchiu    文件:JavacTreeMaker.java   
public JCForLoop ForLoop(List<JCStatement> init, JCExpression cond, List<JCExpressionStatement> step, JCStatement body) {
    return invoke(ForLoop, init, cond, step, body);
}
项目:javaparser2jctree    文件:AJCForLoop.java   
public AJCForLoop(JCForLoop ltree) {
    super(ltree.init, ltree.cond, ltree.step, ltree.body);
}
项目:javaparser2jctree    文件:AJCForLoop.java   
public AJCForLoop(JCForLoop ltree, String lcomment) {
    this(ltree);
    setComment(lcomment);
}
项目:EasyMPermission    文件:JavacTreeMaker.java   
public JCForLoop ForLoop(List<JCStatement> init, JCExpression cond, List<JCExpressionStatement> step, JCStatement body) {
    return invoke(ForLoop, init, cond, step, body);
}