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