First try for AST structure. A lot of things to change
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / ForStatement.java
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java
new file mode 100644 (file)
index 0000000..8a16b5e
--- /dev/null
@@ -0,0 +1,61 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * @author Matthieu Casanova
+ */
+public class ForStatement extends Statement {
+
+  public Statement[] initializations;
+  public Expression condition;
+  public Statement[] increments;
+  public Statement action;
+
+  public ForStatement(Statement[] initializations,
+                      Expression condition,
+                      Statement[] increments,
+                      Statement action,
+                      int sourceStart,
+                      int sourceEnd) {
+    super(sourceStart, sourceEnd);
+    this.initializations = initializations;
+    this.condition = condition;
+    this.increments = increments;
+    this.action = action;
+  }
+
+  public String toString(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());
+        if (i != (initializations.length - 1))
+          buff.append(" , "); //$NON-NLS-1$
+      }
+    }
+    buff.append( "; "); //$NON-NLS-1$
+    //cond
+    if (condition != null)           {
+      buff.append(condition.toStringExpression());
+    }
+    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());
+        if (i != (increments.length - 1))
+          buff.append(" , "); //$NON-NLS-1$
+      }
+    }
+    buff.append(") "); //$NON-NLS-1$
+    //block
+    if (action == null)
+      buff.append("{}"); //$NON-NLS-1$
+    else
+      buff.append( "\n").append(action.toString(tab + 1)); //$NON-NLS-1$
+    return buff.toString();
+  }
+}