Skip to content

Commit 49a2970

Browse files
committed
search super-interfaces as well (SPR-7355)
1 parent 665a997 commit 49a2970

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -119,9 +119,9 @@ public static <A extends Annotation> A findAnnotation(Method method, Class<A> an
119119
private static <A extends Annotation> A searchOnInterfaces(Method method, Class<A> annotationType, Class[] ifcs) {
120120
A annotation = null;
121121
for (Class<?> iface : ifcs) {
122-
Method equivalentMethod = null;
122+
Method equivalentMethod;
123123
try {
124-
equivalentMethod = iface.getDeclaredMethod(method.getName(), method.getParameterTypes());
124+
equivalentMethod = iface.getMethod(method.getName(), method.getParameterTypes());
125125
annotation = getAnnotation(equivalentMethod, annotationType);
126126
}
127127
catch (NoSuchMethodException e) {
@@ -338,7 +338,7 @@ public static Object getDefaultValue(Annotation annotation) {
338338
* Retrieve the <em>default value</em> of a named Annotation attribute, given an annotation instance.
339339
* @param annotation the annotation instance from which to retrieve the default value
340340
* @param attributeName the name of the attribute value to retrieve
341-
* @return the default value of the named attribute, or <code>null</code> if not found.
341+
* @return the default value of the named attribute, or <code>null</code> if not found
342342
* @see #getDefaultValue(Class, String)
343343
*/
344344
public static Object getDefaultValue(Annotation annotation, String attributeName) {

org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public static void doWithMethods(Class<?> clazz, MethodCallback mc) throws Illeg
432432

433433
/**
434434
* Perform the given callback operation on all matching methods of the given
435-
* class and superclasses.
435+
* class and superclasses (or given interface and super-interfaces).
436436
* <p>The same named method occurring on subclass and superclass will appear
437437
* twice, unless excluded by the specified {@link MethodFilter}.
438438
* @param clazz class to start looking at
@@ -443,24 +443,27 @@ public static void doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter
443443
throws IllegalArgumentException {
444444

445445
// Keep backing up the inheritance hierarchy.
446-
Class<?> targetClass = clazz;
447-
do {
448-
Method[] methods = targetClass.getDeclaredMethods();
449-
for (Method method : methods) {
450-
if (mf != null && !mf.matches(method)) {
451-
continue;
452-
}
453-
try {
454-
mc.doWith(method);
455-
}
456-
catch (IllegalAccessException ex) {
457-
throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName()
458-
+ "': " + ex);
459-
}
446+
Method[] methods = clazz.getDeclaredMethods();
447+
for (Method method : methods) {
448+
if (mf != null && !mf.matches(method)) {
449+
continue;
450+
}
451+
try {
452+
mc.doWith(method);
453+
}
454+
catch (IllegalAccessException ex) {
455+
throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName()
456+
+ "': " + ex);
457+
}
458+
}
459+
if (clazz.getSuperclass() != null) {
460+
doWithMethods(clazz.getSuperclass(), mc, mf);
461+
}
462+
else if (clazz.isInterface()) {
463+
for (Class<?> superIfc : clazz.getInterfaces()) {
464+
doWithMethods(superIfc, mc, mf);
460465
}
461-
targetClass = targetClass.getSuperclass();
462466
}
463-
while (targetClass != null);
464467
}
465468

466469
/**

0 commit comments

Comments
 (0)