X-Git-Url: http://secure.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..689a737 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,21 @@ public class ForStatement extends Statement { public Statement action; - public ForStatement(Expression[] initializations, - Expression condition, - Expression[] increments, - Statement action, - int sourceStart, - int sourceEnd) { + /** + * a for statement + * @param initializations the initializations expressions + * @param condition the condition when the for get out + * @param increments the increments statements + * @param action the action (a statement, a block ...) + * @param sourceStart the beginning sources + * @param sourceEnd the ending sources + */ + 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 +42,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 +53,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 +76,79 @@ 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(); + if (condition != null) { + list.addAll(condition.getOutsideVariable()); + } + if (action != null) { + list.addAll(action.getOutsideVariable()); + } + if (initializations != null) { + for (int i = 0; i < initializations.length; i++) { + list.addAll(initializations[i].getOutsideVariable()); + } + } + if (increments != null) { + 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(); + if (condition != null) { + list.addAll(condition.getModifiedVariable()); + } + if (action != null) { + list.addAll(action.getModifiedVariable()); + } + if (initializations != null) { + for (int i = 0; i < initializations.length; i++) { + list.addAll(initializations[i].getModifiedVariable()); + } + } + if (increments != null) { + 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(); + if (condition != null) { + list.addAll(condition.getUsedVariable()); + } + if (action != null) { + list.addAll(action.getUsedVariable()); + } + if (initializations != null) { + for (int i = 0; i < initializations.length; i++) { + list.addAll(initializations[i].getUsedVariable()); + } + } + if (increments != null) { + for (int i = 0; i < increments.length; i++) { + list.addAll(increments[i].getUsedVariable()); + } + } + return list; + } }