@Override public AstNode addStatement(AstNode blockOrStatement, AstNode statement) { if (blockOrStatement instanceof Block) { ((Block) blockOrStatement).addStatement(statement); return blockOrStatement; } Block block = new Block(); if (blockOrStatement != null) { block.addStatement(blockOrStatement); } if (statement != null) { block.addStatement(statement); } return block; }
@Override public AstNode addStatementBeginning(AstNode blockOrStatement, AstNode statement) { if (blockOrStatement instanceof Block) { if (statement != null) { blockOrStatement.addChildrenToFront(statement); statement.setParent(blockOrStatement); } return blockOrStatement; } Block block = new Block(); if (statement != null) { block.addStatement(statement); } if (blockOrStatement != null) { block.addStatement(blockOrStatement); } return block; }
@Override public AstNode block(Iterable<AstNode> statements) { Block block = new Block(); for (AstNode stmt : statements) { if (stmt != null) { block.addStatement(stmt); } } return block; }
@Override public AstNode catchClause(AstNode varName, AstNode body) { CatchClause c = new CatchClause(); c.setVarName(cast(varName, Name.class)); if (body instanceof Block) { c.setBody((Block) body); } else { Block b = new Block(); b.addStatement(body); c.setBody(b); } return c; }