the unknown variables should be reported only once
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ForStatement.java
index 212d451..b11d6f0 100644 (file)
@@ -1,25 +1,34 @@
 package net.sourceforge.phpdt.internal.compiler.ast;
 
 import java.util.List;
-import java.util.ArrayList;
 
 /**
  * A For statement.
  * for(initializations;condition;increments) action
  * @author Matthieu Casanova
  */
-public class ForStatement extends Statement {
+public final class ForStatement extends Statement {
 
   /** the initializations. */
-  public Expression[] initializations;
+  private final Expression[] initializations;
 
   /** the condition. */
-  public Expression condition;
+  private final Expression condition;
   /** the increments. */
-  public Expression[] increments;
+  private final Expression[] increments;
 
-  public Statement action;
+  private final Statement action;
 
+  /**
+   * 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,
@@ -70,52 +79,73 @@ public class ForStatement extends Statement {
 
   /**
    * Get the variables from outside (parameters, globals ...)
-   * @return the variables from outside
+   *
+   * @param list the list where we will put variables
    */
-  public List getOutsideVariable() {
-    final ArrayList list = new ArrayList();
-    list.addAll(condition.getOutsideVariable());
-    list.addAll(action.getOutsideVariable());
-    for (int i = 0; i < initializations.length; i++) {
-      list.addAll(initializations[i].getOutsideVariable());
+  public void getOutsideVariable(final List list) {
+    if (condition != null) {
+      condition.getOutsideVariable(list);
+    }
+    if (action != null) {
+      action.getOutsideVariable(list);
     }
-    for (int i = 0; i < increments.length; i++) {
-      list.addAll(increments[i].getOutsideVariable());
+    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);
+      }
     }
-    return list;
   }
 
   /**
    * get the modified variables.
-   * @return the variables from we change value
+   *
+   * @param list the list where we will put variables
    */
-  public List getModifiedVariable() {
-    final ArrayList list = new ArrayList();
-    list.addAll(condition.getModifiedVariable());
-    list.addAll(action.getModifiedVariable());
-    for (int i = 0; i < initializations.length; i++) {
-      list.addAll(initializations[i].getModifiedVariable());
+  public void getModifiedVariable(final List list) {
+    if (condition != null) {
+      condition.getModifiedVariable(list);
     }
-    for (int i = 0; i < increments.length; i++) {
-      list.addAll(increments[i].getModifiedVariable());
+    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);
+      }
     }
-    return list;
   }
 
   /**
    * Get the variables used.
-   * @return the variables used
+   *
+   * @param list the list where we will put variables
    */
-  public List getUsedVariable() {
-    final ArrayList list = new ArrayList();
-    list.addAll(condition.getUsedVariable());
-    list.addAll(action.getUsedVariable());
-    for (int i = 0; i < initializations.length; i++) {
-      list.addAll(initializations[i].getUsedVariable());
+  public void getUsedVariable(final List list) {
+    if (condition != null) {
+      condition.getUsedVariable(list);
+    }
+    if (action != null) {
+      action.getUsedVariable(list);
     }
-    for (int i = 0; i < increments.length; i++) {
-      list.addAll(increments[i].getUsedVariable());
+    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);
+      }
     }
-    return list;
   }
 }