First try, not finished
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / Block.java
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/Block.java
new file mode 100644 (file)
index 0000000..6b131d3
--- /dev/null
@@ -0,0 +1,47 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * A Block is
+ * {
+ * statements
+ * }.
+ * @author Matthieu Casanova
+ */
+public class Block extends Statement {
+  public Statement[] statements;
+
+  public boolean isEmptyBlock() {
+    return statements == null;
+  }
+
+  public String toString(int tab) {
+    final String s = tabString(tab);
+    final StringBuffer buff = new StringBuffer(s);
+    if (this.statements == null) {
+      buff.append("{\n"); //$NON-NLS-1$
+      buff.append(s);
+      buff.append("}"); //$NON-NLS-1$
+      return s;
+    }
+    buff.append("{\n"); //$NON-NLS-1$
+    buff.append(this.toStringStatements(tab));
+    buff.append(s);
+    buff.append("}"); //$NON-NLS-1$
+    return s;
+  }
+
+  public String toStringStatements(int tab) {
+    if (this.statements == null)
+      return ""; //$NON-NLS-1$
+    StringBuffer buffer = new StringBuffer();
+    for (int i = 0; i < statements.length; i++) {
+      buffer.append(statements[i].toString(tab + 1));
+      if (statements[i] instanceof Block) {
+        buffer.append("\n"); //$NON-NLS-1$
+      } else {
+        buffer.append(";\n"); //$NON-NLS-1$
+      }
+    }
+    return buffer.toString();
+  }
+}