package net.sourceforge.phpdt.internal.compiler.ast;
import java.util.List;
-import java.util.ArrayList;
/**
* This is a if statement.
* else statement
* @author Matthieu Casanova
*/
-public class IfStatement extends Statement {
+public final class IfStatement extends Statement {
- public Expression condition;
- public Statement statement;
- public ElseIf[] elseifs;
- public Else els;
+ private final Expression condition;
+ private final Statement statement;
+ private final ElseIf[] elseifs;
+ private final Else els;
/**
* Create a new If statement.
final StringBuffer buff = new StringBuffer(tabString(tab));
buff.append("if (");//$NON-NLS-1$
buff.append(condition.toStringExpression()).append(") ");//$NON-NLS-1$
- buff.append(statement.toString(tab + 1));
+ if (statement != null) {
+ buff.append(statement.toString(tab + 1));
+ }
for (int i = 0; i < elseifs.length; i++) {
buff.append(elseifs[i].toString(tab + 1));
buff.append("\n");//$NON-NLS-1$
/**
* Get the variables from outside (parameters, globals ...)
- * @return the variables from outside
+ *
+ * @param list the list where we will put variables
*/
- public List getOutsideVariable() {
- final ArrayList list = new ArrayList();
- list.addAll(condition.getOutsideVariable()); // todo: check if unuseful
- list.addAll(statement.getOutsideVariable());
+ public void getOutsideVariable(final List list) {
+ condition.getOutsideVariable(list); // todo: check if unuseful
+ if (statement != null) {
+ statement.getOutsideVariable(list);
+ }
for (int i = 0; i < elseifs.length; i++) {
- list.addAll(elseifs[i].getOutsideVariable());
+ elseifs[i].getOutsideVariable(list);
}
if (els != null) {
- list.addAll(els.getOutsideVariable());
+ els.getOutsideVariable(list);
}
- return list;
}
/**
* get the modified variables.
- * @return the variables from we change value
+ *
+ * @param list the list where we will put variables
*/
- public List getModifiedVariable() {
- final ArrayList list = new ArrayList();
- list.addAll(condition.getModifiedVariable());
- list.addAll(statement.getModifiedVariable());
+ public void getModifiedVariable(final List list) {
+ condition.getModifiedVariable(list);
+ if (statement != null) {
+ statement.getModifiedVariable(list);
+ }
for (int i = 0; i < elseifs.length; i++) {
- list.addAll(elseifs[i].getModifiedVariable());
+ elseifs[i].getModifiedVariable(list);
}
if (els != null) {
- list.addAll(els.getModifiedVariable());
+ els.getModifiedVariable(list);
}
- return list;
}
/**
* Get the variables used.
- * @return the variables used
+ *
+ * @param list the list where we will put variables
*/
- public List getUsedVariable() {
- final ArrayList list = new ArrayList();
- list.addAll(condition.getUsedVariable());
- list.addAll(statement.getUsedVariable());
+ public void getUsedVariable(final List list) {
+ condition.getUsedVariable(list);
+ if (statement != null) {
+ statement.getUsedVariable(list);
+ }
for (int i = 0; i < elseifs.length; i++) {
- list.addAll(elseifs[i].getUsedVariable());
+ elseifs[i].getUsedVariable(list);
}
if (els != null) {
- list.addAll(els.getUsedVariable());
+ els.getUsedVariable(list);
}
- return list;
}
}