Class MethodMap

java.lang.Object
org.apache.velocity.util.introspection.MethodMap

public class MethodMap extends Object
Version:
$Id$
  • Field Details

  • Constructor Details

    • MethodMap

      public MethodMap()
      Default constructor
    • MethodMap

      public MethodMap(TypeConversionHandler conversionHandler)
      Constructor with provided conversion handler
      Parameters:
      conversionHandler - conversion handler
      Since:
      2.0
  • Method Details

    • add

      public void add(Method method)
      Add a method to a list of methods by name. For a particular class we are keeping track of all the methods with the same name.
      Parameters:
      method -
    • get

      public List<Method> get(String key)
      Return a list of methods with the same name.
      Parameters:
      key -
      Returns:
      List list of methods
    • find

      public Method find(String methodName, Object[] args) throws MethodMap.AmbiguousException

      Find a method. Attempts to find the most specific applicable method using the algorithm described in the JLS section 15.12.2 (with the exception that it can't distinguish a primitive type argument from an object type argument, since in reflection primitive type arguments are represented by their object counterparts, so for an argument of type (say) java.lang.Integer, it will not be able to decide between a method that takes int and a method that takes java.lang.Integer as a parameter.

      This turns out to be a relatively rare case where this is needed - however, functionality like this is needed.

      Parameters:
      methodName - name of method
      args - the actual arguments with which the method is called
      Returns:
      the most specific applicable method, or null if no method is applicable.
      Throws:
      MethodMap.AmbiguousException - if there is more than one maximally specific applicable method
    • onlyNullOrObjects

      private static boolean onlyNullOrObjects(Class<?>[] args)
    • getBestMatch

      private Method getBestMatch(List<Method> methods, Class<?>[] args)
    • compare

      private int compare(Type[] t1, Type[] t2)
      Determines which method signature (represented by a class array) is more specific. This defines a partial ordering on the method signatures.
      Parameters:
      t1 - first signature to compare
      t2 - second signature to compare
      Returns:
      MORE_SPECIFIC if c1 is more specific than c2, LESS_SPECIFIC if c1 is less specific than c2, INCOMPARABLE if they are incomparable.
    • getApplicability

      private int getApplicability(Method method, Class<?>[] classes)
      Returns the applicability of the supplied method against actual argument types.
      Parameters:
      method - method that will be called
      classes - arguments to method
      Returns:
      the level of applicability: 0 = not applicable 1 = explicitly applicable (i.e. using stock or custom conversion handlers) 2 = implicitly applicable (i.e. using JAva implicit boxing/unboxing and primitive types widening) 3 = strictly applicable
    • isConvertible

      private boolean isConvertible(Type formal, Class<?> actual, boolean possibleVarArg)
      Returns true if actual is convertible to formal by implicit Java method call conversions
      Parameters:
      formal -
      actual -
      possibleVarArg -
      Returns:
      convertible
    • isStrictConvertible

      private static boolean isStrictConvertible(Type formal, Class<?> actual, boolean possibleVarArg)
      Returns true if actual is strictly convertible to formal (aka without implicit boxing/unboxing)
      Parameters:
      formal -
      actual -
      possibleVarArg -
      Returns:
      convertible
    • isExplicitlyConvertible

      private boolean isExplicitlyConvertible(Type formal, Class<?> actual, boolean possibleVarArg)
      Returns true if actual is convertible to formal using an explicit converter
      Parameters:
      formal -
      actual -
      possibleVarArg -
      Returns: