X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java index f808542..212d451 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ForStatement.java @@ -1,5 +1,8 @@ package net.sourceforge.phpdt.internal.compiler.ast; +import java.util.List; +import java.util.ArrayList; + /** * A For statement. * for(initializations;condition;increments) action @@ -17,12 +20,12 @@ public class ForStatement extends Statement { public Statement action; - public ForStatement(Expression[] initializations, - Expression condition, - Expression[] increments, - Statement action, - int sourceStart, - int sourceEnd) { + public ForStatement(final Expression[] initializations, + final Expression condition, + final Expression[] increments, + final Statement action, + final int sourceStart, + final int sourceEnd) { super(sourceStart, sourceEnd); this.initializations = initializations; this.condition = condition; @@ -30,7 +33,7 @@ public class ForStatement extends Statement { this.action = action; } - public String toString(int tab) { + public String toString(final int tab) { final StringBuffer buff = new StringBuffer(tabString(tab)); buff.append("for ("); //$NON-NLS-1$ //inits @@ -41,12 +44,12 @@ public class ForStatement extends Statement { buff.append(" , "); //$NON-NLS-1$ } } - buff.append( "; "); //$NON-NLS-1$ + buff.append("; "); //$NON-NLS-1$ //cond - if (condition != null) { + if (condition != null) { buff.append(condition.toStringExpression()); } - buff.append( "; "); //$NON-NLS-1$ + buff.append("; "); //$NON-NLS-1$ //updates if (increments != null) { for (int i = 0; i < increments.length; i++) { @@ -64,4 +67,55 @@ public class ForStatement extends Statement { buff.append(action.toString(tab + 1)); //$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()); + list.addAll(action.getOutsideVariable()); + for (int i = 0; i < initializations.length; i++) { + list.addAll(initializations[i].getOutsideVariable()); + } + for (int i = 0; i < increments.length; i++) { + list.addAll(increments[i].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(action.getModifiedVariable()); + for (int i = 0; i < initializations.length; i++) { + list.addAll(initializations[i].getModifiedVariable()); + } + for (int i = 0; i < increments.length; i++) { + list.addAll(increments[i].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(action.getUsedVariable()); + for (int i = 0; i < initializations.length; i++) { + list.addAll(initializations[i].getUsedVariable()); + } + for (int i = 0; i < increments.length; i++) { + list.addAll(increments[i].getUsedVariable()); + } + return list; + } }