|
|
|
@ -38,7 +38,7 @@ import org.springframework.util.MethodInvoker; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Utility methods used by the reflection resolver code to discover the appropriate |
|
|
|
* Utility methods used by the reflection resolver code to discover the appropriate |
|
|
|
* methods/constructors and fields that should be used in expressions. |
|
|
|
* methods, constructors, and fields that should be used in expressions. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Andy Clement |
|
|
|
* @author Andy Clement |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
@ -49,7 +49,7 @@ public abstract class ReflectionHelper { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Compare argument arrays and return information about whether they match. |
|
|
|
* Compare argument arrays and return information about whether they match. |
|
|
|
* A supplied type converter and conversionAllowed flag allow for matches to take |
|
|
|
* <p>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. |
|
|
|
* into account that a type may be transformed into a different type by the converter. |
|
|
|
* @param expectedArgTypes the types the method/constructor is expecting |
|
|
|
* @param expectedArgTypes the types the method/constructor is expecting |
|
|
|
* @param suppliedArgTypes the types that are being supplied at the point of invocation |
|
|
|
* @param suppliedArgTypes the types that are being supplied at the point of invocation |
|
|
|
@ -68,7 +68,7 @@ public abstract class ReflectionHelper { |
|
|
|
for (int i = 0; i < expectedArgTypes.size() && match != null; i++) { |
|
|
|
for (int i = 0; i < expectedArgTypes.size() && match != null; i++) { |
|
|
|
TypeDescriptor suppliedArg = suppliedArgTypes.get(i); |
|
|
|
TypeDescriptor suppliedArg = suppliedArgTypes.get(i); |
|
|
|
TypeDescriptor expectedArg = expectedArgTypes.get(i); |
|
|
|
TypeDescriptor expectedArg = expectedArgTypes.get(i); |
|
|
|
// The user may supply null - and that will be ok unless a primitive is expected
|
|
|
|
// The user may supply null, and that will be OK unless a primitive is expected.
|
|
|
|
if (suppliedArg == null) { |
|
|
|
if (suppliedArg == null) { |
|
|
|
if (expectedArg.isPrimitive()) { |
|
|
|
if (expectedArg.isPrimitive()) { |
|
|
|
match = null; |
|
|
|
match = null; |
|
|
|
@ -136,9 +136,9 @@ public abstract class ReflectionHelper { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Compare argument arrays and return information about whether they match. |
|
|
|
* Compare argument arrays and return information about whether they match. |
|
|
|
* A supplied type converter and conversionAllowed flag allow for matches to |
|
|
|
* <p>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 |
|
|
|
* 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. |
|
|
|
* converter. This variant of {@link #compareArguments} also allows for a varargs match. |
|
|
|
* @param expectedArgTypes the types the method/constructor is expecting |
|
|
|
* @param expectedArgTypes the types the method/constructor is expecting |
|
|
|
* @param suppliedArgTypes the types that are being supplied at the point of invocation |
|
|
|
* @param suppliedArgTypes the types that are being supplied at the point of invocation |
|
|
|
* @param typeConverter a registered type converter |
|
|
|
* @param typeConverter a registered type converter |
|
|
|
@ -233,19 +233,26 @@ public abstract class ReflectionHelper { |
|
|
|
return (match != null ? new ArgumentsMatchInfo(match) : null); |
|
|
|
return (match != null ? new ArgumentsMatchInfo(match) : null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO could do with more refactoring around argument handling and varargs
|
|
|
|
// TODO could do with more refactoring around argument handling and varargs
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Convert a supplied set of arguments into the requested types. If the parameterTypes are related to |
|
|
|
* Convert the supplied set of arguments into the parameter types specified |
|
|
|
* a varargs method then the final entry in the parameterTypes array is going to be an array itself whose |
|
|
|
* by the supplied {@link Method}. |
|
|
|
* component type should be used as the conversion target for extraneous arguments. (For example, if the |
|
|
|
* <p>The arguments are converted 'in-place' in the input array. |
|
|
|
* parameterTypes are {Integer, String[]} and the input arguments are {Integer, boolean, float} then both |
|
|
|
* <p>If the method accepts varargs, the final entry in its parameterTypes |
|
|
|
* the boolean and float must be converted to strings). This method does *not* repackage the arguments |
|
|
|
* array is going to be an array itself whose component type will be used as |
|
|
|
* into a form suitable for the varargs invocation - a subsequent call to setupArgumentsForVarargsInvocation handles that. |
|
|
|
* the conversion target for any additional 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. |
|
|
|
|
|
|
|
* <p>This method does <strong>not</strong> repackage the arguments into a |
|
|
|
|
|
|
|
* form suitable for the varargs invocation. A subsequent call to |
|
|
|
|
|
|
|
* {@link #setupArgumentsForVarargsInvocation(Class[], Object...)} must be |
|
|
|
|
|
|
|
* used for that. |
|
|
|
* @param converter the converter to use for type conversions |
|
|
|
* @param converter the converter to use for type conversions |
|
|
|
* @param arguments the arguments to convert to the requested parameter types |
|
|
|
* @param arguments the arguments to convert to the parameter types of the |
|
|
|
* @param method the target Method |
|
|
|
* target method |
|
|
|
* @return true if some kind of conversion occurred on the argument |
|
|
|
* @param method the target method |
|
|
|
|
|
|
|
* @return true if some kind of conversion occurred on an argument |
|
|
|
* @throws SpelEvaluationException if there is a problem with conversion |
|
|
|
* @throws SpelEvaluationException if there is a problem with conversion |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static boolean convertAllArguments(TypeConverter converter, Object[] arguments, Method method) |
|
|
|
public static boolean convertAllArguments(TypeConverter converter, Object[] arguments, Method method) |
|
|
|
@ -256,8 +263,9 @@ public abstract class ReflectionHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Takes an input set of argument values and converts them to the types specified as the |
|
|
|
* Takes an input set of argument values and converts them to the parameter |
|
|
|
* required parameter types. The arguments are converted 'in-place' in the input array. |
|
|
|
* types of the supplied {@link Executable} (i.e., constructor or method). |
|
|
|
|
|
|
|
* <p>The arguments are converted 'in-place' in the input array. |
|
|
|
* @param converter the type converter to use for attempting conversions |
|
|
|
* @param converter the type converter to use for attempting conversions |
|
|
|
* @param arguments the actual arguments that need conversion |
|
|
|
* @param arguments the actual arguments that need conversion |
|
|
|
* @param executable the target Method or Constructor |
|
|
|
* @param executable the target Method or Constructor |
|
|
|
@ -334,8 +342,9 @@ public abstract class ReflectionHelper { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Takes an input set of argument values and converts them to the types specified as the |
|
|
|
* Takes an input set of argument values and converts them to the parameter |
|
|
|
* required parameter types. The arguments are converted 'in-place' in the input array. |
|
|
|
* types of the supplied {@link MethodHandle}. |
|
|
|
|
|
|
|
* <p>The arguments are converted 'in-place' in the input array. |
|
|
|
* @param converter the type converter to use for attempting conversions |
|
|
|
* @param converter the type converter to use for attempting conversions |
|
|
|
* @param arguments the actual arguments that need conversion |
|
|
|
* @param arguments the actual arguments that need conversion |
|
|
|
* @param methodHandle the target MethodHandle |
|
|
|
* @param methodHandle the target MethodHandle |
|
|
|
|