package net.sourceforge.phpdt.internal.compiler.ast;
import java.util.List;
-import java.util.ArrayList;
/**
* A do statement.
+ *
* @author Matthieu Casanova
*/
-public class DoStatement extends Statement {
+public final class DoStatement extends Statement {
/** The condition expression. */
- public Expression condition;
+ private final Expression condition;
/** The action of the while. (it could be a block) */
- public Statement action;
+ private final Statement action;
public DoStatement(final Expression condition,
final Statement action,
/**
* Return the object into String.
+ *
* @param tab how many tabs (not used here
* @return a String
*/
public String toString(final int tab) {
- final String s = tabString(tab);
- final StringBuffer buff = new StringBuffer("do ");//$NON-NLS-1$
+ final String conditionString = condition.toStringExpression();
+ final StringBuffer buff;
if (action == null) {
+ buff = new StringBuffer(17 + tab + conditionString.length());
+ buff.append("do ");//$NON-NLS-1$
buff.append(" {} ;"); //$NON-NLS-1$
} else {
- buff.append("\n").append(action.toString(tab + 1));//$NON-NLS-1$
+ final String actionString = action.toString(tab + 1);
+ buff = new StringBuffer(13 + conditionString.length() + actionString.length());
+ buff.append("do ");//$NON-NLS-1$
+ buff.append("\n");//$NON-NLS-1$
+ buff.append(actionString);
}
- buff.append(s).append(" while (");//$NON-NLS-1$
- buff.append(condition.toStringExpression()).append(")");//$NON-NLS-1$
+ buff.append(tabString(tab));
+ buff.append(" while (");//$NON-NLS-1$
+ buff.append(conditionString);
+ buff.append(")");//$NON-NLS-1$
return buff.toString();
}
/**
* Get the variables from outside (parameters, globals ...)
- * @return the variables from outside
+ *
+ * @param list the list where we will put variables
*/
- public List getOutsideVariable() {
- final ArrayList list = new ArrayList();
- list.addAll(condition.getOutsideVariable()); // todo: check if unuseful
- list.addAll(action.getOutsideVariable());
- return list;
+ public void getOutsideVariable(final List list) {
+ condition.getOutsideVariable(list); // todo: check if unuseful
+ action.getOutsideVariable(list);
}
/**
* get the modified variables.
- * @return the variables from we change value
+ *
+ * @param list the list where we will put variables
*/
- public List getModifiedVariable() {
- final ArrayList list = new ArrayList();
- list.addAll(condition.getModifiedVariable());
- list.addAll(action.getModifiedVariable());
- return list;
+ public void getModifiedVariable(final List list) {
+ condition.getModifiedVariable(list);
+ action.getModifiedVariable(list);
}
/**
* Get the variables used.
- * @return the variables used
+ *
+ * @param list the list where we will put variables
*/
- public List getUsedVariable() {
- final ArrayList list = new ArrayList();
- list.addAll(condition.getUsedVariable());
- list.addAll(action.getUsedVariable());
- return list;
+ public void getUsedVariable(final List list) {
+ condition.getUsedVariable(list);
+ action.getUsedVariable(list);
}
}