Skip to content

Commit

Permalink
Polish SpEL function invocation support
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jul 10, 2024
1 parent f2b3263 commit dc16f3c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ else if (spelParamCount != declaredParamCount) {
}
}

// more complex case, we need to look at conversion and vararg repacking
// more complex case, we need to look at conversion and varargs repackaging
Integer varArgPosition = null;
if (isSuspectedVarargs) {
varArgPosition = declaredParamCount - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,10 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O
MethodHandle methodHandle, @Nullable Integer varargsPosition) throws EvaluationException {

boolean conversionOccurred = false;
MethodType methodHandleArgumentTypes = methodHandle.type();
MethodType methodHandleType = methodHandle.type();
if (varargsPosition == null) {
for (int i = 0; i < arguments.length; i++) {
Class<?> argumentClass = methodHandleArgumentTypes.parameterType(i);
Class<?> argumentClass = methodHandleType.parameterType(i);
ResolvableType resolvableType = ResolvableType.forClass(argumentClass);
TypeDescriptor targetType = new TypeDescriptor(resolvableType, argumentClass, null);

Expand All @@ -371,7 +371,7 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O
else {
// Convert everything up to the varargs position
for (int i = 0; i < varargsPosition; i++) {
Class<?> argumentClass = methodHandleArgumentTypes.parameterType(i);
Class<?> argumentClass = methodHandleType.parameterType(i);
ResolvableType resolvableType = ResolvableType.forClass(argumentClass);
TypeDescriptor targetType = new TypeDescriptor(resolvableType, argumentClass, null);

Expand All @@ -380,10 +380,10 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O
conversionOccurred |= (argument != arguments[i]);
}

Class<?> varArgClass = methodHandleArgumentTypes.lastParameterType().componentType();
Class<?> varArgClass = methodHandleType.lastParameterType().componentType();
ResolvableType varArgResolvableType = ResolvableType.forClass(varArgClass);
TypeDescriptor varArgComponentType = new TypeDescriptor(varArgResolvableType, varArgClass, null);
TypeDescriptor componentTypeDesc = varArgComponentType.getElementTypeDescriptor();
TypeDescriptor targetType = new TypeDescriptor(varArgResolvableType, varArgClass, null);
TypeDescriptor componentTypeDesc = targetType.getElementTypeDescriptor();
// TODO Determine why componentTypeDesc can be null.
// Assert.state(componentTypeDesc != null, "Component type must not be null for a varargs array");

Expand All @@ -403,7 +403,7 @@ public static boolean convertAllMethodHandleArguments(TypeConverter converter, O
// convert a String containing a comma would result in the String being split and
// repackaged in an array when it should be used as-is.
else if (componentTypeDesc != null && !sourceType.isAssignableTo(componentTypeDesc)) {
arguments[varargsPosition] = converter.convertValue(argument, sourceType, varArgComponentType);
arguments[varargsPosition] = converter.convertValue(argument, sourceType, targetType);
}
// Possible outcomes of the above if-else block:
// 1) the input argument was null, and nothing was done.
Expand All @@ -420,7 +420,7 @@ else if (componentTypeDesc != null && !sourceType.isAssignableTo(componentTypeDe
else {
for (int i = varargsPosition; i < arguments.length; i++) {
Object argument = arguments[i];
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), varArgComponentType);
arguments[i] = converter.convertValue(argument, TypeDescriptor.forObject(argument), targetType);
conversionOccurred |= (argument != arguments[i]);
}
}
Expand Down

0 comments on commit dc16f3c

Please sign in to comment.