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;
23 public ForStatement(final Expression[] initializations,
24 final Expression condition,
25 final Expression[] increments,
26 final Statement action,
27 final int sourceStart,
28 final int sourceEnd) {
29 super(sourceStart, sourceEnd);
30 this.initializations = initializations;
31 this.condition = condition;
32 this.increments = increments;
36 public String toString(final int tab) {
37 final StringBuffer buff = new StringBuffer(tabString(tab));
38 buff.append("for ("); //$NON-NLS-1$
40 if (initializations != null) {
41 for (int i = 0; i < initializations.length; i++) {
42 buff.append(initializations[i].toStringExpression());
43 if (i != (initializations.length - 1))
44 buff.append(" , "); //$NON-NLS-1$
47 buff.append("; "); //$NON-NLS-1$
49 if (condition != null) {
50 buff.append(condition.toStringExpression());
52 buff.append("; "); //$NON-NLS-1$
54 if (increments != null) {
55 for (int i = 0; i < increments.length; i++) {
56 //nice only with expressions
57 buff.append(increments[i].toStringExpression());
58 if (i != (increments.length - 1))
59 buff.append(" , "); //$NON-NLS-1$
62 buff.append(") "); //$NON-NLS-1$
65 buff.append("{}"); //$NON-NLS-1$
67 buff.append(action.toString(tab + 1)); //$NON-NLS-1$
68 return buff.toString();
72 * Get the variables from outside (parameters, globals ...)
73 * @return the variables from outside
75 public List getOutsideVariable() {
76 final ArrayList list = new ArrayList();
77 list.addAll(condition.getOutsideVariable());
78 list.addAll(action.getOutsideVariable());
79 for (int i = 0; i < initializations.length; i++) {
80 list.addAll(initializations[i].getOutsideVariable());
82 for (int i = 0; i < increments.length; i++) {
83 list.addAll(increments[i].getOutsideVariable());
89 * get the modified variables.
90 * @return the variables from we change value
92 public List getModifiedVariable() {
93 final ArrayList list = new ArrayList();
94 list.addAll(condition.getModifiedVariable());
95 list.addAll(action.getModifiedVariable());
96 for (int i = 0; i < initializations.length; i++) {
97 list.addAll(initializations[i].getModifiedVariable());
99 for (int i = 0; i < increments.length; i++) {
100 list.addAll(increments[i].getModifiedVariable());
106 * Get the variables used.
107 * @return the variables used
109 public List getUsedVariable() {
110 final ArrayList list = new ArrayList();
111 list.addAll(condition.getUsedVariable());
112 list.addAll(action.getUsedVariable());
113 for (int i = 0; i < initializations.length; i++) {
114 list.addAll(initializations[i].getUsedVariable());
116 for (int i = 0; i < increments.length; i++) {
117 list.addAll(increments[i].getUsedVariable());