package net.sourceforge.phpdt.internal.compiler.ast; /** * A For statement. * for(initializations;condition;increments) action * @author Matthieu Casanova */ public class ForStatement extends Statement { /** the initializations. */ public Expression[] initializations; /** the condition. */ public Expression condition; /** the increments. */ public Expression[] increments; public Statement action; public ForStatement(Expression[] initializations, Expression condition, Expression[] increments, Statement action, int sourceStart, int sourceEnd) { super(sourceStart, sourceEnd); this.initializations = initializations; this.condition = condition; this.increments = increments; this.action = action; } public String toString(int tab) { final StringBuffer buff = new StringBuffer(tabString(tab)); buff.append("for ("); //$NON-NLS-1$ //inits if (initializations != null) { for (int i = 0; i < initializations.length; i++) { buff.append(initializations[i].toStringExpression()); if (i != (initializations.length - 1)) buff.append(" , "); //$NON-NLS-1$ } } buff.append( "; "); //$NON-NLS-1$ //cond if (condition != null) { buff.append(condition.toStringExpression()); } buff.append( "; "); //$NON-NLS-1$ //updates if (increments != null) { for (int i = 0; i < increments.length; i++) { //nice only with expressions buff.append(increments[i].toStringExpression()); if (i != (increments.length - 1)) buff.append(" , "); //$NON-NLS-1$ } } buff.append(") "); //$NON-NLS-1$ //block if (action == null) buff.append("{}"); //$NON-NLS-1$ else buff.append(action.toString(tab + 1)); //$NON-NLS-1$ return buff.toString(); } }