@@ -386,13 +386,14 @@ public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElemen
386
386
@ Nullable
387
387
public static <A extends Annotation > A getMergedAnnotation (AnnotatedElement element , Class <A > annotationType ) {
388
388
// Shortcut: directly present on the element, with no merging needed?
389
- if (!(element instanceof Class )) {
390
- // Do not use this shortcut against a Class: Inherited annotations
391
- // would get preferred over locally declared composed annotations.
392
- A annotation = element .getAnnotation (annotationType );
393
- if (annotation != null ) {
394
- return AnnotationUtils .synthesizeAnnotation (annotation , element );
395
- }
389
+ A annotation = element .getDeclaredAnnotation (annotationType );
390
+ if (annotation != null ) {
391
+ return AnnotationUtils .synthesizeAnnotation (annotation , element );
392
+ }
393
+
394
+ // Shortcut: no non-java annotations to be found on plain Java classes and org.springframework.lang types...
395
+ if (AnnotationUtils .hasPlainJavaAnnotationsOnly (element ) && !annotationType .getName ().startsWith ("java" )) {
396
+ return null ;
396
397
}
397
398
398
399
// Exhaustive retrieval of merged annotation attributes...
@@ -671,13 +672,9 @@ public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedEleme
671
672
@ Nullable
672
673
public static <A extends Annotation > A findMergedAnnotation (AnnotatedElement element , Class <A > annotationType ) {
673
674
// Shortcut: directly present on the element, with no merging needed?
674
- if (!(element instanceof Class )) {
675
- // Do not use this shortcut against a Class: Inherited annotations
676
- // would get preferred over locally declared composed annotations.
677
- A annotation = element .getAnnotation (annotationType );
678
- if (annotation != null ) {
679
- return AnnotationUtils .synthesizeAnnotation (annotation , element );
680
- }
675
+ A annotation = element .getDeclaredAnnotation (annotationType );
676
+ if (annotation != null ) {
677
+ return AnnotationUtils .synthesizeAnnotation (annotation , element );
681
678
}
682
679
683
680
// Shortcut: no non-java annotations to be found on plain Java classes and org.springframework.lang types...
@@ -1145,8 +1142,7 @@ else if (currentAnnotationType == containerType) {
1145
1142
Set <Method > annotatedMethods = AnnotationUtils .getAnnotatedMethodsInBaseType (clazz );
1146
1143
if (!annotatedMethods .isEmpty ()) {
1147
1144
for (Method annotatedMethod : annotatedMethods ) {
1148
- if (annotatedMethod .getName ().equals (method .getName ()) &&
1149
- Arrays .equals (annotatedMethod .getParameterTypes (), method .getParameterTypes ())) {
1145
+ if (AnnotationUtils .isOverride (method , annotatedMethod )) {
1150
1146
Method resolvedSuperMethod = BridgeMethodResolver .findBridgedMethod (annotatedMethod );
1151
1147
result = searchWithFindSemantics (resolvedSuperMethod , annotationType , annotationName ,
1152
1148
containerType , processor , visited , metaDepth );
@@ -1203,8 +1199,7 @@ private static <T> T searchOnInterfaces(Method method, @Nullable Class<? extends
1203
1199
Set <Method > annotatedMethods = AnnotationUtils .getAnnotatedMethodsInBaseType (ifc );
1204
1200
if (!annotatedMethods .isEmpty ()) {
1205
1201
for (Method annotatedMethod : annotatedMethods ) {
1206
- if (annotatedMethod .getName ().equals (method .getName ()) &&
1207
- Arrays .equals (annotatedMethod .getParameterTypes (), method .getParameterTypes ())) {
1202
+ if (AnnotationUtils .isOverride (method , annotatedMethod )) {
1208
1203
T result = searchWithFindSemantics (annotatedMethod , annotationType , annotationName ,
1209
1204
containerType , processor , visited , metaDepth );
1210
1205
if (result != null ) {
@@ -1280,7 +1275,7 @@ private static Class<? extends Annotation> resolveContainerType(Class<? extends
1280
1275
1281
1276
/**
1282
1277
* Validate that the supplied {@code containerType} is a proper container
1283
- * annotation for the supplied repeatable {@code annotationType} (i.e.,
1278
+ * annotation for the supplied repeatable {@code annotationType} (i.e.
1284
1279
* that it declares a {@code value} attribute that holds an array of the
1285
1280
* {@code annotationType}).
1286
1281
* @throws AnnotationConfigurationException if the supplied {@code containerType}
@@ -1322,27 +1317,24 @@ private static <A extends Annotation> Set<A> postProcessAndSynthesizeAggregatedR
1322
1317
1323
1318
/**
1324
1319
* Callback interface that is used to process annotations during a search.
1325
- * <p>Depending on the use case, a processor may choose to
1326
- * {@linkplain #process} a single target annotation, multiple target
1327
- * annotations, or all annotations discovered by the currently executing
1328
- * search. The term "target" in this context refers to a matching
1329
- * annotation (i.e., a specific annotation type that was found during
1330
- * the search).
1331
- * <p>Returning a non-null value from the {@link #process}
1332
- * method instructs the search algorithm to stop searching further;
1333
- * whereas, returning {@code null} from the {@link #process} method
1334
- * instructs the search algorithm to continue searching for additional
1335
- * annotations. One exception to this rule applies to processors
1336
- * that {@linkplain #aggregates aggregate} results. If an aggregating
1337
- * processor returns a non-null value, that value will be added to the
1338
- * list of {@linkplain #getAggregatedResults aggregated results}
1320
+ * <p>Depending on the use case, a processor may choose to {@linkplain #process}
1321
+ * a single target annotation, multiple target annotations, or all annotations
1322
+ * discovered by the currently executing search. The term "target" in this
1323
+ * context refers to a matching annotation (i.e. a specific annotation type
1324
+ * that was found during the search).
1325
+ * <p>Returning a non-null value from the {@link #process} method instructs
1326
+ * the search algorithm to stop searching further; whereas, returning
1327
+ * {@code null} from the {@link #process} method instructs the search
1328
+ * algorithm to continue searching for additional annotations. One exception
1329
+ * to this rule applies to processors that {@linkplain #aggregates aggregate}
1330
+ * results. If an aggregating processor returns a non-null value, that value
1331
+ * will be added to the {@linkplain #getAggregatedResults aggregated results}
1339
1332
* and the search algorithm will continue.
1340
- * <p>Processors can optionally {@linkplain #postProcess post-process}
1341
- * the result of the {@link #process} method as the search algorithm
1342
- * goes back down the annotation hierarchy from an invocation of
1343
- * {@link #process} that returned a non-null value down to the
1344
- * {@link AnnotatedElement} that was supplied as the starting point to
1345
- * the search algorithm.
1333
+ * <p>Processors can optionally {@linkplain #postProcess post-process} the
1334
+ * result of the {@link #process} method as the search algorithm goes back
1335
+ * down the annotation hierarchy from an invocation of {@link #process} that
1336
+ * returned a non-null value down to the {@link AnnotatedElement} that was
1337
+ * supplied as the starting point to the search algorithm.
1346
1338
* @param <T> the type of result returned by the processor
1347
1339
*/
1348
1340
private interface Processor <T > {
0 commit comments