Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ForStatement.java
index 8a16b5e..9ee27d5 100644 (file)
@@ -1,21 +1,39 @@
 package net.sourceforge.phpdt.internal.compiler.ast;
 
+import java.util.List;
+
 /**
+ * A For statement.
+ * for(initializations;condition;increments) action
  * @author Matthieu Casanova
  */
 public class ForStatement extends Statement {
 
-  public Statement[] initializations;
+  /** the initializations. */
+  public Expression[] initializations;
+
+  /** the condition. */
   public Expression condition;
-  public Statement[] increments;
+  /** the increments. */
+  public Expression[] increments;
+
   public Statement action;
 
-  public ForStatement(Statement[] initializations,
-                      Expression condition,
-                      Statement[] increments,
-                      Statement action,
-                      int sourceStart,
-                      int sourceEnd) {
+  /**
+   * a for statement
+   * @param initializations the initializations expressions
+   * @param condition the condition when the for get out
+   * @param increments the increments statements
+   * @param action the action (a statement, a block ...)
+   * @param sourceStart the beginning sources
+   * @param sourceEnd the ending sources
+   */
+  public ForStatement(final Expression[] initializations,
+                      final Expression condition,
+                      final Expression[] increments,
+                      final Statement action,
+                      final int sourceStart,
+                      final int sourceEnd) {
     super(sourceStart, sourceEnd);
     this.initializations = initializations;
     this.condition = condition;
@@ -23,29 +41,28 @@ public class ForStatement extends Statement {
     this.action = action;
   }
 
-  public String toString(int tab) {
+  public String toString(final int tab) {
     final StringBuffer buff = new StringBuffer(tabString(tab));
     buff.append("for (");  //$NON-NLS-1$
     //inits
     if (initializations != null) {
       for (int i = 0; i < initializations.length; i++) {
-        //nice only with expressions
-        buff.append(initializations[i].toString());
+        buff.append(initializations[i].toStringExpression());
         if (i != (initializations.length - 1))
           buff.append(" , "); //$NON-NLS-1$
       }
     }
-    buff.append( "; "); //$NON-NLS-1$
+    buff.append("; "); //$NON-NLS-1$
     //cond
-    if (condition != null)           {
+    if (condition != null) {
       buff.append(condition.toStringExpression());
     }
-    buff.append( "; "); //$NON-NLS-1$
+    buff.append("; "); //$NON-NLS-1$
     //updates
     if (increments != null) {
       for (int i = 0; i < increments.length; i++) {
         //nice only with expressions
-        buff.append(increments[i].toString());
+        buff.append(increments[i].toStringExpression());
         if (i != (increments.length - 1))
           buff.append(" , "); //$NON-NLS-1$
       }
@@ -55,7 +72,73 @@ public class ForStatement extends Statement {
     if (action == null)
       buff.append("{}"); //$NON-NLS-1$
     else
-      buff.append( "\n").append(action.toString(tab + 1)); //$NON-NLS-1$
+      buff.append(action.toString(tab + 1)); //$NON-NLS-1$
     return buff.toString();
   }
+
+  /**
+   * Get the variables from outside (parameters, globals ...)
+   */
+  public void getOutsideVariable(final List list) {
+    if (condition != null) {
+      condition.getOutsideVariable(list);
+    }
+    if (action != null) {
+      action.getOutsideVariable(list);
+    }
+    if (initializations != null) {
+      for (int i = 0; i < initializations.length; i++) {
+        initializations[i].getOutsideVariable(list);
+      }
+    }
+    if (increments != null) {
+      for (int i = 0; i < increments.length; i++) {
+        increments[i].getOutsideVariable(list);
+      }
+    }
+  }
+
+  /**
+   * get the modified variables.
+   */
+  public void getModifiedVariable(final List list) {
+    if (condition != null) {
+      condition.getModifiedVariable(list);
+    }
+    if (action != null) {
+      action.getModifiedVariable(list);
+    }
+    if (initializations != null) {
+      for (int i = 0; i < initializations.length; i++) {
+        initializations[i].getModifiedVariable(list);
+      }
+    }
+    if (increments != null) {
+      for (int i = 0; i < increments.length; i++) {
+        increments[i].getModifiedVariable(list);
+      }
+    }
+  }
+
+  /**
+   * Get the variables used.
+   */
+  public void getUsedVariable(final List list) {
+    if (condition != null) {
+      condition.getUsedVariable(list);
+    }
+    if (action != null) {
+      action.getUsedVariable(list);
+    }
+    if (initializations != null) {
+      for (int i = 0; i < initializations.length; i++) {
+        initializations[i].getUsedVariable(list);
+      }
+    }
+    if (increments != null) {
+      for (int i = 0; i < increments.length; i++) {
+        increments[i].getUsedVariable(list);
+      }
+    }
+  }
 }