Some minor changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / SwitchStatement.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import java.util.List;
4
5 /**
6  * @author Matthieu Casanova
7  */
8 public final class SwitchStatement extends Statement {
9
10   private final Expression variable;
11   private final AbstractCase[] cases;
12
13   public SwitchStatement(final Expression variable,
14                          final AbstractCase[] cases,
15                          final int sourceStart,
16                          final int sourceEnd) {
17     super(sourceStart, sourceEnd);
18     this.variable = variable;
19     this.cases = cases;
20   }
21
22   /**
23    * Return the object into String.
24    * @param tab how many tabs (not used here
25    * @return a String
26    */
27   public String toString(final int tab) {
28     final StringBuffer buff = new StringBuffer(tabString(tab));
29     buff.append("switch (").append(variable.toStringExpression()).append(") {\n");
30     for (int i = 0; i < cases.length; i++) {
31       final AbstractCase cas = cases[i];
32       buff.append(cas.toString(tab + 1));
33       buff.append('\n');
34     }
35     buff.append('}');
36     return buff.toString();
37   }
38
39   /**
40    * Get the variables from outside (parameters, globals ...)
41    *
42    * @param list the list where we will put variables
43    */
44   public void getOutsideVariable(final List list) {
45     for (int i = 0; i < cases.length; i++) {
46       cases[i].getOutsideVariable(list);
47     }
48   }
49
50   /**
51    * get the modified variables.
52    *
53    * @param list the list where we will put variables
54    */
55   public void getModifiedVariable(final List list) {
56     for (int i = 0; i < cases.length; i++) {
57       cases[i].getModifiedVariable(list);
58     }
59     variable.getModifiedVariable(list);
60   }
61
62   /**
63    * Get the variables used.
64    *
65    * @param list the list where we will put variables
66    */
67   public void getUsedVariable(final List list) {
68     for (int i = 0; i < cases.length; i++) {
69       cases[i].getUsedVariable(list);
70     }
71     variable.getUsedVariable(list);
72   }
73 }