类 ReflectionHelper

java.lang.Object
cn.taketoday.expression.spel.support.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.
从以下版本开始:
4.0
作者:
Andy Clement, Juergen Hoeller, Sam Brannen, Harry Yang
  • 字段详细资料

    • publicDeclaringClassCache

      private static final ConcurrentReferenceHashMap<Method,Class<?>> publicDeclaringClassCache
      Cache for equivalent methods in a public declaring class in the type hierarchy of the method's declaring class.
  • 构造器详细资料

    • ReflectionHelper

      public ReflectionHelper()
  • 方法详细资料

    • compareArguments

      @Nullable static ReflectionHelper.ArgumentsMatchInfo compareArguments(List<TypeDescriptor> expectedArgTypes, List<TypeDescriptor> suppliedArgTypes, TypeConverter typeConverter)
      Compare argument arrays and return information about whether they match. A supplied type converter and conversionAllowed flag allow for matches to take into account that a type may be transformed into a different type by the converter.
      参数:
      expectedArgTypes - the types the method/constructor is expecting
      suppliedArgTypes - the types that are being supplied at the point of invocation
      typeConverter - a registered type converter
      返回:
      a MatchInfo object indicating what kind of match it was, or null if it was not a match
    • getTypeDifferenceWeight

      public static int getTypeDifferenceWeight(List<TypeDescriptor> paramTypes, List<TypeDescriptor> argTypes)
    • compareArgumentsVarargs

      @Nullable static ReflectionHelper.ArgumentsMatchInfo compareArgumentsVarargs(List<TypeDescriptor> expectedArgTypes, List<TypeDescriptor> suppliedArgTypes, TypeConverter typeConverter)
      Compare argument arrays and return information about whether they match. A supplied type converter and conversionAllowed flag allow for matches to take into account that a type may be transformed into a different type by the converter. This variant of compareArguments also allows for a varargs match.
      参数:
      expectedArgTypes - the types the method/constructor is expecting
      suppliedArgTypes - the types that are being supplied at the point of invocation
      typeConverter - a registered type converter
      返回:
      a MatchInfo object indicating what kind of match it was, or null if it was not a match
    • 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
    • convertArguments

      static boolean convertArguments(TypeConverter converter, Object[] arguments, Executable executable, @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
      executable - the target Method or Constructor
      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
    • 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
    • isFirstEntryInArray

      private static boolean isFirstEntryInArray(Object value, @Nullable Object possibleArray)
      Check if the supplied value is the first entry in the array represented by the possibleArray value.
      参数:
      value - the value to check for in the array
      possibleArray - an array object that may have the supplied value as the first element
      返回:
      true if the supplied value is the first entry in the array
    • 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
    • findPublicDeclaringClass

      @Nullable public static Class<?> findPublicDeclaringClass(Method method)
      Find the first public class or interface in the method's class hierarchy that declares the supplied method.

      Sometimes the reflective method discovery logic finds a suitable method that can easily be called via reflection but cannot be called from generated code when compiling the expression because of visibility restrictions. For example, if a non-public class overrides toString(), this method will traverse up the type hierarchy to find the first public type that declares the method (if there is one). For toString(), it may traverse as far as Object.

      参数:
      method - the method to process
      返回:
      the public class or interface that declares the method, or null if no such public type could be found
    • findPublicDeclaringClass

      @Nullable private static Class<?> findPublicDeclaringClass(Class<?> declaringClass, String methodName, Class<?>[] parameterTypes)