search super-interfaces as well (SPR-7355)

This commit is contained in:
Juergen Hoeller 2010-08-14 21:12:58 +00:00
parent 665a997f66
commit 49a2970def
2 changed files with 24 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -119,9 +119,9 @@ public abstract class AnnotationUtils {
private static <A extends Annotation> A searchOnInterfaces(Method method, Class<A> annotationType, Class[] ifcs) {
A annotation = null;
for (Class<?> iface : ifcs) {
Method equivalentMethod = null;
Method equivalentMethod;
try {
equivalentMethod = iface.getDeclaredMethod(method.getName(), method.getParameterTypes());
equivalentMethod = iface.getMethod(method.getName(), method.getParameterTypes());
annotation = getAnnotation(equivalentMethod, annotationType);
}
catch (NoSuchMethodException e) {
@ -338,7 +338,7 @@ public abstract class AnnotationUtils {
* Retrieve the <em>default value</em> of a named Annotation attribute, given an annotation instance.
* @param annotation the annotation instance from which to retrieve the default value
* @param attributeName the name of the attribute value to retrieve
* @return the default value of the named attribute, or <code>null</code> if not found.
* @return the default value of the named attribute, or <code>null</code> if not found
* @see #getDefaultValue(Class, String)
*/
public static Object getDefaultValue(Annotation annotation, String attributeName) {

View File

@ -432,7 +432,7 @@ public abstract class ReflectionUtils {
/**
* Perform the given callback operation on all matching methods of the given
* class and superclasses.
* class and superclasses (or given interface and super-interfaces).
* <p>The same named method occurring on subclass and superclass will appear
* twice, unless excluded by the specified {@link MethodFilter}.
* @param clazz class to start looking at
@ -443,9 +443,7 @@ public abstract class ReflectionUtils {
throws IllegalArgumentException {
// Keep backing up the inheritance hierarchy.
Class<?> targetClass = clazz;
do {
Method[] methods = targetClass.getDeclaredMethods();
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
if (mf != null && !mf.matches(method)) {
continue;
@ -458,9 +456,14 @@ public abstract class ReflectionUtils {
+ "': " + ex);
}
}
targetClass = targetClass.getSuperclass();
if (clazz.getSuperclass() != null) {
doWithMethods(clazz.getSuperclass(), mc, mf);
}
else if (clazz.isInterface()) {
for (Class<?> superIfc : clazz.getInterfaces()) {
doWithMethods(superIfc, mc, mf);
}
}
while (targetClass != null);
}
/**