static class ReferenceNode.MethodReferenceNode extends ReferenceNode
$list.size()
.ReferenceNode.IndexReferenceNode, ReferenceNode.MemberReferenceNode, ReferenceNode.MethodReferenceNode, ReferenceNode.PlainReferenceNode
ExpressionNode.BinaryExpressionNode, ExpressionNode.NotExpressionNode
Modifier and Type | Field and 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 |
lineNumber
Constructor and Description |
---|
MethodReferenceNode(ReferenceNode lhs,
java.lang.String id,
java.util.List<ExpressionNode> args) |
Modifier and Type | Method and 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)
|
invokeMethod, visibleMethod
intValue, isDefinedAndTrue, isTrue
cons, emptyNode, evaluationException, evaluationException
final ReferenceNode lhs
final java.lang.String id
final java.util.List<ExpressionNode> args
private static final com.google.common.collect.ImmutableList<java.lang.Class<?>> NUMERICAL_PRIMITIVES
private static final int INDEX_OF_INT
MethodReferenceNode(ReferenceNode lhs, java.lang.String id, java.util.List<ExpressionNode> args)
java.lang.Object evaluate(EvaluationContext context)
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.
.
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 Collections#singletonList
.
static boolean compatibleArgs(java.lang.Class<?>[] paramTypes, java.util.List<java.lang.Object> argValues)
Integer
argument being compatible with a parameter of type int
or
long
, for example.private static boolean primitiveIsCompatible(java.lang.Class<?> primitive, java.lang.Object value)
static boolean primitiveTypeIsAssignmentCompatible(java.lang.Class<?> to, java.lang.Class<?> from)