Example usage for org.eclipse.jdt.core.dom SwitchCase isDefault

List of usage examples for org.eclipse.jdt.core.dom SwitchCase isDefault

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom SwitchCase isDefault.

Prototype

public boolean isDefault() 

Source Link

Document

Returns whether this switch case represents the "default:" case.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(SwitchCase node) {
    if (node.isDefault()) {
        this.fBuffer.append("default :");//$NON-NLS-1$
    } else {/*from  w  ww.  ja v  a 2s .  c  om*/
        this.fBuffer.append("case ");//$NON-NLS-1$
        node.getExpression().accept(this);
        this.fBuffer.append(":");//$NON-NLS-1$
    }
    return false;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(SwitchCase node) {
    if (node.isDefault()) {
        this.buffer.append("default :\n");//$NON-NLS-1$
    } else {//from ww w .java 2s  .com
        this.buffer.append("case ");//$NON-NLS-1$
        node.getExpression().accept(this);
        this.buffer.append(":\n");//$NON-NLS-1$
    }
    this.indent++; // decremented in visit(SwitchStatement)
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public boolean visit(SwitchCase node) {
    if (node.isDefault()) {
        handleToken(node, TokenNameCOLON, this.options.insert_space_before_colon_in_default, false);
    } else {//from   ww  w . j  a v a  2 s. c  om
        handleToken(node, TokenNamecase, false, true);
        handleToken(node.getExpression(), TokenNameCOLON, this.options.insert_space_before_colon_in_case,
                false);
    }
    return true;
}

From source file:com.chookapp.org.bracketeer.jdt.ClosingBracketHintVisitor.java

License:Open Source License

@Override
public boolean visit(SwitchCase node) {
    /* TODO: specific params: don't show the switch part (only the case argument) */

    try {//from   ww w.j  a va  2 s. co m
        ScopeInfo scope = _scopeStack.peek();
        if (!(scope._statement instanceof SwitchStatement)) {
            if (!(scope._statement instanceof SwitchCase)) {
                throw new ScopeTraceException("Lost track of stack (in case), found:" + scope._statement); //$NON-NLS-1$
            }

            _scopeStack.pop();
            scope = _scopeStack.peek();
        }

        if (!(scope._statement instanceof SwitchStatement)) {
            throw new ScopeTraceException("Lost track of stack (in case2), found:" + scope._statement); //$NON-NLS-1$
        }

        String hint = ""; //$NON-NLS-1$
        if (node.isDefault()) {
            hint = "default"; //$NON-NLS-1$
        } else {
            hint = "case: " + node.getExpression(); //$NON-NLS-1$
        }

        int startLoc = node.getStartPosition();
        _scopeStack.push(new ScopeInfo(scope._str + " - " + hint, startLoc, node)); //$NON-NLS-1$
    } catch (ScopeTraceException e) {
        if (Activator.DEBUG)
            Activator.log(e);
    } catch (EmptyStackException e) {
        if (Activator.DEBUG)
            Activator.log(e);
    }

    return shouldContinue();
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

@Override
public boolean visit(SwitchCase node) {
    if (node.isDefault()) {
        buffer.append("  default:");
    } else {//from  w w w  .j  a  v  a 2s .com
        buffer.append("  case ");
        Expression expr = node.getExpression();
        boolean isEnumConstant = Types.getTypeBinding(expr).isEnum();
        if (isEnumConstant) {
            String bareTypeName = NameTable.getFullName(Types.getTypeBinding(expr)).replace("Enum", "");
            buffer.append(bareTypeName).append("_");
        }
        if (isEnumConstant && expr instanceof SimpleName) {
            buffer.append(((SimpleName) expr).getIdentifier());
        } else if (isEnumConstant && expr instanceof QualifiedName) {
            buffer.append(((QualifiedName) expr).getName().getIdentifier());
        } else {
            expr.accept(this);
        }
        buffer.append(":");
    }
    return false;
}

From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(SwitchCase node) {
    if (node.isDefault()) {
        sb.println("default :");
    } else {//w w w  . j  a  v  a 2s  .  c  o  m
        sb.print("case ");
        node.getExpression().accept(this);
        sb.println(":");
    }
    sb.indent();
    return false;
}

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link SwitchCase}s. */
@Override/*  w w w . j a  v a 2 s  .  c o m*/
public boolean visit(SwitchCase node) {
    sync(node);
    markForPartialFormat();
    if (node.isDefault()) {
        token("default", plusTwo);
        token(":");
    } else {
        token("case", plusTwo);
        builder.space();
        node.getExpression().accept(this);
        token(":");
    }
    return false;
}

From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java

License:Open Source License

private CAstNode visit(SwitchStatement n, WalkContext context) {
    ASTNode breakTarget = makeBreakOrContinueTarget(n, "breakLabel" + n.getStartPosition());
    CAstNode breakAst = visitNode(breakTarget, context);
    String loopLabel = (String) context.getLabelMap().get(n); // set by labeled statement (if there is one before this
    // switch statement)
    WalkContext childContext = new BreakContext(context, loopLabel, breakTarget);
    Expression cond = n.getExpression();
    List/* <Statement> */ cases = n.statements();

    // First compute the control flow edges for the various case labels
    for (int i = 0; i < cases.size(); i++) {
        Statement se = (Statement) cases.get(i);
        if (se instanceof SwitchCase) {
            SwitchCase c = (SwitchCase) se;

            if (c.isDefault())
                context.cfg().add(n, c, CAstControlFlowMap.SWITCH_DEFAULT);
            else/*from w w w  .j  av  a  2s . c o m*/
                context.cfg().add(n, c, getSwitchCaseConstant(c, context));
            // if we don't do this, we may not get a constant but a
            // block expression or something else
        }
    }

    ArrayList<CAstNode> caseNodes = new ArrayList<CAstNode>();

    // polyglot bundles all statements in between two statements into a block.
    // this is temporary place to hold current bundle of nodes.
    ArrayList<CAstNode> currentBlock = new ArrayList<CAstNode>();

    // Now produce the CAst representation for each case
    for (Object o : cases) {
        Statement s = (Statement) o;
        if (s instanceof SwitchCase) {
            if (!currentBlock.isEmpty()) {
                // bundle up statements before this case
                CAstNode stmtNodes[] = currentBlock.toArray(new CAstNode[currentBlock.size()]);
                // make position from start of first statement to end of last statement
                T positionOfAll = makePosition(childContext.pos().getPosition(stmtNodes[0]).getFirstOffset(),
                        childContext.pos().getPosition(stmtNodes[stmtNodes.length - 1]).getLastOffset());
                caseNodes.add(makeNode(childContext, fFactory, positionOfAll, CAstNode.BLOCK_STMT, stmtNodes));
                currentBlock.clear();
            }
            caseNodes.add(visitNode(s, childContext));
        } else {
            visitNodeOrNodes(s, childContext, currentBlock);
        }
    }
    if (!currentBlock.isEmpty()) {
        // bundle up statements before this case
        CAstNode stmtNodes[] = currentBlock.toArray(new CAstNode[currentBlock.size()]);
        // make position from start of first statement to end of last statement
        T positionOfAll = makePosition(childContext.pos().getPosition(stmtNodes[0]).getFirstOffset(),
                childContext.pos().getPosition(stmtNodes[stmtNodes.length - 1]).getLastOffset());
        caseNodes.add(makeNode(childContext, fFactory, positionOfAll, CAstNode.BLOCK_STMT, stmtNodes));
    }

    // Now produce the switch stmt itself
    CAstNode switchAst = makeNode(context, fFactory, n, CAstNode.SWITCH, visitNode(cond, context), makeNode(
            context, fFactory, n, CAstNode.BLOCK_STMT, caseNodes.toArray(new CAstNode[caseNodes.size()])));

    context.cfg().map(n, switchAst);

    // Finally, wrap the entire switch in a block so that we have a
    // well-defined place to 'break' to.
    return makeNode(context, fFactory, n, CAstNode.BLOCK_STMT, switchAst, breakAst);

}

From source file:com.j2swift.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(SwitchCase node) {
    sb.unindent();//from w  ww  .  j av a 2  s .c o m
    sb.printIndent();
    if (node.isDefault()) {
        sb.println("default :");
    } else {
        sb.print("case ");
        node.getExpression().accept(this);
        sb.println(":");
    }
    sb.indent();
    return false;
}

From source file:edu.cmu.cs.crystal.internal.ControlFlowVisitor.java

License:Open Source License

public boolean visit(SwitchStatement node) {
    Expression expression = node.getExpression();
    List statements = node.statements();
    if (expression == null)
        throw new CrystalRuntimeException("Switch statement without an expression?");
    if (statements == null || statements.size() == 0)
        throw new CrystalRuntimeException("Switch statements without any statements?");

    ControlFlowNode expressionCFN = controlFlowNode.newControlFlowNode(expression);

    controlFlowNode.moveEdges(ControlFlowNode.Direction.BACKWARDS, expressionCFN);

    Iterator i = statements.iterator();
    List<ControlFlowNode> statementCFNs = new LinkedList<ControlFlowNode>();
    ControlFlowNode cfn = null, previous = null;
    Statement astNode;//from   ww  w  .j ava  2 s . c  om
    boolean haveSeenDefault = false;
    while (i.hasNext()) {
        astNode = (Statement) i.next();
        cfn = controlFlowNode.newControlFlowNode(astNode);
        statementCFNs.add(cfn);
        if (previous != null)
            previous.addEdge(Direction.FORWARDS, cfn);
        if (astNode.getNodeType() == ASTNode.SWITCH_CASE) {
            expressionCFN.addEdge(Direction.FORWARDS, cfn);
            SwitchCase sc = (SwitchCase) astNode;
            if (sc.isDefault()) {
                if (haveSeenDefault)
                    throw new CrystalRuntimeException("cannot have more than one default in a switch");
                haveSeenDefault = true;
            }
        }
        previous = cfn;
    }
    if (cfn == null)
        throw new CrystalRuntimeException("no statements in switch");
    // if we never saw a default, then add an edge to the switch statement
    if (!haveSeenDefault)
        expressionCFN.addEdge(Direction.FORWARDS, controlFlowNode);
    cfn.addEdge(ControlFlowNode.Direction.FORWARDS, controlFlowNode);

    expressionCFN.evaluate();
    if (statementCFNs != null)
        evaluate(statementCFNs);

    return false;
}