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