Class Macro.MacroEvaluationContext
- java.lang.Object
-
- com.google.auto.value.processor.escapevelocity.Macro.MacroEvaluationContext
-
- All Implemented Interfaces:
EvaluationContext
- Enclosing class:
- Macro
static class Macro.MacroEvaluationContext extends java.lang.Object implements EvaluationContext
The context for evaluation within macros. This wraps an existingEvaluationContext
but intercepts reads of the macro's parameters so that they result in a call-by-name evaluation of whatever was passed as the parameter. For example, if you write...
...then the#macro (mymacro $x) $x $x #end #mymacro($foo.bar(23))
#mymacro
call will result in$foo.bar(23)
being evaluated twice, once for each time$x
appears. The way this works is that$x
is a thunk. Historically a thunk is a piece of code to evaluate an expression in the context where it occurs, for call-by-name procedures as in Algol 60. Here, it is not exactly a piece of code, but it has the same responsibility.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.google.auto.value.processor.escapevelocity.EvaluationContext
EvaluationContext.PlainEvaluationContext
-
-
Field Summary
Fields Modifier and Type Field Description private EvaluationContext
originalEvaluationContext
private java.util.Map<java.lang.String,Node>
parameterThunks
-
Constructor Summary
Constructors Constructor Description MacroEvaluationContext(java.util.Map<java.lang.String,Node> parameterThunks, EvaluationContext originalEvaluationContext)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
getVar(java.lang.String var)
java.lang.Runnable
setVar(java.lang.String var, java.lang.Object value)
Sets the given variable to the given value.boolean
varIsDefined(java.lang.String var)
-
-
-
Field Detail
-
parameterThunks
private final java.util.Map<java.lang.String,Node> parameterThunks
-
originalEvaluationContext
private final EvaluationContext originalEvaluationContext
-
-
Constructor Detail
-
MacroEvaluationContext
MacroEvaluationContext(java.util.Map<java.lang.String,Node> parameterThunks, EvaluationContext originalEvaluationContext)
-
-
Method Detail
-
getVar
public java.lang.Object getVar(java.lang.String var)
- Specified by:
getVar
in interfaceEvaluationContext
-
varIsDefined
public boolean varIsDefined(java.lang.String var)
- Specified by:
varIsDefined
in interfaceEvaluationContext
-
setVar
public java.lang.Runnable setVar(java.lang.String var, java.lang.Object value)
Description copied from interface:EvaluationContext
Sets the given variable to the given value.- Specified by:
setVar
in interfaceEvaluationContext
- Returns:
- a Runnable that will restore the variable to the value it had before. If the variable
was undefined before this method was executed, the Runnable will make it undefined again.
This allows us to restore the state of
$x
after#foreach ($x in ...)
.
-
-