1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
import org .springframework .lang .NonNull ;
29
29
import org .springframework .lang .Nullable ;
30
30
import org .springframework .util .Assert ;
31
- import org .springframework .util .ClassUtils ;
32
31
import org .springframework .util .ObjectUtils ;
33
32
import org .springframework .util .ReflectionUtils ;
34
33
import org .springframework .util .StringUtils ;
@@ -54,7 +53,7 @@ public class AnnotatedMethod {
54
53
private final MethodParameter [] parameters ;
55
54
56
55
@ Nullable
57
- private volatile List <Annotation [][]> interfaceParameterAnnotations ;
56
+ private volatile List <Annotation [][]> inheritedParameterAnnotations ;
58
57
59
58
60
59
/**
@@ -77,7 +76,7 @@ protected AnnotatedMethod(AnnotatedMethod annotatedMethod) {
77
76
this .method = annotatedMethod .method ;
78
77
this .bridgedMethod = annotatedMethod .bridgedMethod ;
79
78
this .parameters = annotatedMethod .parameters ;
80
- this .interfaceParameterAnnotations = annotatedMethod .interfaceParameterAnnotations ;
79
+ this .inheritedParameterAnnotations = annotatedMethod .inheritedParameterAnnotations ;
81
80
}
82
81
83
82
@@ -164,18 +163,32 @@ public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationTyp
164
163
return AnnotatedElementUtils .hasAnnotation (this .method , annotationType );
165
164
}
166
165
167
- private List <Annotation [][]> getInterfaceParameterAnnotations () {
168
- List <Annotation [][]> parameterAnnotations = this .interfaceParameterAnnotations ;
166
+ private List <Annotation [][]> getInheritedParameterAnnotations () {
167
+ List <Annotation [][]> parameterAnnotations = this .inheritedParameterAnnotations ;
169
168
if (parameterAnnotations == null ) {
170
169
parameterAnnotations = new ArrayList <>();
171
- for (Class <?> ifc : ClassUtils .getAllInterfacesForClassAsSet (this .method .getDeclaringClass ())) {
172
- for (Method candidate : ifc .getMethods ()) {
173
- if (isOverrideFor (candidate )) {
174
- parameterAnnotations .add (candidate .getParameterAnnotations ());
170
+ Class <?> clazz = this .method .getDeclaringClass ();
171
+ while (clazz != null ) {
172
+ for (Class <?> ifc : clazz .getInterfaces ()) {
173
+ for (Method candidate : ifc .getMethods ()) {
174
+ if (isOverrideFor (candidate )) {
175
+ parameterAnnotations .add (candidate .getParameterAnnotations ());
176
+ }
177
+ }
178
+ }
179
+ clazz = clazz .getSuperclass ();
180
+ if (clazz == Object .class ) {
181
+ clazz = null ;
182
+ }
183
+ if (clazz != null ) {
184
+ for (Method candidate : clazz .getMethods ()) {
185
+ if (isOverrideFor (candidate )) {
186
+ parameterAnnotations .add (candidate .getParameterAnnotations ());
187
+ }
175
188
}
176
189
}
177
190
}
178
- this .interfaceParameterAnnotations = parameterAnnotations ;
191
+ this .inheritedParameterAnnotations = parameterAnnotations ;
179
192
}
180
193
return parameterAnnotations ;
181
194
}
@@ -281,7 +294,7 @@ public Annotation[] getParameterAnnotations() {
281
294
anns = super .getParameterAnnotations ();
282
295
int index = getParameterIndex ();
283
296
if (index >= 0 ) {
284
- for (Annotation [][] ifcAnns : getInterfaceParameterAnnotations ()) {
297
+ for (Annotation [][] ifcAnns : getInheritedParameterAnnotations ()) {
285
298
if (index < ifcAnns .length ) {
286
299
Annotation [] paramAnns = ifcAnns [index ];
287
300
if (paramAnns .length > 0 ) {
0 commit comments