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