Top Description Inners Fields Constructors Methods
com.google.escapevelocity

pack-priv abstract Class ReferenceNode

extends ExpressionNode
Class Inheritance
Known Direct Subclasses
com.google.escapevelocity.ReferenceNode.PlainReferenceNode, com.google.escapevelocity.ReferenceNode.MemberReferenceNode, com.google.escapevelocity.ReferenceNode.IndexReferenceNode, com.google.escapevelocity.ReferenceNode.MethodReferenceNode
Static Imports
java.util.stream.Collectors.toList

A node in the parse tree that is a reference. A reference is anything beginning with $, such as $x or $x[$i].foo($j).
Author
[email protected] (Éamonn McManus)

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
ReferenceNode.IndexReferenceNode

A node in the parse tree that is an indexing of a reference, like $x[0] or $x.foo[$i].

pack-priv static class
ReferenceNode.MemberReferenceNode

A node in the parse tree that is a reference to a property of another reference, like $x.foo or $x[$i].foo.

pack-priv static class
ReferenceNode.MethodReferenceNode

A node in the parse tree representing a method reference, like $list.size().

pack-priv static class
ReferenceNode.PlainReferenceNode

A node in the parse tree that is a plain reference such as $x.

Field Summary

Modifier and TypeField and Description
pack-priv final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
ReferenceNode(String resourceName, int lineNumber, boolean silent)

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
evaluateLhs(ReferenceNode lhs, EvaluationContext context)

Evaluates the first part of a complex reference, for example $foo in $foo.bar.

pack-priv EvaluationException
pack-priv Object
invokeMethod(Method method, Object target, List<Object> argValues)

Invoke the given method on the given target with the given arguments.

pack-priv boolean
isSilent()

Overrides com.google.escapevelocity.ExpressionNode.isSilent.

True if a null value for this expression is silently translated to an empty string when substituted into template text.
Inherited from com.google.escapevelocity.ExpressionNode:
evaluateevaluateintValueisTruerendertoString

Field Detail

silentback to summary
pack-priv final boolean silent

Constructor Detail

ReferenceNodeback to summary
pack-priv ReferenceNode(String resourceName, int lineNumber, boolean silent)

Method Detail

evaluateLhsback to summary
pack-priv Object evaluateLhs(ReferenceNode lhs, EvaluationContext context)

Evaluates the first part of a complex reference, for example $foo in $foo.bar. It must not be null, and it must not be a macro's $bodyContent or the result of a #define.

evaluationExceptionInThisback to summary
pack-priv EvaluationException evaluationExceptionInThis(String message)
invokeMethodback to summary
pack-priv Object invokeMethod(Method method, Object target, List<Object> argValues)

Invoke the given method on the given target with the given arguments.

isSilentback to summary
pack-priv boolean isSilent()

Overrides com.google.escapevelocity.ExpressionNode.isSilent.

Doc from com.google.escapevelocity.ExpressionNode.isSilent.

True if a null value for this expression is silently translated to an empty string when substituted into template text. Otherwise it results in an exception.

Annotations
@Override
com.google.escapevelocity back to summary

pack-priv Class ReferenceNode.IndexReferenceNode

extends ReferenceNode
Class Inheritance

A node in the parse tree that is an indexing of a reference, like $x[0] or $x.foo[$i]. Indexing is array indexing or calling the get method of a list or a map.

Field Summary

Modifier and TypeField and Description
pack-priv final ExpressionNode
pack-priv final ReferenceNode
Inherited from com.google.escapevelocity.ReferenceNode:
silent

Constructor Summary

AccessConstructor and Description
pack-priv
IndexReferenceNode(ReferenceNode lhs, ExpressionNode index, boolean silent)

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
evaluate(EvaluationContext
the context of the evaluation, for example the $variables that are in scope
context
,
boolean
whether an undefined plain reference like $foo is considered to be false. This is the case when evaluating the condition in an #if. Everywhere else, an undefined reference causes an exception.
undefinedIsFalse
)

Implements abstract com.google.escapevelocity.ExpressionNode.evaluate.

Returns the result of evaluating this node in the given context.
public String
toString()

Implements abstract com.google.escapevelocity.ExpressionNode.toString.

Returns the source form of this node.
Inherited from com.google.escapevelocity.ReferenceNode:
evaluateLhsevaluationExceptionInThisinvokeMethodisSilent

Field Detail

indexback to summary
pack-priv final ExpressionNode index
lhsback to summary
pack-priv final ReferenceNode lhs

Constructor Detail

IndexReferenceNodeback to summary
pack-priv IndexReferenceNode(ReferenceNode lhs, ExpressionNode index, boolean silent)

Method Detail

evaluateback to summary
pack-priv Object evaluate(EvaluationContext context, boolean undefinedIsFalse)

Implements abstract com.google.escapevelocity.ExpressionNode.evaluate.

Doc from com.google.escapevelocity.ExpressionNode.evaluate.

Returns the result of evaluating this node in the given context. This result may be used as part of a further operation, for example evaluating 2 + 3 to 5 in order to set $x to 5 in #set ($x = 2 + 3). Or it may be used directly as part of the template output, for example evaluating replacing name by Fred in My name is $name..

This has to be an Object rather than a String (or rather than appending to a StringBuilder) because it can potentially participate in other operations. In the preceding example, the nodes representing 2 and 3 and the node representing 2 + 3 all return Integer. As another example, in #if ($foo.bar < 3) the value $foo is itself an ExpressionNode which evaluates to the object referenced by the foo variable, and $foo.bar is another ExpressionNode that takes the value from foo and looks for the property bar in it.

Parameters
context:EvaluationContext

the context of the evaluation, for example the $variables that are in scope

undefinedIsFalse:boolean

whether an undefined plain reference like $foo is considered to be false. This is the case when evaluating the condition in an #if. Everywhere else, an undefined reference causes an exception.

Annotations
@Override
toStringback to summary
public String toString()

Implements abstract com.google.escapevelocity.ExpressionNode.toString.

Doc from com.google.escapevelocity.ExpressionNode.toString.

Returns the source form of this node. This may not be exactly how it appears in the template. For example both $x and ${x} end up being the same kind of node, and its toString() is "$x".

This method is used in error messages. It is not invoked in normal template evaluation.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
com.google.escapevelocity back to summary

pack-priv Class ReferenceNode.MemberReferenceNode

extends ReferenceNode
Class Inheritance

A node in the parse tree that is a reference to a property of another reference, like $x.foo or $x[$i].foo.

Field Summary

Modifier and TypeField and Description
private static final boolean[]
pack-priv final String
pack-priv final ReferenceNode
private static final String[]
Inherited from com.google.escapevelocity.ReferenceNode:
silent

Constructor Summary

AccessConstructor and Description
pack-priv
MemberReferenceNode(ReferenceNode lhs, String id, boolean silent)

Method Summary

Modifier and TypeMethod and Description
private static String
pack-priv Object
evaluate(EvaluationContext
the context of the evaluation, for example the $variables that are in scope
context
,
boolean
whether an undefined plain reference like $foo is considered to be false. This is the case when evaluating the condition in an #if. Everywhere else, an undefined reference causes an exception.
undefinedIsFalse
)

Implements abstract com.google.escapevelocity.ExpressionNode.evaluate.

Returns the result of evaluating this node in the given context.
public String
toString()

Implements abstract com.google.escapevelocity.ExpressionNode.toString.

Returns the source form of this node.
Inherited from com.google.escapevelocity.ReferenceNode:
evaluateLhsevaluationExceptionInThisinvokeMethodisSilent

Field Detail

CHANGE_CASEback to summary
private static final boolean[] CHANGE_CASE
idback to summary
pack-priv final String id
lhsback to summary
pack-priv final ReferenceNode lhs
PREFIXESback to summary
private static final String[] PREFIXES

Constructor Detail

MemberReferenceNodeback to summary
pack-priv MemberReferenceNode(ReferenceNode lhs, String id, boolean silent)

Method Detail

changeInitialCaseback to summary
private static String changeInitialCase(String id)
evaluateback to summary
pack-priv Object evaluate(EvaluationContext context, boolean undefinedIsFalse)

Implements abstract com.google.escapevelocity.ExpressionNode.evaluate.

Doc from com.google.escapevelocity.ExpressionNode.evaluate.

Returns the result of evaluating this node in the given context. This result may be used as part of a further operation, for example evaluating 2 + 3 to 5 in order to set $x to 5 in #set ($x = 2 + 3). Or it may be used directly as part of the template output, for example evaluating replacing name by Fred in My name is $name..

This has to be an Object rather than a String (or rather than appending to a StringBuilder) because it can potentially participate in other operations. In the preceding example, the nodes representing 2 and 3 and the node representing 2 + 3 all return Integer. As another example, in #if ($foo.bar < 3) the value $foo is itself an ExpressionNode which evaluates to the object referenced by the foo variable, and $foo.bar is another ExpressionNode that takes the value from foo and looks for the property bar in it.

Parameters
context:EvaluationContext

the context of the evaluation, for example the $variables that are in scope

undefinedIsFalse:boolean

whether an undefined plain reference like $foo is considered to be false. This is the case when evaluating the condition in an #if. Everywhere else, an undefined reference causes an exception.

Annotations
@Override
toStringback to summary
public String toString()

Implements abstract com.google.escapevelocity.ExpressionNode.toString.

Doc from com.google.escapevelocity.ExpressionNode.toString.

Returns the source form of this node. This may not be exactly how it appears in the template. For example both $x and ${x} end up being the same kind of node, and its toString() is "$x".

This method is used in error messages. It is not invoked in normal template evaluation.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
com.google.escapevelocity back to summary

pack-priv Class ReferenceNode.MethodReferenceNode

extends ReferenceNode
Class Inheritance

A node in the parse tree representing a method reference, like $list.size().

Field Summary

Modifier and TypeField and Description
pack-priv final List<ExpressionNode>
pack-priv final String
private static final int
pack-priv final ReferenceNode
private static final ImmutableList<Class<?>>
Inherited from com.google.escapevelocity.ReferenceNode:
silent

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static boolean
compatibleArgs(Class<?>[] paramTypes, List<Object> argValues)

Determines if the given argument list is compatible with the given parameter types.

pack-priv Object
evaluate(EvaluationContext
the context of the evaluation, for example the $variables that are in scope
context
,
boolean
whether an undefined plain reference like $foo is considered to be false. This is the case when evaluating the condition in an #if. Everywhere else, an undefined reference causes an exception.
undefinedIsFalse
)

Implements abstract com.google.escapevelocity.ExpressionNode.evaluate.

Returns the result of evaluating this node in the given context.
private Object
evaluate(EvaluationContext context, Object lhsValue, Class<?> targetClass)

private static boolean
primitiveIsCompatible(Class<?> primitive, Object value)

pack-priv static boolean
primitiveTypeIsAssignmentCompatible(Class<?> to, Class<?> from)

Returns true if from can be assigned to to according to Widening Primitive Conversion.

public String
toString()

Implements abstract com.google.escapevelocity.ExpressionNode.toString.

Returns the source form of this node.
Inherited from com.google.escapevelocity.ReferenceNode:
evaluateLhsevaluationExceptionInThisinvokeMethodisSilent

Field Detail

argsback to summary
pack-priv final List<ExpressionNode> args
idback to summary
pack-priv final String id
INDEX_OF_INTback to summary
private static final int INDEX_OF_INT
lhsback to summary
pack-priv final ReferenceNode lhs
NUMERICAL_PRIMITIVESback to summary
private static final ImmutableList<Class<?>> NUMERICAL_PRIMITIVES

Constructor Detail

MethodReferenceNodeback to summary
pack-priv MethodReferenceNode(ReferenceNode lhs, String id, List<ExpressionNode> args, boolean silent)

Method Detail

compatibleArgsback to summary
pack-priv static boolean compatibleArgs(Class<?>[] paramTypes, List<Object> argValues)

Determines if the given argument list is compatible with the given parameter types. This includes an Integer argument being compatible with a parameter of type int or long, for example.

evaluateback to summary
pack-priv Object evaluate(EvaluationContext context, boolean undefinedIsFalse)

Implements abstract com.google.escapevelocity.ExpressionNode.evaluate.

Doc from com.google.escapevelocity.ExpressionNode.evaluate.

Returns the result of evaluating this node in the given context. This result may be used as part of a further operation, for example evaluating 2 + 3 to 5 in order to set $x to 5 in #set ($x = 2 + 3). Or it may be used directly as part of the template output, for example evaluating replacing name by Fred in My name is $name..

This has to be an Object rather than a String (or rather than appending to a StringBuilder) because it can potentially participate in other operations. In the preceding example, the nodes representing 2 and 3 and the node representing 2 + 3 all return Integer. As another example, in #if ($foo.bar < 3) the value $foo is itself an ExpressionNode which evaluates to the object referenced by the foo variable, and $foo.bar is another ExpressionNode that takes the value from foo and looks for the property bar in it.

Evaluating a method expression such as $x.foo($y) involves looking at the actual types of $x and $y. The type of $x must have a public method foo with a parameter type that is compatible with $y.

Currently we don't allow there to be more than one matching method. That is a difference from Velocity, which blithely allows you to invoke List#remove(int) even though it can't really know that you didn't mean to invoke List#remove(Object) with an Object that just happens to be an Integer.

The method to be invoked must be visible in a public class or interface that is either the class of $x itself or one of its supertypes. Allowing supertypes is important because you may want to invoke a public method like List#size() on a list whose class is not public, such as the list returned by java.util.Collections#singletonList.

Parameters
context:EvaluationContext

the context of the evaluation, for example the $variables that are in scope

undefinedIsFalse:boolean

whether an undefined plain reference like $foo is considered to be false. This is the case when evaluating the condition in an #if. Everywhere else, an undefined reference causes an exception.

Annotations
@Override
evaluateback to summary
private Object evaluate(EvaluationContext context, Object lhsValue, Class<?> targetClass)
primitiveIsCompatibleback to summary
private static boolean primitiveIsCompatible(Class<?> primitive, Object value)
primitiveTypeIsAssignmentCompatibleback to summary
pack-priv static boolean primitiveTypeIsAssignmentCompatible(Class<?> to, Class<?> from)

Returns true if from can be assigned to to according to Widening Primitive Conversion.

toStringback to summary
public String toString()

Implements abstract com.google.escapevelocity.ExpressionNode.toString.

Doc from com.google.escapevelocity.ExpressionNode.toString.

Returns the source form of this node. This may not be exactly how it appears in the template. For example both $x and ${x} end up being the same kind of node, and its toString() is "$x".

This method is used in error messages. It is not invoked in normal template evaluation.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
com.google.escapevelocity back to summary

pack-priv Class ReferenceNode.PlainReferenceNode

extends ReferenceNode
Class Inheritance

A node in the parse tree that is a plain reference such as $x. This node may appear inside a more complex reference like $x.foo.

Field Summary

Modifier and TypeField and Description
pack-priv final String
Inherited from com.google.escapevelocity.ReferenceNode:
silent

Constructor Summary

AccessConstructor and Description
pack-priv
PlainReferenceNode(String resourceName, int lineNumber, String id, boolean silent)

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
evaluate(EvaluationContext
the context of the evaluation, for example the $variables that are in scope
context
,
boolean
whether an undefined plain reference like $foo is considered to be false. This is the case when evaluating the condition in an #if. Everywhere else, an undefined reference causes an exception.
undefinedIsFalse
)

Implements abstract com.google.escapevelocity.ExpressionNode.evaluate.

Returns the result of evaluating this node in the given context.
public String
toString()

Implements abstract com.google.escapevelocity.ExpressionNode.toString.

Returns the source form of this node.
Inherited from com.google.escapevelocity.ReferenceNode:
evaluateLhsevaluationExceptionInThisinvokeMethodisSilent

Field Detail

idback to summary
pack-priv final String id

Constructor Detail

PlainReferenceNodeback to summary
pack-priv PlainReferenceNode(String resourceName, int lineNumber, String id, boolean silent)

Method Detail

evaluateback to summary
pack-priv Object evaluate(EvaluationContext context, boolean undefinedIsFalse)

Implements abstract com.google.escapevelocity.ExpressionNode.evaluate.

Doc from com.google.escapevelocity.ExpressionNode.evaluate.

Returns the result of evaluating this node in the given context. This result may be used as part of a further operation, for example evaluating 2 + 3 to 5 in order to set $x to 5 in #set ($x = 2 + 3). Or it may be used directly as part of the template output, for example evaluating replacing name by Fred in My name is $name..

This has to be an Object rather than a String (or rather than appending to a StringBuilder) because it can potentially participate in other operations. In the preceding example, the nodes representing 2 and 3 and the node representing 2 + 3 all return Integer. As another example, in #if ($foo.bar < 3) the value $foo is itself an ExpressionNode which evaluates to the object referenced by the foo variable, and $foo.bar is another ExpressionNode that takes the value from foo and looks for the property bar in it.

Parameters
context:EvaluationContext

the context of the evaluation, for example the $variables that are in scope

undefinedIsFalse:boolean

whether an undefined plain reference like $foo is considered to be false. This is the case when evaluating the condition in an #if. Everywhere else, an undefined reference causes an exception.

Annotations
@Override
toStringback to summary
public String toString()

Implements abstract com.google.escapevelocity.ExpressionNode.toString.

Doc from com.google.escapevelocity.ExpressionNode.toString.

Returns the source form of this node. This may not be exactly how it appears in the template. For example both $x and ${x} end up being the same kind of node, and its toString() is "$x".

This method is used in error messages. It is not invoked in normal template evaluation.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override