private void print(SwitchStatement node) throws IOException { writer.append("switch").ws().append('('); print(node.getExpression()); writer.append(')').ws().append('{').indent().softNewLine(); for (SwitchCase sc : node.getCases()) { if (sc.getExpression() == null) { writer.append("default:"); } else { writer.append("case "); print(sc.getExpression()); writer.append(':'); } writer.indent().softNewLine(); if (sc.getStatements() != null) { for (AstNode stmt : sc.getStatements()) { print(stmt); writer.softNewLine(); } } writer.outdent(); } writer.outdent().append('}'); }
int pos = ts.tokenBeg; SwitchStatement pn = new SwitchStatement(pos); if (mustMatchToken(Token.LP, "msg.no.paren.switch")) pn.setLp(ts.tokenBeg - pos); pn.setLineno(ts.lineno); pn.setExpression(discriminant); enterSwitch(pn); pn.setRp(ts.tokenBeg - pos); switch (tt) { case Token.RC: pn.setLength(ts.tokenEnd - pos); break switchLoop; pn.addCase(caseNode);
Node switchExpr = transform(node.getExpression()); decompiler.addToken(Token.RP); node.addChildToBack(switchExpr); Node block = new Node(Token.BLOCK, node, node.getLineno()); decompiler.addEOL(Token.LC); for (SwitchCase sc : node.getCases()) { AstNode expr = sc.getExpression(); Node caseExpr = null;
public int getNumCases() { return node.getCases().size(); }
/** * Sets the switch discriminant expression, and sets its parent * to this node. * @throws IllegalArgumentException} if expression is {@code null} */ public void setExpression(AstNode expression) { assertNotNull(expression); this.expression = expression; expression.setParent(this); }
@Override public String toSource(int depth) { String pad = makeIndent(depth); StringBuilder sb = new StringBuilder(); sb.append(pad); sb.append("switch ("); sb.append(expression.toSource(0)); sb.append(") {\n"); for (SwitchCase sc : cases) { sb.append(sc.toSource(depth + 1)); } sb.append(pad); sb.append("}\n"); return sb.toString(); }
/** * Sets case statement list, and sets the parent of each child * case to this node. * @param cases list, which may be {@code null} to remove all the cases */ public void setCases(List<SwitchCase> cases) { if (cases == null) { this.cases = null; } else { if (this.cases != null) this.cases.clear(); for (SwitchCase sc : cases) addCase(sc); } }
int pos = ts.tokenBeg; SwitchStatement pn = new SwitchStatement(pos); if (mustMatchToken(Token.LP, "msg.no.paren.switch")) pn.setLp(ts.tokenBeg - pos); pn.setLineno(ts.lineno); pn.setExpression(discriminant); enterSwitch(pn); pn.setRp(ts.tokenBeg - pos); switch (tt) { case Token.RC: pn.setLength(ts.tokenEnd - pos); break switchLoop; pn.addCase(caseNode);
Node switchExpr = transform(node.getExpression()); decompiler.addToken(Token.RP); node.addChildToBack(switchExpr); Node block = new Node(Token.BLOCK, node, node.getLineno()); decompiler.addEOL(Token.LC); for (SwitchCase sc : node.getCases()) { AstNode expr = sc.getExpression(); Node caseExpr = null;
/** Extract local variables from switch node* */ private void processSwitchNode(Node child, CodeBlock block, Set<Completion> set, String entered, int offset) { SwitchStatement switchStatement = (SwitchStatement) child; if (canProcessNode(switchStatement)) { List<SwitchCase> cases = switchStatement.getCases(); if(cases != null) { for (SwitchCase switchCase : cases) { iterateNode(switchCase, set, entered, block, offset); } } } }
/** * Sets the switch discriminant expression, and sets its parent * to this node. * @throws IllegalArgumentException} if expression is {@code null} */ public void setExpression(AstNode expression) { assertNotNull(expression); this.expression = expression; expression.setParent(this); }
@Override public String toSource(int depth) { String pad = makeIndent(depth); StringBuilder sb = new StringBuilder(); sb.append(pad); sb.append("switch ("); sb.append(expression.toSource(0)); sb.append(") {\n"); for (SwitchCase sc : cases) { sb.append(sc.toSource(depth + 1)); } sb.append(pad); sb.append("}\n"); return sb.toString(); }
/** * Sets case statement list, and sets the parent of each child * case to this node. * @param cases list, which may be {@code null} to remove all the cases */ public void setCases(List<SwitchCase> cases) { if (cases == null) { this.cases = null; } else { if (this.cases != null) this.cases.clear(); for (SwitchCase sc : cases) addCase(sc); } }
int pos = ts.tokenBeg; SwitchStatement pn = new SwitchStatement(pos); if (mustMatchToken(Token.LP, "msg.no.paren.switch")) pn.setLp(ts.tokenBeg - pos); pn.setLineno(ts.lineno); pn.setExpression(discriminant); enterSwitch(pn); pn.setRp(ts.tokenBeg - pos); switch (tt) { case Token.RC: pn.setLength(ts.tokenEnd - pos); break switchLoop; pn.addCase(caseNode);
Node switchExpr = transform(node.getExpression()); decompiler.addToken(Token.RP); node.addChildToBack(switchExpr); Node block = new Node(Token.BLOCK, node, node.getLineno()); decompiler.addEOL(Token.LC); for (SwitchCase sc : node.getCases()) { AstNode expr = sc.getExpression(); Node caseExpr = null;
CAstNode[] children = new CAstNode[ node.getCases().size() * 2 ]; for(SwitchCase sc : node.getCases()) { CAstNode label = Ast.makeNode(CAstNode.LABEL_STMT, visit(node.getExpression(), context), Ast.makeNode(CAstNode.BLOCK_STMT, children));
/** * Visits this node, then the switch-expression, then the cases * in lexical order. */ @Override public void visit(NodeVisitor v) { if (v.visit(this)) { expression.visit(v); for (SwitchCase sc: getCases()) { sc.visit(v); } } } }
/** * Sets the switch discriminant expression, and sets its parent * to this node. * @throws IllegalArgumentException} if expression is {@code null} */ public void setExpression(AstNode expression) { assertNotNull(expression); this.expression = expression; expression.setParent(this); }
@Override public String toSource(int depth) { String pad = makeIndent(depth); StringBuilder sb = new StringBuilder(); sb.append(pad); sb.append("switch ("); sb.append(expression.toSource(0)); sb.append(") {\n"); if (cases != null) { for (SwitchCase sc : cases) { sb.append(sc.toSource(depth + 1)); } } sb.append(pad); sb.append("}\n"); return sb.toString(); }
/** * Sets case statement list, and sets the parent of each child * case to this node. * @param cases list, which may be {@code null} to remove all the cases */ public void setCases(List<SwitchCase> cases) { if (cases == null) { this.cases = null; } else { if (this.cases != null) this.cases.clear(); for (SwitchCase sc : cases) addCase(sc); } }