spring-framework / org.springframework.expression.spel.support / ReflectionHelper

ReflectionHelper

open class ReflectionHelper

Utility methods used by the reflection resolver code to discover the appropriate methods/constructors and fields that should be used in expressions.

Author
Andy Clement

Author
Juergen Hoeller

Since
3.0

Constructors

<init>

ReflectionHelper()

Utility methods used by the reflection resolver code to discover the appropriate methods/constructors and fields that should be used in expressions.

Functions

convertAllArguments

open static fun convertAllArguments(converter: TypeConverter, arguments: Array<Any>, method: Method): Boolean

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.

getTypeDifferenceWeight

open static fun getTypeDifferenceWeight(paramTypes: MutableList<TypeDescriptor>, argTypes: MutableList<TypeDescriptor>): Int

Based on MethodInvoker#getTypeDifferenceWeight(Class[], Object[]) but operates on TypeDescriptors.

setupArgumentsForVarargsInvocation

open static fun setupArgumentsForVarargsInvocation(requiredParameterTypes: Array<Class<*>>, vararg args: Any): Array<Any>

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 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.