1 46 package org.codehaus.groovy.ast.stmt; 47 48 import java.util.ArrayList ; 49 import java.util.Arrays ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 53 import org.codehaus.groovy.ast.GroovyCodeVisitor; 54 55 61 public class BlockStatement extends Statement { 62 63 private List statements; 64 65 public BlockStatement() { 66 this(new ArrayList ()); 67 } 68 69 public BlockStatement(List statements) { 70 this.statements = statements; 71 } 72 73 public BlockStatement(Statement[] statements) { 74 this(); 75 this.statements.addAll(Arrays.asList(statements)); 76 } 77 78 public void visit(GroovyCodeVisitor visitor) { 79 visitor.visitBlockStatement(this); 80 } 81 82 public List getStatements() { 83 return statements; 84 } 85 86 public void addStatement(Statement statement) { 87 statements.add(statement); 88 } 89 90 public void addStatements(List listOfStatements) { 91 statements.addAll(listOfStatements); 92 } 93 94 public String toString() { 95 return super.toString() + statements; 96 } 97 98 public String getText() { 99 StringBuffer buffer = new StringBuffer ("{ "); 100 boolean first = true; 101 for (Iterator iter = statements.iterator(); iter.hasNext(); ) { 102 if (first) { 103 first = false; 104 } 105 else { 106 buffer.append("; "); 107 } 108 Statement statement = (Statement) iter.next(); 109 buffer.append(statement.getText()); 110 } 111 buffer.append(" }"); 112 return buffer.toString(); 113 } 114 115 public boolean isEmpty() { 116 return statements.isEmpty(); 117 } 118 119 } 120 | Popular Tags |