1 package net.sourceforge.phpdt.internal.compiler.ast;
7 * for(initializations;condition;increments) action
8 * @author Matthieu Casanova
10 public final class ForStatement extends Statement {
12 /** the initializations. */
13 private final Expression[] initializations;
16 private final Expression condition;
17 /** the increments. */
18 private final Expression[] increments;
20 private final 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 * @param list the list where we will put variables
85 public void getOutsideVariable(final List list) {
86 if (condition != null) {
87 condition.getOutsideVariable(list);
90 action.getOutsideVariable(list);
92 if (initializations != null) {
93 for (int i = 0; i < initializations.length; i++) {
94 initializations[i].getOutsideVariable(list);
97 if (increments != null) {
98 for (int i = 0; i < increments.length; i++) {
99 increments[i].getOutsideVariable(list);
105 * get the modified variables.
107 * @param list the list where we will put variables
109 public void getModifiedVariable(final List list) {
110 if (condition != null) {
111 condition.getModifiedVariable(list);
113 if (action != null) {
114 action.getModifiedVariable(list);
116 if (initializations != null) {
117 for (int i = 0; i < initializations.length; i++) {
118 initializations[i].getModifiedVariable(list);
121 if (increments != null) {
122 for (int i = 0; i < increments.length; i++) {
123 increments[i].getModifiedVariable(list);
129 * Get the variables used.
131 * @param list the list where we will put variables
133 public void getUsedVariable(final List list) {
134 if (condition != null) {
135 condition.getUsedVariable(list);
137 if (action != null) {
138 action.getUsedVariable(list);
140 if (initializations != null) {
141 for (int i = 0; i < initializations.length; i++) {
142 initializations[i].getUsedVariable(list);
145 if (increments != null) {
146 for (int i = 0; i < increments.length; i++) {
147 increments[i].getUsedVariable(list);