1 package net.sourceforge.phpdt.internal.compiler.ast;
6 * This is a if statement.
11 * @author Matthieu Casanova
13 public final class IfStatement extends Statement {
15 private final Expression condition;
16 private final Statement statement;
17 private final ElseIf[] elseifs;
18 private final Else els;
21 * Create a new If statement.
22 * @param condition the condition
23 * @param statement a statement or a block of statements
24 * @param elseifs the elseifs
25 * @param els the else (or null)
26 * @param sourceStart the starting position
27 * @param sourceEnd the ending offset
29 public IfStatement(final Expression condition,
30 final Statement statement,
31 final ElseIf[] elseifs,
33 final int sourceStart,
34 final int sourceEnd) {
35 super(sourceStart, sourceEnd);
36 this.condition = condition;
37 this.statement = statement;
38 this.elseifs = elseifs;
43 * Return the object into String.
44 * @param tab how many tabs (not used here
47 public String toString(final int tab) {
48 final StringBuffer buff = new StringBuffer(tabString(tab));
49 buff.append("if (");//$NON-NLS-1$
50 buff.append(condition.toStringExpression()).append(") ");//$NON-NLS-1$
51 if (statement != null) {
52 buff.append(statement.toString(tab + 1));
54 for (int i = 0; i < elseifs.length; i++) {
55 buff.append(elseifs[i].toString(tab + 1));
56 buff.append("\n");//$NON-NLS-1$
59 buff.append(els.toString(tab + 1));
60 buff.append("\n");//$NON-NLS-1$
62 return buff.toString();
66 * Get the variables from outside (parameters, globals ...)
68 * @param list the list where we will put variables
70 public void getOutsideVariable(final List list) {
71 condition.getOutsideVariable(list); // todo: check if unuseful
72 if (statement != null) {
73 statement.getOutsideVariable(list);
75 for (int i = 0; i < elseifs.length; i++) {
76 elseifs[i].getOutsideVariable(list);
79 els.getOutsideVariable(list);
84 * get the modified variables.
86 * @param list the list where we will put variables
88 public void getModifiedVariable(final List list) {
89 condition.getModifiedVariable(list);
90 if (statement != null) {
91 statement.getModifiedVariable(list);
93 for (int i = 0; i < elseifs.length; i++) {
94 elseifs[i].getModifiedVariable(list);
97 els.getModifiedVariable(list);
102 * Get the variables used.
104 * @param list the list where we will put variables
106 public void getUsedVariable(final List list) {
107 condition.getUsedVariable(list);
108 if (statement != null) {
109 statement.getUsedVariable(list);
111 for (int i = 0; i < elseifs.length; i++) {
112 elseifs[i].getUsedVariable(list);
115 els.getUsedVariable(list);