类 ReflectionHelper
- java.lang.Object
- org.springframework.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.- 从以下版本开始:
- 3.0
- 作者:
- Andy Clement, Juergen Hoeller
构造器概要
构造器 构造器 说明 ReflectionHelper()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static boolean
convertAllArguments(TypeConverter converter, Object[] arguments, Method method)
Convert a supplied set of arguments into the requested types.static int
getTypeDifferenceWeight(List<TypeDescriptor> paramTypes, List<TypeDescriptor> argTypes)
Based onMethodInvoker.getTypeDifferenceWeight(Class[], Object[])
but operates on TypeDescriptors.static Object[]
setupArgumentsForVarargsInvocation(Class<?>[] requiredParameterTypes, Object... args)
Package up the arguments so that they correctly match what is expected in parameterTypes.
构造器详细资料
ReflectionHelper
public ReflectionHelper()
方法详细资料
getTypeDifferenceWeight
public static int getTypeDifferenceWeight(List<TypeDescriptor> paramTypes, List<TypeDescriptor> argTypes)
Based onMethodInvoker.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 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
setupArgumentsForVarargsInvocation
public static Object[] setupArgumentsForVarargsInvocation(Class<?>[] requiredParameterTypes, Object... args)
Package up the arguments so that they correctly match what is expected in parameterTypes. For example, if parameterTypes 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