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..9ee27d5 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,7 @@ package net.sourceforge.phpdt.internal.compiler.ast; +import java.util.List; + /** * A For statement. * for(initializations;condition;increments) action @@ -17,12 +19,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 +41,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 +52,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 +75,70 @@ public class ForStatement extends Statement { buff.append(action.toString(tab + 1)); //$NON-NLS-1$ return buff.toString(); } + + /** + * Get the variables from outside (parameters, globals ...) + */ + public void getOutsideVariable(final List list) { + if (condition != null) { + condition.getOutsideVariable(list); + } + if (action != null) { + action.getOutsideVariable(list); + } + if (initializations != null) { + for (int i = 0; i < initializations.length; i++) { + initializations[i].getOutsideVariable(list); + } + } + if (increments != null) { + for (int i = 0; i < increments.length; i++) { + increments[i].getOutsideVariable(list); + } + } + } + + /** + * get the modified variables. + */ + public void getModifiedVariable(final List list) { + if (condition != null) { + condition.getModifiedVariable(list); + } + if (action != null) { + action.getModifiedVariable(list); + } + if (initializations != null) { + for (int i = 0; i < initializations.length; i++) { + initializations[i].getModifiedVariable(list); + } + } + if (increments != null) { + for (int i = 0; i < increments.length; i++) { + increments[i].getModifiedVariable(list); + } + } + } + + /** + * Get the variables used. + */ + public void getUsedVariable(final List list) { + if (condition != null) { + condition.getUsedVariable(list); + } + if (action != null) { + action.getUsedVariable(list); + } + if (initializations != null) { + for (int i = 0; i < initializations.length; i++) { + initializations[i].getUsedVariable(list); + } + } + if (increments != null) { + for (int i = 0; i < increments.length; i++) { + increments[i].getUsedVariable(list); + } + } + } }