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('}'); }
SwitchCase caseNode = new SwitchCase(casePos); caseNode.setExpression(caseExpression); caseNode.setLength(ts.tokenEnd - pos); // include colon caseNode.setLineno(caseLineno); && tt != Token.EOF) caseNode.addStatement(statement()); // updates length
/** * Adds a statement to the end of the statement list. * Sets the parent of the new statement to this node, updates * its start offset to be relative to this node, and sets the * length of this node to include the new child. * * @param statement a child statement * @throws IllegalArgumentException} if statement is {@code null} */ public void addStatement(AstNode statement) { assertNotNull(statement); if (statements == null) { statements = new ArrayList<AstNode>(); } int end = statement.getPosition() + statement.getLength(); this.setLength(end - this.getPosition()); statements.add(statement); statement.setParent(this); }
private void processCaseNode(Node child, CodeBlock block, Set<Completion> set, String entered, int offset) { SwitchCase switchCase = (SwitchCase) child; List<AstNode> statements = switchCase.getStatements(); int start = switchCase.getAbsolutePosition(); offset = start + switchCase.getLength(); if (canProcessNode(switchCase)) { block = block.addChildCodeBlock(start); block.setEndOffset(offset); if(statements != null) { for (AstNode node : statements) { iterateNode(node, set, entered, block, offset); } } } }
public int getNumStatements() { // TODO Tell Rhino folks about null Statements, should be empty List? return node.getStatements() != null ? node.getStatements().size() : 0; }
children[i++] = label; if (sc.isDefault()) { context.cfg().add(node, label, CAstControlFlowMap.SWITCH_DEFAULT); } else { CAstNode labelCAst = visit(sc.getExpression(), context); context.cfg().add(node, label, labelCAst);
/** * Sets statement list. May be {@code null}. Replaces any existing * statements. Each element in the list has its parent set to this node. */ public void setStatements(List<AstNode> statements) { if (this.statements != null) { this.statements.clear(); } for (AstNode s : statements) { addStatement(s); } }
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); if (expression == null) { sb.append("default:\n"); } else { sb.append("case "); sb.append(expression.toSource(0)); sb.append(":\n"); } if (statements != null) { for (AstNode s : statements) { sb.append(s.toSource(depth+1)); } } return sb.toString(); }
SwitchCase caseNode = new SwitchCase(casePos); caseNode.setExpression(caseExpression); caseNode.setLength(ts.tokenEnd - pos); // include colon caseNode.setLineno(caseLineno); && tt != Token.EOF) caseNode.addStatement(statement()); // updates length
/** * Adds a statement to the end of the statement list. * Sets the parent of the new statement to this node, updates * its start offset to be relative to this node, and sets the * length of this node to include the new child. * * @param statement a child statement * @throws IllegalArgumentException} if statement is {@code null} */ public void addStatement(AstNode statement) { assertNotNull(statement); if (statements == null) { statements = new ArrayList<AstNode>(); } int end = statement.getPosition() + statement.getLength(); this.setLength(end - this.getPosition()); statements.add(statement); statement.setParent(this); }
@Override public CAstNode visitSwitchCase(SwitchCase node, WalkContext arg) { if (node.getStatements() == null) { return Ast.makeNode(CAstNode.EMPTY); } else { CAstNode[] stmts = new CAstNode[ node.getStatements().size() ]; for(int i = 0; i < stmts.length; i++) { stmts[i] = visit(node.getStatements().get(i), arg); } return Ast.makeNode(CAstNode.BLOCK_STMT, stmts); } }
/** * Sets statement list. May be {@code null}. Replaces any existing * statements. Each element in the list has its parent set to this node. */ public void setStatements(List<AstNode> statements) { if (this.statements != null) { this.statements.clear(); } for (AstNode s : statements) { addStatement(s); } }
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); if (expression == null) { sb.append("default:\n"); } else { sb.append("case "); sb.append(expression.toSource(0)); sb.append(":\n"); } if (statements != null) { for (AstNode s : statements) { sb.append(s.toSource(depth+1)); } } return sb.toString(); }
SwitchCase caseNode = new SwitchCase(casePos); caseNode.setExpression(caseExpression); caseNode.setLength(ts.tokenEnd - pos); // include colon caseNode.setLineno(caseLineno); && tt != Token.EOF) caseNode.addStatement(statement()); // updates length
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.append('}'); }
/** * Adds a statement to the end of the statement list. * Sets the parent of the new statement to this node, updates * its start offset to be relative to this node, and sets the * length of this node to include the new child. * * @param statement a child statement * @throws IllegalArgumentException} if statement is {@code null} */ public void addStatement(AstNode statement) { assertNotNull(statement); if (statements == null) { statements = new ArrayList<AstNode>(); } int end = statement.getPosition() + statement.getLength(); this.setLength(end - this.getPosition()); statements.add(statement); statement.setParent(this); }
/** * Sets statement list. May be {@code null}. Replaces any existing * statements. Each element in the list has its parent set to this node. */ public void setStatements(List<AstNode> statements) { if (this.statements != null) { this.statements.clear(); } for (AstNode s : statements) { addStatement(s); } }
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); if (expression == null) { sb.append("default:\n"); } else { sb.append("case "); sb.append(expression.toSource(0)); sb.append(":\n"); } if (statements != null) { for (AstNode s : statements) { sb.append(s.toSource(depth+1)); } } return sb.toString(); }
SwitchCase caseNode = new SwitchCase(casePos); caseNode.setExpression(caseExpression); caseNode.setLength(ts.tokenEnd - pos); // include colon caseNode.setLineno(caseLineno); && tt != Token.EOF) caseNode.addStatement(statement()); // updates length
AstNode expr = sc.getExpression(); Node caseExpr = null; List<AstNode> stmts = sc.getStatements(); Node body = new Block(); if (stmts != null) {