1 package net.sourceforge.phpdt.internal.compiler.ast;
6 * This is a if statement.
11 * @author Matthieu Casanova
13 public class IfStatement extends Statement {
15 public Expression condition;
16 public Statement statement;
17 public ElseIf[] elseifs;
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 public void getOutsideVariable(final List list) {
69 condition.getOutsideVariable(list); // todo: check if unuseful
70 if (statement != null) {
71 statement.getOutsideVariable(list);
73 for (int i = 0; i < elseifs.length; i++) {
74 elseifs[i].getOutsideVariable(list);
77 els.getOutsideVariable(list);
82 * get the modified variables.
84 public void getModifiedVariable(final List list) {
85 condition.getModifiedVariable(list);
86 if (statement != null) {
87 statement.getModifiedVariable(list);
89 for (int i = 0; i < elseifs.length; i++) {
90 elseifs[i].getModifiedVariable(list);
93 els.getModifiedVariable(list);
98 * Get the variables used.
100 public void getUsedVariable(final List list) {
101 condition.getUsedVariable(list);
102 if (statement != null) {
103 statement.getUsedVariable(list);
105 for (int i = 0; i < elseifs.length; i++) {
106 elseifs[i].getUsedVariable(list);
109 els.getUsedVariable(list);