Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / WhileStatement.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import java.util.List;
4
5 /**
6  * A While statement.
7  * @author Matthieu Casanova
8  */
9 public class WhileStatement extends Statement {
10
11   /** The condition expression. */
12   public Expression condition;
13   /** The action of the while. (it could be a block) */
14   public Statement action;
15
16   /**
17    * Create a While statement.
18    * @param condition the condition
19    * @param action the action
20    * @param sourceStart the starting offset
21    * @param sourceEnd the ending offset
22    */
23   public WhileStatement(final Expression condition,
24                         final Statement action,
25                         final int sourceStart,
26                         final int sourceEnd) {
27     super(sourceStart, sourceEnd);
28     this.condition = condition;
29     this.action = action;
30   }
31
32   /**
33    * Return the object into String.
34    * @param tab how many tabs (not used here
35    * @return a String
36    */
37   public String toString(final int tab) {
38     final String s = tabString(tab);
39     final StringBuffer buff = new StringBuffer(s).append("while ("); //$NON-NLS-1$
40     buff.append(condition.toStringExpression()).append(")");    //$NON-NLS-1$
41     if (action == null) {
42       buff.append(" {} ;"); //$NON-NLS-1$
43     } else {
44       buff.append("\n").append(action.toString(tab + 1)); //$NON-NLS-1$
45     }
46     return buff.toString();
47   }
48
49   /**
50    * Get the variables from outside (parameters, globals ...)
51    */
52   public void getOutsideVariable(final List list) {
53     condition.getOutsideVariable(list); // todo: check if unuseful
54     if (action != null) {
55       action.getOutsideVariable(list);
56     }
57   }
58
59   /**
60    * get the modified variables.
61    */
62   public void getModifiedVariable(final List list) {
63     condition.getModifiedVariable(list);
64     if (action != null) {
65       action.getModifiedVariable(list);
66     }
67   }
68
69   /**
70    * Get the variables used.
71    */
72   public void getUsedVariable(final List list) {
73     condition.getUsedVariable(list);
74     if (action != null) {
75       action.getUsedVariable(list);
76     }
77   }
78 }