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 ...)
 
  69   public void getOutsideVariable(final List list) {
 
  70     condition.getOutsideVariable(list); // todo: check if unuseful
 
  71     if (statement != null) {
 
  72       statement.getOutsideVariable(list);
 
  74     for (int i = 0; i < elseifs.length; i++) {
 
  75       elseifs[i].getOutsideVariable(list);
 
  78       els.getOutsideVariable(list);
 
  83    * get the modified variables.
 
  85   public void getModifiedVariable(final List list) {
 
  86     condition.getModifiedVariable(list);
 
  87     if (statement != null) {
 
  88       statement.getModifiedVariable(list);
 
  90     for (int i = 0; i < elseifs.length; i++) {
 
  91       elseifs[i].getModifiedVariable(list);
 
  94       els.getModifiedVariable(list);
 
  99    * Get the variables used.
 
 101   public void getUsedVariable(final List list) {
 
 102     condition.getUsedVariable(list);
 
 103     if (statement != null) {
 
 104       statement.getUsedVariable(list);
 
 106     for (int i = 0; i < elseifs.length; i++) {
 
 107       elseifs[i].getUsedVariable(list);
 
 110       els.getUsedVariable(list);