类 ReflectionHelper
java.lang.Object
cn.taketoday.expression.spel.support.ReflectionHelper
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
-
嵌套类概要
嵌套类修饰符和类型类说明(专用程序包) static classAn instance of ArgumentsMatchInfo describes what kind of match was achieved between two sets of arguments - the set that a method/constructor is expecting and the set that are being supplied at the point of invocation.(专用程序包) static enumArguments match kinds. -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明(专用程序包) static ReflectionHelper.ArgumentsMatchInfocompareArguments(List<TypeDescriptor> expectedArgTypes, List<TypeDescriptor> suppliedArgTypes, TypeConverter typeConverter) Compare argument arrays and return information about whether they match.(专用程序包) static ReflectionHelper.ArgumentsMatchInfocompareArgumentsVarargs(List<TypeDescriptor> expectedArgTypes, List<TypeDescriptor> suppliedArgTypes, TypeConverter typeConverter) Compare argument arrays and return information about whether they match.static booleanconvertAllArguments(TypeConverter converter, Object[] arguments, Method method) Convert a supplied set of arguments into the requested types.static booleanconvertAllMethodHandleArguments(TypeConverter converter, Object[] arguments, MethodHandle methodHandle, Integer varargsPosition) Takes an input set of argument values and converts them to the types specified as the required parameter types.(专用程序包) static booleanconvertArguments(TypeConverter converter, Object[] arguments, Executable executable, Integer varargsPosition) Takes an input set of argument values and converts them to the types specified as the required parameter types.static intgetTypeDifferenceWeight(List<TypeDescriptor> paramTypes, List<TypeDescriptor> argTypes) Based onReflectiveMethodInvoker.getTypeDifferenceWeight(Class[], Object[])but operates on TypeDescriptors.private static booleanisFirstEntryInArray(Object value, Object possibleArray) Check if the supplied value is the first entry in the array represented by the possibleArray value.static Object[]setupArgumentsForVarargsInvocation(Class<?>[] requiredParameterTypes, Object... args) Package up the arguments so that they correctly match what is expected in requiredParameterTypes.
-
构造器详细资料
-
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 expectingsuppliedArgTypes- the types that are being supplied at the point of invocationtypeConverter- a registered type converter- 返回:
- a MatchInfo object indicating what kind of match it was,
or
nullif it was not a match
-
getTypeDifferenceWeight
public static int getTypeDifferenceWeight(List<TypeDescriptor> paramTypes, List<TypeDescriptor> argTypes) Based onReflectiveMethodInvoker.getTypeDifferenceWeight(Class[], Object[])but operates on TypeDescriptors. -
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 expectingsuppliedArgTypes- the types that are being supplied at the point of invocationtypeConverter- a registered type converter- 返回:
- a MatchInfo object indicating what kind of match it was,
or
nullif 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 conversionsarguments- the arguments to convert to the requested parameter typesmethod- 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 conversionsarguments- the actual arguments that need conversionexecutable- the target Method or ConstructorvarargsPosition- the known position of the varargs argument, if any (nullif not varargs)- 返回:
trueif 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 conversionsarguments- the actual arguments that need conversionmethodHandle- the target MethodHandlevarargsPosition- the known position of the varargs argument, if any (nullif not varargs)- 返回:
trueif some kind of conversion occurred on an argument- 抛出:
EvaluationException- if a problem occurs during conversion
-
isFirstEntryInArray
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 arraypossibleArray- 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 declaredString..., 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 invocationargs- the arguments to be setup ready for the invocation- 返回:
- a repackaged array of arguments where any varargs setup has been done
-