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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { private static <A extends Annotation> A searchOnInterfaces(Method method, Class<A> annotationType, Class[] ifcs) {
A annotation = null; A annotation = null;
for (Class<?> iface : ifcs) { for (Class<?> iface : ifcs) {
Method equivalentMethod = null; Method equivalentMethod;
try { try {
equivalentMethod = iface.getDeclaredMethod(method.getName(), method.getParameterTypes()); equivalentMethod = iface.getMethod(method.getName(), method.getParameterTypes());
annotation = getAnnotation(equivalentMethod, annotationType); annotation = getAnnotation(equivalentMethod, annotationType);
} }
catch (NoSuchMethodException e) { 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. * 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 annotation the annotation instance from which to retrieve the default value
* @param attributeName the name of the attribute value to retrieve * @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) * @see #getDefaultValue(Class, String)
*/ */
public static Object getDefaultValue(Annotation annotation, String attributeName) { 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 * 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 * <p>The same named method occurring on subclass and superclass will appear
* twice, unless excluded by the specified {@link MethodFilter}. * twice, unless excluded by the specified {@link MethodFilter}.
* @param clazz class to start looking at * @param clazz class to start looking at
@ -443,24 +443,27 @@ public abstract class ReflectionUtils {
throws IllegalArgumentException { throws IllegalArgumentException {
// Keep backing up the inheritance hierarchy. // Keep backing up the inheritance hierarchy.
Class<?> targetClass = clazz; Method[] methods = clazz.getDeclaredMethods();
do { for (Method method : methods) {
Method[] methods = targetClass.getDeclaredMethods(); if (mf != null && !mf.matches(method)) {
for (Method method : methods) { continue;
if (mf != null && !mf.matches(method)) { }
continue; try {
} mc.doWith(method);
try { }
mc.doWith(method); catch (IllegalAccessException ex) {
} throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName()
catch (IllegalAccessException ex) { + "': " + ex);
throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName() }
+ "': " + ex); }
} if (clazz.getSuperclass() != null) {
doWithMethods(clazz.getSuperclass(), mc, mf);
}
else if (clazz.isInterface()) {
for (Class<?> superIfc : clazz.getInterfaces()) {
doWithMethods(superIfc, mc, mf);
} }
targetClass = targetClass.getSuperclass();
} }
while (targetClass != null);
} }
/** /**