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 if (statement != null) {
53 buff.append(statement.toString(tab + 1));
55 for (int i = 0; i < elseifs.length; i++) {
56 buff.append(elseifs[i].toString(tab + 1));
57 buff.append("\n");//$NON-NLS-1$
60 buff.append(els.toString(tab + 1));
61 buff.append("\n");//$NON-NLS-1$
63 return buff.toString();
67 * Get the variables from outside (parameters, globals ...)
68 * @return the variables from outside
70 public List getOutsideVariable() {
71 final ArrayList list = new ArrayList();
72 list.addAll(condition.getOutsideVariable()); // todo: check if unuseful
73 if (statement != null) {
74 list.addAll(statement.getOutsideVariable());
76 for (int i = 0; i < elseifs.length; i++) {
77 list.addAll(elseifs[i].getOutsideVariable());
80 list.addAll(els.getOutsideVariable());
86 * get the modified variables.
87 * @return the variables from we change value
89 public List getModifiedVariable() {
90 final ArrayList list = new ArrayList();
91 list.addAll(condition.getModifiedVariable());
92 if (statement != null) {
93 list.addAll(statement.getModifiedVariable());
95 for (int i = 0; i < elseifs.length; i++) {
96 list.addAll(elseifs[i].getModifiedVariable());
99 list.addAll(els.getModifiedVariable());
105 * Get the variables used.
106 * @return the variables used
108 public List getUsedVariable() {
109 final ArrayList list = new ArrayList();
110 list.addAll(condition.getUsedVariable());
111 if (statement != null) {
112 list.addAll(statement.getUsedVariable());
114 for (int i = 0; i < elseifs.length; i++) {
115 list.addAll(elseifs[i].getUsedVariable());
118 list.addAll(els.getUsedVariable());