X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/IfStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/IfStatement.java index e424d23..c61c049 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/IfStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/IfStatement.java @@ -1,5 +1,8 @@ package net.sourceforge.phpdt.internal.compiler.ast; +import java.util.List; +import java.util.ArrayList; + /** * This is a if statement. * if (condition) @@ -24,12 +27,12 @@ public class IfStatement extends Statement { * @param sourceStart the starting position * @param sourceEnd the ending offset */ - public IfStatement(Expression condition, - Statement statement, - ElseIf[] elseifs, - Else els, - int sourceStart, - int sourceEnd) { + public IfStatement(final Expression condition, + final Statement statement, + final ElseIf[] elseifs, + final Else els, + final int sourceStart, + final int sourceEnd) { super(sourceStart, sourceEnd); this.condition = condition; this.statement = statement; @@ -42,19 +45,70 @@ public class IfStatement extends Statement { * @param tab how many tabs (not used here * @return a String */ - public String toString(int tab) { + public String toString(final int tab) { final StringBuffer buff = new StringBuffer(tabString(tab)); - buff.append("if ("); - buff.append(condition.toStringExpression()).append(") "); - buff.append(statement.toString(tab+1)); + buff.append("if (");//$NON-NLS-1$ + buff.append(condition.toStringExpression()).append(") ");//$NON-NLS-1$ + buff.append(statement.toString(tab + 1)); for (int i = 0; i < elseifs.length; i++) { - buff.append(elseifs[i].toString(tab+1)); - buff.append("\n"); + buff.append(elseifs[i].toString(tab + 1)); + buff.append("\n");//$NON-NLS-1$ } if (els != null) { - buff.append(els.toString(tab+1)); - buff.append('\n'); + buff.append(els.toString(tab + 1)); + buff.append("\n");//$NON-NLS-1$ } return buff.toString(); } + + /** + * Get the variables from outside (parameters, globals ...) + * @return the variables from outside + */ + public List getOutsideVariable() { + final ArrayList list = new ArrayList(); + list.addAll(condition.getOutsideVariable()); // todo: check if unuseful + list.addAll(statement.getOutsideVariable()); + for (int i = 0; i < elseifs.length; i++) { + list.addAll(elseifs[i].getOutsideVariable()); + } + if (els != null) { + list.addAll(els.getOutsideVariable()); + } + return list; + } + + /** + * get the modified variables. + * @return the variables from we change value + */ + public List getModifiedVariable() { + final ArrayList list = new ArrayList(); + list.addAll(condition.getModifiedVariable()); + list.addAll(statement.getModifiedVariable()); + for (int i = 0; i < elseifs.length; i++) { + list.addAll(elseifs[i].getModifiedVariable()); + } + if (els != null) { + list.addAll(els.getModifiedVariable()); + } + return list; + } + + /** + * Get the variables used. + * @return the variables used + */ + public List getUsedVariable() { + final ArrayList list = new ArrayList(); + list.addAll(condition.getUsedVariable()); + list.addAll(statement.getUsedVariable()); + for (int i = 0; i < elseifs.length; i++) { + list.addAll(elseifs[i].getUsedVariable()); + } + if (els != null) { + list.addAll(els.getUsedVariable()); + } + return list; + } }