com.sun.tools.javac.tree.JCTree.JCSwitch Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCSwitch. 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: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitSwitch(JCSwitch tree) {
    ListBuffer<PendingExit> prevPendingExits = pendingExits;
    pendingExits = new ListBuffer<>();
    scan(tree.selector);
    boolean hasDefault = false;
    for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) {
        alive = true;
        JCCase c = l.head;
        if (c.pat == null)
            hasDefault = true;
        else
            scan(c.pat);
        scanStats(c.stats);
        // Warn about fall-through if lint switch fallthrough enabled.
        if (alive &&
            lint.isEnabled(Lint.LintCategory.FALLTHROUGH) &&
            c.stats.nonEmpty() && l.tail.nonEmpty())
            log.warning(Lint.LintCategory.FALLTHROUGH,
                        l.tail.head.pos(),
                        Warnings.PossibleFallThroughIntoCase);
    }
    if (!hasDefault) {
        alive = true;
    }
    alive |= resolveBreaks(tree, prevPendingExits);
}
 
Example #2
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void visitSwitch(JCSwitch tree) {
    Type selsuper = types.supertype(tree.selector.type);
    boolean enumSwitch = selsuper != null &&
        (tree.selector.type.tsym.flags() & ENUM) != 0;
    boolean stringSwitch = selsuper != null &&
        types.isSameType(tree.selector.type, syms.stringType);
    Type target = enumSwitch ? tree.selector.type :
        (stringSwitch? syms.stringType : syms.intType);
    tree.selector = translate(tree.selector, target);
    tree.cases = translateCases(tree.cases);
    if (enumSwitch) {
        result = visitEnumSwitch(tree);
    } else if (stringSwitch) {
        result = visitStringSwitch(tree);
    } else {
        result = tree;
    }
}
 
Example #3
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 6 votes vote down vote up
private SwitchStatement convertSwitch(JCSwitch switchStatement) {

    return SwitchStatement.newBuilder()
        .setSourcePosition(getSourcePosition(switchStatement))
        .setSwitchExpression(convertExpressionOrNull(switchStatement.getExpression()))
        .setCases(
            switchStatement.getCases().stream()
                .map(
                    caseClause ->
                        SwitchCase.newBuilder()
                            .setCaseExpression(convertExpressionOrNull(caseClause.getExpression()))
                            .setStatements(convertStatements(caseClause.getStatements()))
                            .build())
                .collect(toImmutableList()))
        .build();
  }
 
Example #4
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 6 votes vote down vote up
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);
	}
}
 
Example #5
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitSwitch(JCSwitch tree) {
    Type selsuper = types.supertype(tree.selector.type);
    boolean enumSwitch = selsuper != null &&
        selsuper.tsym == syms.enumSym;
    Type target = enumSwitch ? erasure(tree.selector.type) : syms.intType;
    tree.selector = translate(tree.selector, target);
    tree.cases = translateCases(tree.cases);
    result = tree;
}
 
Example #6
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitSwitch(JCSwitch tree) {
    ListBuffer<FlowPendingExit> prevPendingExits = pendingExits;
    pendingExits = new ListBuffer<>();
    scan(tree.selector);
    for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) {
        JCCase c = l.head;
        if (c.pat != null) {
            scan(c.pat);
        }
        scan(c.stats);
    }
    resolveBreaks(tree, prevPendingExits);
}
 
Example #7
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void visitSwitch(JCSwitch tree) {
    ListBuffer<AssignPendingExit> prevPendingExits = pendingExits;
    pendingExits = new ListBuffer<>();
    int nextadrPrev = nextadr;
    scanExpr(tree.selector);
    final Bits initsSwitch = new Bits(inits);
    final Bits uninitsSwitch = new Bits(uninits);
    boolean hasDefault = false;
    for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) {
        inits.assign(initsSwitch);
        uninits.assign(uninits.andSet(uninitsSwitch));
        JCCase c = l.head;
        if (c.pat == null) {
            hasDefault = true;
        } else {
            scanExpr(c.pat);
        }
        if (hasDefault) {
            inits.assign(initsSwitch);
            uninits.assign(uninits.andSet(uninitsSwitch));
        }
        scan(c.stats);
        addVars(c.stats, initsSwitch, uninitsSwitch);
        if (!hasDefault) {
            inits.assign(initsSwitch);
            uninits.assign(uninits.andSet(uninitsSwitch));
        }
        // Warn about fall-through if lint switch fallthrough enabled.
    }
    if (!hasDefault) {
        inits.andSet(initsSwitch);
    }
    resolveBreaks(tree, prevPendingExits);
    nextadr = nextadrPrev;
}
 
Example #8
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void visitSwitch(JCSwitch tree) {
    SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
    sr.mergeWith(csp(tree.selector));
    sr.mergeWith(cspCases(tree.cases));
    result = sr;
}
 
Example #9
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void visitSwitch(JCSwitch tree) {
    scan(tree.getExpression());
}
 
Example #10
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
private Statement convertStatement(JCStatement jcStatement) {
  switch (jcStatement.getKind()) {
    case ASSERT:
      return convertAssert((JCAssert) jcStatement);
    case BLOCK:
      return convertBlock((JCBlock) jcStatement);
    case BREAK:
      return convertBreak((JCBreak) jcStatement);
    case CLASS:
      convertClassDeclaration((JCClassDecl) jcStatement);
      return null;
    case CONTINUE:
      return convertContinue((JCContinue) jcStatement);
    case DO_WHILE_LOOP:
      return convertDoWhileLoop((JCDoWhileLoop) jcStatement);
    case EMPTY_STATEMENT:
      return new EmptyStatement(getSourcePosition(jcStatement));
    case ENHANCED_FOR_LOOP:
      return convertEnhancedForLoop((JCEnhancedForLoop) jcStatement);
    case EXPRESSION_STATEMENT:
      return convertExpressionStatement((JCExpressionStatement) jcStatement);
    case FOR_LOOP:
      return convertForLoop((JCForLoop) jcStatement);
    case IF:
      return convertIf((JCIf) jcStatement);
    case LABELED_STATEMENT:
      return convertLabeledStatement((JCLabeledStatement) jcStatement);
    case RETURN:
      return convertReturn((JCReturn) jcStatement);
    case SWITCH:
      return convertSwitch((JCSwitch) jcStatement);
    case THROW:
      return convertThrow((JCThrow) jcStatement);
    case TRY:
      return convertTry((JCTry) jcStatement);
    case VARIABLE:
      return convertVariableDeclaration((JCVariableDecl) jcStatement);
    case WHILE_LOOP:
      return convertWhileLoop((JCWhileLoop) jcStatement);
    case SYNCHRONIZED:
      return convertSynchronized((JCSynchronized) jcStatement);
    default:
      throw new AssertionError("Unknown statement node type: " + jcStatement.getKind());
  }
}
 
Example #11
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visitSwitch(JCSwitch tree) {
    scan(tree.getExpression());
}
 
Example #12
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCSwitch Switch(JCExpression selector, List<JCCase> cases) {
	return invoke(Switch, selector, cases);
}