1 package net.sourceforge.phpdt.internal.compiler.ast;
3 import net.sourceforge.phpdt.internal.compiler.ast.AstNode;
11 * @author Matthieu Casanova
13 public class Block extends Statement {
15 /** An array of statements inside the block. */
16 public Statement[] statements;
20 * @param statements the statements
21 * @param sourceStart starting offset
22 * @param sourceEnd ending offset
24 public Block(Statement[] statements,int sourceStart, int sourceEnd) {
25 super(sourceStart, sourceEnd);
26 this.statements = statements;
29 public boolean isEmptyBlock() {
30 return statements == null;
33 public String toString(int tab) {
34 final String s = AstNode.tabString(tab);
35 final StringBuffer buff = new StringBuffer(s);
36 if (this.statements == null) {
37 buff.append("{\n"); //$NON-NLS-1$
39 buff.append("}"); //$NON-NLS-1$
42 buff.append("{\n"); //$NON-NLS-1$
43 buff.append(this.toStringStatements(tab));
45 buff.append("}"); //$NON-NLS-1$
49 public String toStringStatements(int tab) {
50 if (this.statements == null)
51 return ""; //$NON-NLS-1$
52 StringBuffer buffer = new StringBuffer();
53 for (int i = 0; i < statements.length; i++) {
54 buffer.append(statements[i].toString(tab + 1));
55 if (statements[i] instanceof Block) {
56 buffer.append("\n"); //$NON-NLS-1$
58 buffer.append(";\n"); //$NON-NLS-1$
61 return buffer.toString();