Consistent resolution of Class methods and static methods
Issue: SPR-12502
This commit is contained in:
@@ -17,12 +17,13 @@
|
||||
package org.springframework.expression.spel.support;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -107,7 +108,7 @@ public class ReflectiveMethodResolver implements MethodResolver {
|
||||
try {
|
||||
TypeConverter typeConverter = context.getTypeConverter();
|
||||
Class<?> type = (targetObject instanceof Class ? (Class<?>) targetObject : targetObject.getClass());
|
||||
List<Method> methods = new ArrayList<Method>(Arrays.asList(getMethods(type, targetObject)));
|
||||
List<Method> methods = new ArrayList<Method>((getMethods(type, targetObject)));
|
||||
|
||||
// If a filter is registered for this type, call it
|
||||
MethodFilter filter = (this.filters != null ? this.filters.get(type) : null);
|
||||
@@ -216,14 +217,22 @@ public class ReflectiveMethodResolver implements MethodResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private Method[] getMethods(Class<?> type, Object targetObject) {
|
||||
private Collection<Method> getMethods(Class<?> type, Object targetObject) {
|
||||
if (targetObject instanceof Class) {
|
||||
Set<Method> methods = new HashSet<Method>();
|
||||
methods.addAll(Arrays.asList(getMethods(type)));
|
||||
methods.addAll(Arrays.asList(getMethods(targetObject.getClass())));
|
||||
return methods.toArray(new Method[methods.size()]);
|
||||
Set<Method> result = new LinkedHashSet<Method>();
|
||||
result.addAll(Arrays.asList(getMethods(targetObject.getClass())));
|
||||
// Add these also so that static result are invocable on the type: e.g. Float.valueOf(..)
|
||||
Method[] methods = getMethods(type);
|
||||
for (Method method : methods) {
|
||||
if (Modifier.isStatic(method.getModifiers())) {
|
||||
result.add(method);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return Arrays.asList(getMethods(type));
|
||||
}
|
||||
return getMethods(type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user