1 package net.sourceforge.phpdt.internal.compiler.ast;
4 import java.util.ArrayList;
7 * This is a if statement.
12 * @author Matthieu Casanova
14 public class IfStatement extends Statement {
16 public Expression condition;
17 public Statement statement;
18 public ElseIf[] elseifs;
22 * Create a new If statement.
23 * @param condition the condition
24 * @param statement a statement or a block of statements
25 * @param elseifs the elseifs
26 * @param els the else (or null)
27 * @param sourceStart the starting position
28 * @param sourceEnd the ending offset
30 public IfStatement(final Expression condition,
31 final Statement statement,
32 final ElseIf[] elseifs,
34 final int sourceStart,
35 final int sourceEnd) {
36 super(sourceStart, sourceEnd);
37 this.condition = condition;
38 this.statement = statement;
39 this.elseifs = elseifs;
44 * Return the object into String.
45 * @param tab how many tabs (not used here
48 public String toString(final int tab) {
49 final StringBuffer buff = new StringBuffer(tabString(tab));
50 buff.append("if (");//$NON-NLS-1$
51 buff.append(condition.toStringExpression()).append(") ");//$NON-NLS-1$
52 buff.append(statement.toString(tab + 1));
53 for (int i = 0; i < elseifs.length; i++) {
54 buff.append(elseifs[i].toString(tab + 1));
55 buff.append("\n");//$NON-NLS-1$
58 buff.append(els.toString(tab + 1));
59 buff.append("\n");//$NON-NLS-1$
61 return buff.toString();
65 * Get the variables from outside (parameters, globals ...)
66 * @return the variables from outside
68 public List getOutsideVariable() {
69 final ArrayList list = new ArrayList();
70 list.addAll(condition.getOutsideVariable()); // todo: check if unuseful
71 list.addAll(statement.getOutsideVariable());
72 for (int i = 0; i < elseifs.length; i++) {
73 list.addAll(elseifs[i].getOutsideVariable());
76 list.addAll(els.getOutsideVariable());
82 * get the modified variables.
83 * @return the variables from we change value
85 public List getModifiedVariable() {
86 final ArrayList list = new ArrayList();
87 list.addAll(condition.getModifiedVariable());
88 list.addAll(statement.getModifiedVariable());
89 for (int i = 0; i < elseifs.length; i++) {
90 list.addAll(elseifs[i].getModifiedVariable());
93 list.addAll(els.getModifiedVariable());
99 * Get the variables used.
100 * @return the variables used
102 public List getUsedVariable() {
103 final ArrayList list = new ArrayList();
104 list.addAll(condition.getUsedVariable());
105 list.addAll(statement.getUsedVariable());
106 for (int i = 0; i < elseifs.length; i++) {
107 list.addAll(elseifs[i].getUsedVariable());
110 list.addAll(els.getUsedVariable());