Class ASTReference
java.lang.Object
org.apache.velocity.runtime.parser.node.SimpleNode
org.apache.velocity.runtime.parser.node.ASTReference
- All Implemented Interfaces:
Node,Renderable
This class is responsible for handling the references in
VTL ($foo).
Please look at the Parser.jjt file which is
what controls the generation of this class.
- Version:
- $Id: ASTReference.java 832302 2009-11-03 05:32:31Z wglass $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ASTIndexnon null Indicates if we are setting an index reference e.g, $foo[2], which basically means that the last syntax of the reference are brackets.private booleanprivate booleanprivate Stringprivate static final intprivate Stringprivate Stringprivate booleanprivate Stringprivate static final intprivate Stringprivate intprivate static final intprivate intprivate Stringprivate static final intbooleanIndicates if we are using modified escape behavior in strict mode.booleanIndicates if we are running in strict reference mode.booleanIndicates if toString() should be called during condition evaluation just to ensure it does not return null.protected Info -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanevaluate(InternalContextAdapter context) Computes boolean value of this reference Returns the actual value of reference return type boolean, and 'true' if value is not nullexecute(Object o, InternalContextAdapter context) gets an Object that 'is' the value of the referenceprivate StringgetNullString(InternalContextAdapter context) This method helps to implement the "render literal if null" functionality.private StringgetRoot()Returns the 'root string', the reference keygetVariableValue(Context context, String variable) init(InternalContextAdapter context, Object data) jjtAccept(ParserVisitor visitor, Object data) static StringprintClass(Class clazz) Utility class to handle nulls when printing a class typebooleanrender(InternalContextAdapter context, Writer writer) gets the value of the reference and outputs it to the writer.booleansetValue(InternalContextAdapter context, Object value) Sets the value of a complex reference (something like $foo.bar) Currently used by ASTSetReference()value(InternalContextAdapter context) Methods inherited from class org.apache.velocity.runtime.parser.node.SimpleNode
childrenAccept, dump, getColumn, getFirstToken, getInfo, getLastToken, getLine, getLocation, getRuntimeServices, getTemplateName, getType, isInvalid, jjtAddChild, jjtClose, jjtGetChild, jjtGetNumChildren, jjtGetParent, jjtOpen, jjtSetParent, literal, setFirstToken, setInfo, setInvalid, toString, toString
-
Field Details
-
NORMAL_REFERENCE
private static final int NORMAL_REFERENCE- See Also:
-
FORMAL_REFERENCE
private static final int FORMAL_REFERENCE- See Also:
-
QUIET_REFERENCE
private static final int QUIET_REFERENCE- See Also:
-
RUNT
private static final int RUNT- See Also:
-
referenceType
private int referenceType -
nullString
-
rootString
-
escaped
private boolean escaped -
computableReference
private boolean computableReference -
logOnNull
private boolean logOnNull -
escPrefix
-
morePrefix
-
identifier
-
literal
-
strictRef
public boolean strictRefIndicates if we are running in strict reference mode. -
astIndex
non null Indicates if we are setting an index reference e.g, $foo[2], which basically means that the last syntax of the reference are brackets. -
strictEscape
public boolean strictEscapeIndicates if we are using modified escape behavior in strict mode. mainly we allow \$abc -> to render as $abc -
toStringNullCheck
public boolean toStringNullCheckIndicates if toString() should be called during condition evaluation just to ensure it does not return null. Check is unnecessary if all toString() implementations are known to have non-null return values. Disabling the check will give a performance improval since toString() may be a complex operation on large objects. -
numChildren
private int numChildren -
uberInfo
-
-
Constructor Details
-
ASTReference
public ASTReference(int id) - Parameters:
id-
-
ASTReference
- Parameters:
p-id-
-
-
Method Details
-
jjtAccept
- Specified by:
jjtAcceptin interfaceNode- Overrides:
jjtAcceptin classSimpleNode- Returns:
- The Node execution result object.
- See Also:
-
init
- Specified by:
initin interfaceNode- Overrides:
initin classSimpleNode- Returns:
- The init result.
- Throws:
TemplateInitException- See Also:
-
getRootString
Returns the 'root string', the reference key- Returns:
- the root string.
-
execute
gets an Object that 'is' the value of the reference- Specified by:
executein interfaceNode- Overrides:
executein classSimpleNode- Parameters:
o- unused Object parametercontext- context used to generate value- Returns:
- The execution result.
- Throws:
MethodInvocationException- See Also:
-
render
public boolean render(InternalContextAdapter context, Writer writer) throws IOException, MethodInvocationException gets the value of the reference and outputs it to the writer.- Specified by:
renderin interfaceNode- Specified by:
renderin interfaceRenderable- Overrides:
renderin classSimpleNode- Parameters:
context- context of data to use in getting valuewriter- writer to render to- Returns:
- True if rendering was successful.
- Throws:
IOExceptionMethodInvocationException- See Also:
-
getNullString
This method helps to implement the "render literal if null" functionality. VelocimacroProxy saves references to macro arguments (AST nodes) so that if we have a macro #foobar($a $b) then there is key "$a.literal" which points to the literal presentation of the argument provided to variable $a. If the value of $a is null, we render the string that was provided as the argument.- Parameters:
context-- Returns:
-
evaluate
Computes boolean value of this reference Returns the actual value of reference return type boolean, and 'true' if value is not null- Specified by:
evaluatein interfaceNode- Overrides:
evaluatein classSimpleNode- Parameters:
context- context to compute value with- Returns:
- True if evaluation was ok.
- Throws:
MethodInvocationException- See Also:
-
value
- Specified by:
valuein interfaceNode- Overrides:
valuein classSimpleNode- Returns:
- The node value.
- Throws:
MethodInvocationException- See Also:
-
printClass
Utility class to handle nulls when printing a class type -
setValue
public boolean setValue(InternalContextAdapter context, Object value) throws MethodInvocationException Sets the value of a complex reference (something like $foo.bar) Currently used by ASTSetReference()- Parameters:
context- context object containing this referencevalue- Object to set as value- Returns:
- true if successful, false otherwise
- Throws:
MethodInvocationException- See Also:
-
getRoot
-
getVariableValue
- Parameters:
context-variable-- Returns:
- The evaluated value of the variable.
- Throws:
MethodInvocationException
-
getDollarBang
-