1 package net.sourceforge.phpdt.internal.compiler.ast;
7 * for(initializations;condition;increments) action
8 * @author Matthieu Casanova
10 public class ForStatement extends Statement {
12 /** the initializations. */
13 public Expression[] initializations;
16 public Expression condition;
17 /** the increments. */
18 public Expression[] increments;
20 public Statement action;
24 * @param initializations the initializations expressions
25 * @param condition the condition when the for get out
26 * @param increments the increments statements
27 * @param action the action (a statement, a block ...)
28 * @param sourceStart the beginning sources
29 * @param sourceEnd the ending sources
31 public ForStatement(final Expression[] initializations,
32 final Expression condition,
33 final Expression[] increments,
34 final Statement action,
35 final int sourceStart,
36 final int sourceEnd) {
37 super(sourceStart, sourceEnd);
38 this.initializations = initializations;
39 this.condition = condition;
40 this.increments = increments;
44 public String toString(final int tab) {
45 final StringBuffer buff = new StringBuffer(tabString(tab));
46 buff.append("for ("); //$NON-NLS-1$
48 if (initializations != null) {
49 for (int i = 0; i < initializations.length; i++) {
50 buff.append(initializations[i].toStringExpression());
51 if (i != (initializations.length - 1))
52 buff.append(" , "); //$NON-NLS-1$
55 buff.append("; "); //$NON-NLS-1$
57 if (condition != null) {
58 buff.append(condition.toStringExpression());
60 buff.append("; "); //$NON-NLS-1$
62 if (increments != null) {
63 for (int i = 0; i < increments.length; i++) {
64 //nice only with expressions
65 buff.append(increments[i].toStringExpression());
66 if (i != (increments.length - 1))
67 buff.append(" , "); //$NON-NLS-1$
70 buff.append(") "); //$NON-NLS-1$
73 buff.append("{}"); //$NON-NLS-1$
75 buff.append(action.toString(tab + 1)); //$NON-NLS-1$
76 return buff.toString();
80 * Get the variables from outside (parameters, globals ...)
82 public void getOutsideVariable(final List list) {
83 if (condition != null) {
84 condition.getOutsideVariable(list);
87 action.getOutsideVariable(list);
89 if (initializations != null) {
90 for (int i = 0; i < initializations.length; i++) {
91 initializations[i].getOutsideVariable(list);
94 if (increments != null) {
95 for (int i = 0; i < increments.length; i++) {
96 increments[i].getOutsideVariable(list);
102 * get the modified variables.
104 public void getModifiedVariable(final List list) {
105 if (condition != null) {
106 condition.getModifiedVariable(list);
108 if (action != null) {
109 action.getModifiedVariable(list);
111 if (initializations != null) {
112 for (int i = 0; i < initializations.length; i++) {
113 initializations[i].getModifiedVariable(list);
116 if (increments != null) {
117 for (int i = 0; i < increments.length; i++) {
118 increments[i].getModifiedVariable(list);
124 * Get the variables used.
126 public void getUsedVariable(final List list) {
127 if (condition != null) {
128 condition.getUsedVariable(list);
130 if (action != null) {
131 action.getUsedVariable(list);
133 if (initializations != null) {
134 for (int i = 0; i < initializations.length; i++) {
135 initializations[i].getUsedVariable(list);
138 if (increments != null) {
139 for (int i = 0; i < increments.length; i++) {
140 increments[i].getUsedVariable(list);