Modifier and Type | Field and Description |
---|---|
protected Expression |
conditionExpression |
protected Emitter |
whenFalse |
protected Emitter |
whenTrue |
startOfBlock
Constructor and Description |
---|
ConditionalEmitter(parsii.tokenizer.Position startOfBlock)
Creates a new emitter for the given position.
|
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 |
propagateVisitor(EmitterVisitor visitor)
Invokes the visitor on all sub emitters and on this emitter itself.
|
Emitter |
reduce()
Reduces the condition as well as the true and false blocks.
|
void |
setConditionExpression(Expression conditionExpression)
Specifies the expression to evaluate to determine which block to emit.
|
void |
setWhenFalse(Emitter whenFalse)
Specifies the block to emit if the condition evaluates to false.
|
void |
setWhenTrue(Emitter whenTrue)
Specifies the block to emit if the condition evaluates to true.
|
String |
toString() |
void |
visitExpressions(Function<parsii.tokenizer.Position,ExpressionVisitor> visitorSupplier)
Visits all expressions contained in this emitter or its children.
|
emit, getStartOfBlock
protected Expression conditionExpression
protected Emitter whenTrue
protected Emitter whenFalse
public ConditionalEmitter(parsii.tokenizer.Position startOfBlock)
startOfBlock
- the position where the conditional block was defined.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 void setConditionExpression(Expression conditionExpression)
conditionExpression
- the condition as expressionpublic void setWhenTrue(Emitter whenTrue)
whenTrue
- the block to emit when the condition is truepublic void setWhenFalse(Emitter whenFalse)
whenFalse
- the block to emit when the condition is falsepublic 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()
If the condition becomes constant, the emitter is reduced the the repective true or false block.
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).Copyright © 2018. All rights reserved.