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

项目:incubator-netbeans    文件:CasualDiff.java   
protected int diffSwitch(JCSwitch oldT, JCSwitch newT, int[] bounds) {
    int localPointer = bounds[0];

    // rename in switch
    int[] selectorBounds = getBounds(oldT.selector);
    copyTo(localPointer, selectorBounds[0]);
    localPointer = diffTree(oldT.selector, newT.selector, selectorBounds);

    tokenSequence.move(selectorBounds[1]);
    do { } while (tokenSequence.moveNext() && JavaTokenId.LBRACE != tokenSequence.token().id());
    tokenSequence.moveNext();
    copyTo(localPointer, localPointer = tokenSequence.offset());
    PositionEstimator est = EstimatorFactory.cases(oldT.getCases(), newT.getCases(), diffContext);
    localPointer = diffList(oldT.cases, newT.cases, localPointer, est, Measure.MEMBER, printer);

    copyTo(localPointer, bounds[1]);
    return bounds[1];
}
项目:EasyMPermission    文件:PrettyCommentsPrinter.java   
public void visitSwitch(JCSwitch tree) {
    try {
        print("switch ");
        if (PARENS.equals(treeTag(tree.selector))) {
            printExpr(tree.selector);
        } else {
            print("(");
            printExpr(tree.selector);
            print(")");
        }
        print(" {");
        println();
        printStats(tree.cases);
        align();
        print("}");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:s4j    文件:Pretty.java   
public void visitSwitch(JCSwitch tree) {
    try {
        print("switch ");
        if (tree.selector.getTag() == JCTree.PARENS) {
            printExpr(tree.selector);
        } else {
            print("(");
            printExpr(tree.selector);
            print(")");
        }
        print(" {");
        println();
        printStats(tree.cases);
        align();
        print("}");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:lombok    文件:PrettyCommentsPrinter.java   
public void visitSwitch(JCSwitch tree) {
    try {
        print("switch ");
        if (getTag(tree.selector) == PARENS) {
            printExpr(tree.selector);
        } else {
            print("(");
            printExpr(tree.selector);
            print(")");
        }
        print(" {");
        println();
        printStats(tree.cases);
        align();
        print("}");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:lombok-ianchiu    文件:PrettyPrinter.java   
@Override public void visitSwitch(JCSwitch tree) {
    aPrint("switch ");
    if (tree.selector instanceof JCParens) {
        print(tree.selector);
    } else {
        print("(");
        print(tree.selector);
        print(")");
    }
    println(" {");
    print(tree.cases, "\n");
    aPrintln("}", tree);
}
项目:javaparser2jctree    文件:PrintAstVisitor.java   
public void visitSwitch(JCSwitch that) {
    try {
        print("JCSwitch:");
    } catch (Exception e) {
    }
    super.visitSwitch(that);
}
项目:android-retrolambda-lombok    文件:JcTreeConverter.java   
@Override public void visitSwitch(JCSwitch node) {
    Switch s = new Switch();
    JCExpression cond = node.getExpression();
    setConversionPositionInfo(s, "()", getPosition(cond));
    s.rawCondition(toTree(removeParens(cond)));
    Block b = new Block();
    s.astBody(b);
    for (JCCase c : node.getCases()) {
        JCExpression rawExpr = c.getExpression();
        if (rawExpr == null) b.rawContents().addToEnd(setPos(c, new Default()));
        else b.rawContents().addToEnd(setPos(c, new Case().rawCondition(toTree(rawExpr))));
        fillList(c.getStatements(), b.rawContents());
    }
    set(node, s);
}
项目:error-prone    文件:PlaceholderUnificationVisitor.java   
@Override
public Choice<State<JCSwitch>> visitSwitch(final SwitchTree node, State<?> state) {
  return chooseSubtrees(
      state,
      s -> unifyExpression(node.getExpression(), s),
      s -> unify(node.getCases(), s),
      (expr, cases) -> maker().Switch(expr, List.convert(JCCase.class, cases)));
}
项目:incubator-netbeans    文件:CasualDiff.java   
private boolean matchSwitch(JCSwitch t1, JCSwitch t2) {
    return treesMatch(t1.selector, t2.selector) && listsMatch(t1.cases, t2.cases);
}
项目:openjdk-jdk10    文件:Analyzer.java   
@Override
public void visitSwitch(JCSwitch tree) {
    scan(tree.getExpression());
}
项目:openjdk9    文件:Analyzer.java   
@Override
public void visitSwitch(JCSwitch tree) {
    scan(tree.getExpression());
}
项目:lombok-ianchiu    文件:JavacTreeMaker.java   
public JCSwitch Switch(JCExpression selector, List<JCCase> cases) {
    return invoke(Switch, selector, cases);
}
项目:javaparser2jctree    文件:AJCSwitch.java   
public AJCSwitch(JCSwitch ltree) {
    super(ltree.selector, ltree.cases);
}
项目:javaparser2jctree    文件:AJCSwitch.java   
public AJCSwitch(JCSwitch ltree, String lcomment) {
    this(ltree);
    setComment(lcomment);
}
项目:EasyMPermission    文件:JavacTreeMaker.java   
public JCSwitch Switch(JCExpression selector, List<JCCase> cases) {
    return invoke(Switch, selector, cases);
}
项目:android-retrolambda-lombok    文件:JcTreePrinter.java   
@Override public void visitSwitch(JCSwitch tree) {
    printNode(tree);
    child("selector", tree.selector);
    children("cases", tree.cases);
    indent--;
}
项目:s4j    文件:Attr.java   
public void visitSwitch(JCSwitch tree) {
    Type seltype = attribExpr(tree.selector, env);

    Env<AttrContext> switchEnv =
        env.dup(tree, env.info.dup(env.info.scope.dup()));

    boolean enumSwitch =
        allowEnums &&
        (seltype.tsym.flags() & Flags.ENUM) != 0;
    boolean stringSwitch = false;
    if (types.isSameType(seltype, syms.stringType)) {
        if (allowStringsInSwitch) {
            stringSwitch = true;
        } else {
            log.error(tree.selector.pos(), "string.switch.not.supported.in.source", sourceName);
        }
    }
    if (!enumSwitch && !stringSwitch)
        seltype = chk.checkType(tree.selector.pos(), seltype, syms.intType);

    // Attribute all cases and
    // check that there are no duplicate case labels or default clauses.
    Set<Object> labels = new HashSet<Object>(); // The set of case labels.
    boolean hasDefault = false;      // Is there a default label?
    for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) {
        JCCase c = l.head;
        Env<AttrContext> caseEnv =
            switchEnv.dup(c, env.info.dup(switchEnv.info.scope.dup()));
        if (c.pat != null) {
            if (enumSwitch) {
                Symbol sym = enumConstant(c.pat, seltype);
                if (sym == null) {
                    log.error(c.pat.pos(), "enum.label.must.be.unqualified.enum");
                } else if (!labels.add(sym)) {
                    log.error(c.pos(), "duplicate.case.label");
                }
            } else {
                Type pattype = attribExpr(c.pat, switchEnv, seltype);
                if (pattype.tag != ERROR) {
                    if (pattype.constValue() == null) {
                        log.error(c.pat.pos(),
                                  (stringSwitch ? "string.const.req" : "const.expr.req"));
                    } else if (labels.contains(pattype.constValue())) {
                        log.error(c.pos(), "duplicate.case.label");
                    } else {
                        labels.add(pattype.constValue());
                    }
                }
            }
        } else if (hasDefault) {
            log.error(c.pos(), "duplicate.default.label");
        } else {
            hasDefault = true;
        }
        attribStats(c.stats, caseEnv);
        caseEnv.info.scope.leave();
        addVars(c.stats, switchEnv.info.scope);
    }

    switchEnv.info.scope.leave();
    result = null;
}