public class BlockEmitter extends Emitter
Template blocks can be defined using <i:block>. These can be passed to a tag and invoked there. This invokation is represented by this emitter. If no parameter value was given, the tag body (which is the alternative) is evaluated.
startOfBlock
Constructor and Description |
---|
BlockEmitter(parsii.tokenizer.Position startOfBlock,
String name,
Emitter alternative)
Creates a new emitter which outputs the given block parameter at runtime or evaluates the given alternative.
|
Modifier and Type | Method and Description |
---|---|
Emitter |
copy()
Creates a deep copy of this emitter.
|
protected void |
emitToContext(LocalRenderContext context)
Actually produces the output while relying on the caller to properly handle any exception.
|
Emitter |
getAlternative()
Returns the alternative to evaluate if no block with the given name is available.
|
String |
getName()
Returns the name of the block being referenced.
|
Emitter |
propagateVisitor(EmitterVisitor visitor)
Invokes the visitor on all sub emitters and on this emitter itself.
|
Emitter |
reduce()
Performs static optimizations at compile time.
|
String |
toString() |
void |
visitExpressions(Function<parsii.tokenizer.Position,ExpressionVisitor> visitorSupplier)
Visits all expressions contained in this emitter or its children.
|
emit, getStartOfBlock
public BlockEmitter(parsii.tokenizer.Position startOfBlock, String name, Emitter alternative)
startOfBlock
- the position where the block was definedname
- the name of the block to evaluatealternative
- the alternative to evaluate if no block is givenBlockTag
protected void emitToContext(LocalRenderContext context) throws Exception
Emitter
emitToContext
in class Emitter
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
public Emitter copy()
Emitter
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.
public Emitter reduce()
Emitter
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.
public Emitter propagateVisitor(EmitterVisitor visitor)
Emitter
propagateVisitor
in class Emitter
visitor
- the visitor to invokepublic void visitExpressions(Function<parsii.tokenizer.Position,ExpressionVisitor> visitorSupplier)
Emitter
visitExpressions
in class Emitter
visitorSupplier
- a function which generates an ExpressionVisitor
while supplying the current position (for
improved error messages).public String getName()
public Emitter getAlternative()
Copyright © 2018. All rights reserved.