public abstract class Emitter extends Object
Template
which generates text output when the template is rendered.Modifier and Type | Field and Description |
---|---|
protected parsii.tokenizer.Position |
startOfBlock
Contains the position in the source file where this emitter was created.
|
Modifier | Constructor and Description |
---|---|
protected |
Emitter(parsii.tokenizer.Position startOfBlock)
Contains a new emitter with the given position.
|
Modifier and Type | Method and Description |
---|---|
abstract Emitter |
copy()
Creates a deep copy of this emitter.
|
void |
emit(LocalRenderContext context)
Procudes the text output into the given context.
|
protected abstract void |
emitToContext(LocalRenderContext context)
Actually produces the output while relying on the caller to properly handle any exception.
|
parsii.tokenizer.Position |
getStartOfBlock()
Returns the start position within the source file.
|
abstract Emitter |
propagateVisitor(EmitterVisitor visitor)
Invokes the visitor on all sub emitters and on this emitter itself.
|
abstract Emitter |
reduce()
Performs static optimizations at compile time.
|
abstract void |
visitExpressions(Function<parsii.tokenizer.Position,ExpressionVisitor> visitor)
Visits all expressions contained in this emitter or its children.
|
protected parsii.tokenizer.Position startOfBlock
protected Emitter(@Nonnull parsii.tokenizer.Position startOfBlock)
startOfBlock
- the start position where the emitter was createdpublic void emit(@Nonnull LocalRenderContext context) throws RenderException
context
- the render context which provides access to the local and global environment and also the target
for the generated textRenderException
- in case of any exception which occurs during renderingprotected abstract void emitToContext(@Nonnull LocalRenderContext context) throws Exception
context
- the render context which provides access to the local and global environment and also the target
for the generated textException
- all thrown exceptions are caught and converted into a RenderException
@Nonnull public parsii.tokenizer.Position getStartOfBlock()
@Nonnull public abstract Emitter copy()
When templates are inlined, the parameters are propagated and constant expressions and conditions are evaluated at compile time. This yields faster and more efficient templates. In order to perform these optimizations, we need a copy of the template and all its emitters which can safely be modified.
@Nonnull public abstract Emitter reduce()
Certain emitters can perform optimizations (evaluate constant expressions, combine constant outputs etc.) to create more efficient templates. This is especially important when a template is inlined, as this most probably provides a higher level of optimizations.
@Nonnull public abstract Emitter propagateVisitor(@Nonnull EmitterVisitor visitor)
visitor
- the visitor to invokepublic abstract void visitExpressions(@Nonnull Function<parsii.tokenizer.Position,ExpressionVisitor> visitor)
visitor
- a function which generates an ExpressionVisitor
while supplying the current position (for
improved error messages).Copyright © 2018. All rights reserved.