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
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 /**
4  * @author Matthieu Casanova
5  */
6 public class ForStatement extends Statement {
7
8   public Statement[] initializations;
9   public Expression condition;
10   public Statement[] increments;
11   public Statement action;
12
13   public ForStatement(Statement[] initializations,
14                       Expression condition,
15                       Statement[] increments,
16                       Statement action,
17                       int sourceStart,
18                       int sourceEnd) {
19     super(sourceStart, sourceEnd);
20     this.initializations = initializations;
21     this.condition = condition;
22     this.increments = increments;
23     this.action = action;
24   }
25
26   public String toString(int tab) {
27     final StringBuffer buff = new StringBuffer(tabString(tab));
28     buff.append("for (");  //$NON-NLS-1$
29     //inits
30     if (initializations != null) {
31       for (int i = 0; i < initializations.length; i++) {
32         //nice only with expressions
33         buff.append(initializations[i].toString());
34         if (i != (initializations.length - 1))
35           buff.append(" , "); //$NON-NLS-1$
36       }
37     }
38     buff.append( "; "); //$NON-NLS-1$
39     //cond
40     if (condition != null)           {
41       buff.append(condition.toStringExpression());
42     }
43     buff.append( "; "); //$NON-NLS-1$
44     //updates
45     if (increments != null) {
46       for (int i = 0; i < increments.length; i++) {
47         //nice only with expressions
48         buff.append(increments[i].toString());
49         if (i != (increments.length - 1))
50           buff.append(" , "); //$NON-NLS-1$
51       }
52     }
53     buff.append(") "); //$NON-NLS-1$
54     //block
55     if (action == null)
56       buff.append("{}"); //$NON-NLS-1$
57     else
58       buff.append( "\n").append(action.toString(tab + 1)); //$NON-NLS-1$
59     return buff.toString();
60   }
61 }