1 package net.sourceforge.phpdt.internal.compiler.ast;
4 import java.util.ArrayList;
8 * for(initializations;condition;increments) action
9 * @author Matthieu Casanova
11 public class ForStatement extends Statement {
13 /** the initializations. */
14 public Expression[] initializations;
17 public Expression condition;
18 /** the increments. */
19 public Expression[] increments;
21 public Statement action;
25 * @param initializations the initializations expressions
26 * @param condition the condition when the for get out
27 * @param increments the increments statements
28 * @param action the action (a statement, a block ...)
29 * @param sourceStart the beginning sources
30 * @param sourceEnd the ending sources
32 public ForStatement(final Expression[] initializations,
33 final Expression condition,
34 final Expression[] increments,
35 final Statement action,
36 final int sourceStart,
37 final int sourceEnd) {
38 super(sourceStart, sourceEnd);
39 this.initializations = initializations;
40 this.condition = condition;
41 this.increments = increments;
45 public String toString(final int tab) {
46 final StringBuffer buff = new StringBuffer(tabString(tab));
47 buff.append("for ("); //$NON-NLS-1$
49 if (initializations != null) {
50 for (int i = 0; i < initializations.length; i++) {
51 buff.append(initializations[i].toStringExpression());
52 if (i != (initializations.length - 1))
53 buff.append(" , "); //$NON-NLS-1$
56 buff.append("; "); //$NON-NLS-1$
58 if (condition != null) {
59 buff.append(condition.toStringExpression());
61 buff.append("; "); //$NON-NLS-1$
63 if (increments != null) {
64 for (int i = 0; i < increments.length; i++) {
65 //nice only with expressions
66 buff.append(increments[i].toStringExpression());
67 if (i != (increments.length - 1))
68 buff.append(" , "); //$NON-NLS-1$
71 buff.append(") "); //$NON-NLS-1$
74 buff.append("{}"); //$NON-NLS-1$
76 buff.append(action.toString(tab + 1)); //$NON-NLS-1$
77 return buff.toString();
81 * Get the variables from outside (parameters, globals ...)
83 public void getOutsideVariable(final List list) {
84 if (condition != null) {
85 condition.getOutsideVariable(list);
88 action.getOutsideVariable(list);
90 if (initializations != null) {
91 for (int i = 0; i < initializations.length; i++) {
92 initializations[i].getOutsideVariable(list);
95 if (increments != null) {
96 for (int i = 0; i < increments.length; i++) {
97 increments[i].getOutsideVariable(list);
103 * get the modified variables.
105 public void getModifiedVariable(final List list) {
106 if (condition != null) {
107 condition.getModifiedVariable(list);
109 if (action != null) {
110 action.getModifiedVariable(list);
112 if (initializations != null) {
113 for (int i = 0; i < initializations.length; i++) {
114 initializations[i].getModifiedVariable(list);
117 if (increments != null) {
118 for (int i = 0; i < increments.length; i++) {
119 increments[i].getModifiedVariable(list);
125 * Get the variables used.
127 public void getUsedVariable(final List list) {
128 if (condition != null) {
129 condition.getUsedVariable(list);
131 if (action != null) {
132 action.getUsedVariable(list);
134 if (initializations != null) {
135 for (int i = 0; i < initializations.length; i++) {
136 initializations[i].getUsedVariable(list);
139 if (increments != null) {
140 for (int i = 0; i < increments.length; i++) {
141 increments[i].getUsedVariable(list);