@Override protected void setupModelForLoop(TemplateModel model, ReferenceType thrownType, int index) throws TemplateException { super.setupModelForLoop(model, thrownType, index); if (indexVar != null) { model.setVariable(indexVar, index); } if (var != null) { model.setVariable(var, thrownType); } }
/** * Set up the model for the loop and process the body. * * @param block The block. * @param output The output. * @param model The model. * @return Whether to do the loop again. */ @Override public boolean processBody(B block, TemplateOutput<B> output, TemplateModel model) throws IOException, TemplateException { if (this.loop == null) { throw new TemplateException("The body of a template loop cannot be processed without the loop!"); } super.processBody(block, output, model); boolean hasNext = this.loop.hasNext(); if (hasNext) { setupModelForLoop(model, this.loop.next(), this.index++); } return hasNext; }
/** * Gets the loop, and sets up the model for the first iteration. * * @param block The block. * @param output The output. * @param model The model. * @return Whether to evaluate the body. */ @Override public boolean preProcess(B block, TemplateOutput<B> output, TemplateModel model) throws IOException, TemplateException { super.preProcess(block, output, model); this.loop = getLoop(model); this.index = 0; boolean hasNext = this.loop != null && this.loop.hasNext(); if (hasNext) { setupModelForLoop(model, this.loop.next(), this.index++); } return hasNext; }
@Override protected void setupModelForLoop(TemplateModel model, D declaration, int index) throws TemplateException { super.setupModelForLoop(model, declaration, index); this.currentDeclaration = DeclarationDecorator.decorate(declaration); if (this.var != null) { model.setVariable(this.var, currentDeclaration); } if (indexVar != null) { model.setVariable(indexVar, index); } }