Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / Block.java
index 7050649..ac3cdb5 100644 (file)
@@ -1,10 +1,9 @@
 package net.sourceforge.phpdt.internal.compiler.ast;
 
-import net.sourceforge.phpdt.internal.compiler.ast.AstNode;
-
+import java.util.List;
 
 /**
- * A Block is
+ * A Block.
  * {
  * statements
  * }.
@@ -21,43 +20,63 @@ public class Block extends Statement {
    * @param sourceStart starting offset
    * @param sourceEnd ending offset
    */
-  public Block(Statement[] statements,int sourceStart, int sourceEnd) {
+  public Block(final Statement[] statements,
+               final int sourceStart,
+               final int sourceEnd) {
     super(sourceStart, sourceEnd);
     this.statements = statements;
   }
 
+  /**
+   * tell if the block is empty.
+   * @return the block is empty if there are no statements in it
+   */
   public boolean isEmptyBlock() {
     return statements == null;
   }
 
-  public String toString(int tab) {
+  /**
+   * Return the block as String.
+   * @param tab how many tabs
+   * @return the string representation of the block
+   */
+  public String toString(final int tab) {
     final String s = AstNode.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;
+    if (this.statements != null) {
+      for (int i = 0; i < statements.length; i++) {
+        buff.append(statements[i].toString(tab + 1)).append(";\n");//$NON-NLS-1$
+      }
+    }
+    buff.append("}\n"); //$NON-NLS-1$
+    return buff.toString();
   }
 
-  public String toStringStatements(int tab) {
-    if (this.statements == null)
-      return ""; //$NON-NLS-1$
-    StringBuffer buffer = new StringBuffer();
+  /**
+   * Get the variables from outside (parameters, globals ...)
+   */
+  public void getOutsideVariable(final List list) {
     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$
-      }
+      statements[i].getOutsideVariable(list);
+    }
+  }
+
+  /**
+   * get the modified variables.
+   */
+  public void getModifiedVariable(final List list) {
+    for (int i = 0; i < statements.length; i++) {
+      statements[i].getModifiedVariable(list);
+    }
+  }
+
+  /**
+   * Get the variables used.
+   */
+  public void getUsedVariable(final List list) {
+    for (int i = 0; i < statements.length; i++) {
+      statements[i].getUsedVariable(list);
     }
-    return buffer.toString();
   }
 }