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 ...)
82 * @return the variables from outside
84 public List getOutsideVariable() {
85 final ArrayList list = new ArrayList();
86 if (condition != null) {
87 list.addAll(condition.getOutsideVariable());
90 list.addAll(action.getOutsideVariable());
92 if (initializations != null) {
93 for (int i = 0; i < initializations.length; i++) {
94 list.addAll(initializations[i].getOutsideVariable());
97 if (increments != null) {
98 for (int i = 0; i < increments.length; i++) {
99 list.addAll(increments[i].getOutsideVariable());
106 * get the modified variables.
107 * @return the variables from we change value
109 public List getModifiedVariable() {
110 final ArrayList list = new ArrayList();
111 if (condition != null) {
112 list.addAll(condition.getModifiedVariable());
114 if (action != null) {
115 list.addAll(action.getModifiedVariable());
117 if (initializations != null) {
118 for (int i = 0; i < initializations.length; i++) {
119 list.addAll(initializations[i].getModifiedVariable());
122 if (increments != null) {
123 for (int i = 0; i < increments.length; i++) {
124 list.addAll(increments[i].getModifiedVariable());
131 * Get the variables used.
132 * @return the variables used
134 public List getUsedVariable() {
135 final ArrayList list = new ArrayList();
136 if (condition != null) {
137 list.addAll(condition.getUsedVariable());
139 if (action != null) {
140 list.addAll(action.getUsedVariable());
142 if (initializations != null) {
143 for (int i = 0; i < initializations.length; i++) {
144 list.addAll(initializations[i].getUsedVariable());
147 if (increments != null) {
148 for (int i = 0; i < increments.length; i++) {
149 list.addAll(increments[i].getUsedVariable());