Class ReferenceNode.MethodReferenceNode
- java.lang.Object
-
- com.google.auto.value.processor.escapevelocity.Node
-
- com.google.auto.value.processor.escapevelocity.ExpressionNode
-
- com.google.auto.value.processor.escapevelocity.ReferenceNode
-
- com.google.auto.value.processor.escapevelocity.ReferenceNode.MethodReferenceNode
-
- Enclosing class:
- ReferenceNode
static class ReferenceNode.MethodReferenceNode extends ReferenceNode
A node in the parse tree representing a method reference, like$list.size()
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.auto.value.processor.escapevelocity.ReferenceNode
ReferenceNode.IndexReferenceNode, ReferenceNode.MemberReferenceNode, ReferenceNode.MethodReferenceNode, ReferenceNode.PlainReferenceNode
-
Nested classes/interfaces inherited from class com.google.auto.value.processor.escapevelocity.ExpressionNode
ExpressionNode.BinaryExpressionNode, ExpressionNode.NotExpressionNode
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.List<ExpressionNode>
args
(package private) java.lang.String
id
private static int
INDEX_OF_INT
(package private) ReferenceNode
lhs
private static com.google.common.collect.ImmutableList<java.lang.Class<?>>
NUMERICAL_PRIMITIVES
-
Fields inherited from class com.google.auto.value.processor.escapevelocity.Node
lineNumber, resourceName
-
-
Constructor Summary
Constructors Constructor Description MethodReferenceNode(ReferenceNode lhs, java.lang.String id, java.util.List<ExpressionNode> args)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) static boolean
compatibleArgs(java.lang.Class<?>[] paramTypes, java.util.List<java.lang.Object> argValues)
Determines if the given argument list is compatible with the given parameter types.(package private) java.lang.Object
evaluate(EvaluationContext context)
Returns the result of evaluating this node in the given context.private static boolean
primitiveIsCompatible(java.lang.Class<?> primitive, java.lang.Object value)
(package private) static boolean
primitiveTypeIsAssignmentCompatible(java.lang.Class<?> to, java.lang.Class<?> from)
-
Methods inherited from class com.google.auto.value.processor.escapevelocity.ReferenceNode
invokeMethod, visibleMethod
-
Methods inherited from class com.google.auto.value.processor.escapevelocity.ExpressionNode
intValue, isDefinedAndTrue, isTrue
-
Methods inherited from class com.google.auto.value.processor.escapevelocity.Node
cons, emptyNode, evaluationException, evaluationException
-
-
-
-
Field Detail
-
lhs
final ReferenceNode lhs
-
id
final java.lang.String id
-
args
final java.util.List<ExpressionNode> args
-
NUMERICAL_PRIMITIVES
private static final com.google.common.collect.ImmutableList<java.lang.Class<?>> NUMERICAL_PRIMITIVES
-
INDEX_OF_INT
private static final int INDEX_OF_INT
-
-
Constructor Detail
-
MethodReferenceNode
MethodReferenceNode(ReferenceNode lhs, java.lang.String id, java.util.List<ExpressionNode> args)
-
-
Method Detail
-
evaluate
java.lang.Object evaluate(EvaluationContext context)
Returns the result of evaluating this node in the given context. This result may be used as part of a further operation, for example evaluating2 + 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 replacingname
byFred
inMy name is $name.
.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 methodfoo
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 invokeList.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 likeList.size()
on a list whose class is not public, such as the list returned byCollections.singletonList(T)
.
-
compatibleArgs
static boolean compatibleArgs(java.lang.Class<?>[] paramTypes, java.util.List<java.lang.Object> argValues)
Determines if the given argument list is compatible with the given parameter types. This includes anInteger
argument being compatible with a parameter of typeint
orlong
, for example.
-
primitiveIsCompatible
private static boolean primitiveIsCompatible(java.lang.Class<?> primitive, java.lang.Object value)
-
primitiveTypeIsAssignmentCompatible
static boolean primitiveTypeIsAssignmentCompatible(java.lang.Class<?> to, java.lang.Class<?> from)
-
-