Polish ReflectiveMethodResolver and unit tests

- Update Javadoc
 - Fix whitespace errors (tabs v. spaces, trailing spaces)
 - Break at 90 chars where sensible
 - Remove dead test code
 - Fix generics warnings, remove @SuppressWarnings
This commit is contained in:
Chris Beams
2012-02-01 17:19:42 +01:00
parent 8980ce712d
commit c7fd03be69
2 changed files with 275 additions and 327 deletions

View File

@@ -38,27 +38,30 @@ import org.springframework.expression.spel.SpelMessage;
import org.springframework.util.CollectionUtils;
/**
* A method resolver that uses reflection to locate the method that should be invoked.
* Reflection-based {@link MethodResolver} used by default in
* {@link StandardEvaluationContext} unless explicit method resolvers have been specified.
*
* @author Andy Clement
* @author Juergen Hoeller
* @author Chris Beams
* @since 3.0
* @see StandardEvaluationContext#addMethodResolver(MethodResolver)
*/
public class ReflectiveMethodResolver implements MethodResolver {
private static Method[] NO_METHODS = new Method[0];
private Map<Class<?>, MethodFilter> filters = null;
// Using distance will ensure a more accurate match is discovered,
// more closely following the Java rules.
private boolean useDistance = false;
public ReflectiveMethodResolver() {
}
/**
* This constructors allows the ReflectiveMethodResolver to be configured such that it will
* use a distance computation to check which is the better of two close matches (when there
@@ -71,7 +74,7 @@ public class ReflectiveMethodResolver implements MethodResolver {
public ReflectiveMethodResolver(boolean useDistance) {
this.useDistance = useDistance;
}
/**
* Locate a method on a type. There are three kinds of match that might occur:
* <ol>
@@ -88,14 +91,14 @@ public class ReflectiveMethodResolver implements MethodResolver {
TypeConverter typeConverter = context.getTypeConverter();
Class<?> type = (targetObject instanceof Class ? (Class<?>) targetObject : targetObject.getClass());
Method[] methods = type.getMethods();
// If a filter is registered for this type, call it
MethodFilter filter = (this.filters != null ? this.filters.get(type) : null);
if (filter != null) {
List<Method> methodsForFiltering = new ArrayList<Method>();
for (Method method: methods) {
methodsForFiltering.add(method);
}
List<Method> methodsForFiltering = new ArrayList<Method>();
for (Method method: methods) {
methodsForFiltering.add(method);
}
List<Method> methodsFiltered = filter.filter(methodsForFiltering);
if (CollectionUtils.isEmpty(methodsFiltered)) {
methods = NO_METHODS;
@@ -124,7 +127,7 @@ public class ReflectiveMethodResolver implements MethodResolver {
continue;
}
if (method.getName().equals(name)) {
Class[] paramTypes = method.getParameterTypes();
Class<?>[] paramTypes = method.getParameterTypes();
List<TypeDescriptor> paramDescriptors = new ArrayList<TypeDescriptor>(paramTypes.length);
for (int i = 0; i < paramTypes.length; i++) {
paramDescriptors.add(new TypeDescriptor(new MethodParameter(method, i)));