Class ReferenceNode.MethodReferenceNode

  • Enclosing class:
    ReferenceNode

    static class ReferenceNode.MethodReferenceNode
    extends ReferenceNode
    A node in the parse tree representing a method reference, like $list.size().
    • Field Detail

      • id

        final java.lang.String id
      • 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
    • 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 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..

        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(T).

        Specified by:
        evaluate in class Node
      • 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 an Integer argument being compatible with a parameter of type int or long, 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)
        Returns true if from can be assigned to to according to Widening Primitive Conversion.