From 49a2970def8ed6b9e991095b6db29b1e8112cab1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 14 Aug 2010 21:12:58 +0000 Subject: [PATCH] search super-interfaces as well (SPR-7355) --- .../core/annotation/AnnotationUtils.java | 8 ++-- .../springframework/util/ReflectionUtils.java | 37 ++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index dc862823761..ebbcd83fd23 100644 --- a/org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -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 searchOnInterfaces(Method method, Class 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 default value 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 null if not found. + * @return the default value of the named attribute, or null if not found * @see #getDefaultValue(Class, String) */ public static Object getDefaultValue(Annotation annotation, String attributeName) { diff --git a/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java b/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java index c47c02b51b1..0c6e97cb09a 100644 --- a/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/org.springframework.core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -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). *

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,24 +443,27 @@ public abstract class ReflectionUtils { throws IllegalArgumentException { // Keep backing up the inheritance hierarchy. - Class targetClass = clazz; - do { - Method[] methods = targetClass.getDeclaredMethods(); - for (Method method : methods) { - if (mf != null && !mf.matches(method)) { - continue; - } - try { - mc.doWith(method); - } - catch (IllegalAccessException ex) { - throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName() - + "': " + ex); - } + Method[] methods = clazz.getDeclaredMethods(); + for (Method method : methods) { + if (mf != null && !mf.matches(method)) { + continue; + } + try { + mc.doWith(method); + } + catch (IllegalAccessException 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); } /**