package gw.rating.flow.domain uses com.google.common.collect.ImmutableList /** * A marker class so we can log the start of each iteration when worksheets are on. */ class LoopBodyCompoundStatement extends CompoundStatement { construct(loopStatement: LoopStatement, statements: ImmutableList) { super(statements) Parent = loopStatement } property get LoopStatement(): LoopStatement { return Parent as LoopStatement } /** * Needed to override this because CompoundStatement does not wrap its statements. We cannot change * {@link CompoundStatement#generate(GenerationContext)} because that would break the display code.
* * This method causes the {@link gw.rating.worksheet.WorksheetLogger#iteration(String, String, String, String, String, int)} * logging when worksheets are on. * * @param context the generation context to which to write the code */ override function generate(context: GenerationContext) { // To cause the worksheet iteration() logging to be generated even if loop body is empty. context.WorksheetHelper.wrapStatement(this, \ -> generateValue(context)) } /** * Generates the content for the statements in the loop body. * * @param context */ protected function generateValue(context: GenerationContext) { var lastStatementIndex = Statements.size() - 1 Statements.eachWithIndex(\ statement, i -> { statement.generate(context) if (i < lastStatementIndex) { context.append('\n') } }) } }