Class ReflectionHelper


public abstract class ReflectionHelper extends Object
Utility methods used by the reflection resolver code to discover the appropriate methods/constructors and fields that should be used in expressions.
Andy Clement, Juergen Hoeller, Sam Brannen
  • Constructor Details

    • ReflectionHelper

      public ReflectionHelper()
  • Method Details

    • getTypeDifferenceWeight

      public static int getTypeDifferenceWeight(List<TypeDescriptor> paramTypes, List<TypeDescriptor> argTypes)
      Based on MethodInvoker.getTypeDifferenceWeight(Class[], Object[]) but operates on TypeDescriptors.
    • convertAllArguments

      public static boolean convertAllArguments(TypeConverter converter, Object[] arguments, Method method) throws SpelEvaluationException
      Convert a supplied set of arguments into the requested types. If the parameterTypes are related to a varargs method then the final entry in the parameterTypes array is going to be an array itself whose component type should be used as the conversion target for extraneous arguments. (For example, if the parameterTypes are {Integer, String[]} and the input arguments are {Integer, boolean, float} then both the boolean and float must be converted to strings). This method does *not* repackage the arguments into a form suitable for the varargs invocation - a subsequent call to setupArgumentsForVarargsInvocation handles that.
      converter - the converter to use for type conversions
      arguments - the arguments to convert to the requested parameter types
      method - the target Method
      true if some kind of conversion occurred on the argument
      SpelEvaluationException - if there is a problem with conversion
    • convertAllMethodHandleArguments

      public static boolean convertAllMethodHandleArguments(TypeConverter converter, Object[] arguments, MethodHandle methodHandle, @Nullable Integer varargsPosition) throws EvaluationException
      Takes an input set of argument values and converts them to the types specified as the required parameter types. The arguments are converted 'in-place' in the input array.
      converter - the type converter to use for attempting conversions
      arguments - the actual arguments that need conversion
      methodHandle - the target MethodHandle
      varargsPosition - the known position of the varargs argument, if any (null if not varargs)
      true if some kind of conversion occurred on an argument
      EvaluationException - if a problem occurs during conversion
    • setupArgumentsForVarargsInvocation

      public static Object[] setupArgumentsForVarargsInvocation(Class<?>[] requiredParameterTypes, Object... args)
      Package up the arguments so that they correctly match what is expected in requiredParameterTypes.

      For example, if requiredParameterTypes is (int, String[]) because the second parameter was declared String..., then if arguments is [1,"a","b"] then it must be repackaged as [1,new String[]{"a","b"}] in order to match the expected types.

      requiredParameterTypes - the types of the parameters for the invocation
      args - the arguments to be setup ready for the invocation
      a repackaged array of arguments where any varargs setup has been done