@@ -386,13 +386,9 @@ 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 );
396
392
}
397
393
398
394
// Exhaustive retrieval of merged annotation attributes...
@@ -671,13 +667,9 @@ public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedEleme
671
667
@ Nullable
672
668
public static <A extends Annotation > A findMergedAnnotation (AnnotatedElement element , Class <A > annotationType ) {
673
669
// 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
- }
670
+ A annotation = element .getDeclaredAnnotation (annotationType );
671
+ if (annotation != null ) {
672
+ return AnnotationUtils .synthesizeAnnotation (annotation , element );
681
673
}
682
674
683
675
// Exhaustive retrieval of merged annotation attributes...
@@ -1140,8 +1132,7 @@ else if (currentAnnotationType == containerType) {
1140
1132
Set <Method > annotatedMethods = AnnotationUtils .getAnnotatedMethodsInBaseType (clazz );
1141
1133
if (!annotatedMethods .isEmpty ()) {
1142
1134
for (Method annotatedMethod : annotatedMethods ) {
1143
- if (annotatedMethod .getName ().equals (method .getName ()) &&
1144
- Arrays .equals (annotatedMethod .getParameterTypes (), method .getParameterTypes ())) {
1135
+ if (AnnotationUtils .isOverride (method , annotatedMethod )) {
1145
1136
Method resolvedSuperMethod = BridgeMethodResolver .findBridgedMethod (annotatedMethod );
1146
1137
result = searchWithFindSemantics (resolvedSuperMethod , annotationType , annotationName ,
1147
1138
containerType , processor , visited , metaDepth );
@@ -1198,8 +1189,7 @@ private static <T> T searchOnInterfaces(Method method, @Nullable Class<? extends
1198
1189
Set <Method > annotatedMethods = AnnotationUtils .getAnnotatedMethodsInBaseType (ifc );
1199
1190
if (!annotatedMethods .isEmpty ()) {
1200
1191
for (Method annotatedMethod : annotatedMethods ) {
1201
- if (annotatedMethod .getName ().equals (method .getName ()) &&
1202
- Arrays .equals (annotatedMethod .getParameterTypes (), method .getParameterTypes ())) {
1192
+ if (AnnotationUtils .isOverride (method , annotatedMethod )) {
1203
1193
T result = searchWithFindSemantics (annotatedMethod , annotationType , annotationName ,
1204
1194
containerType , processor , visited , metaDepth );
1205
1195
if (result != null ) {
@@ -1275,7 +1265,7 @@ private static Class<? extends Annotation> resolveContainerType(Class<? extends
1275
1265
1276
1266
/**
1277
1267
* Validate that the supplied {@code containerType} is a proper container
1278
- * annotation for the supplied repeatable {@code annotationType} (i.e.,
1268
+ * annotation for the supplied repeatable {@code annotationType} (i.e.
1279
1269
* that it declares a {@code value} attribute that holds an array of the
1280
1270
* {@code annotationType}).
1281
1271
* @throws AnnotationConfigurationException if the supplied {@code containerType}
@@ -1317,27 +1307,24 @@ private static <A extends Annotation> Set<A> postProcessAndSynthesizeAggregatedR
1317
1307
1318
1308
/**
1319
1309
* Callback interface that is used to process annotations during a search.
1320
- * <p>Depending on the use case, a processor may choose to
1321
- * {@linkplain #process} a single target annotation, multiple target
1322
- * annotations, or all annotations discovered by the currently executing
1323
- * search. The term "target" in this context refers to a matching
1324
- * annotation (i.e., a specific annotation type that was found during
1325
- * the search).
1326
- * <p>Returning a non-null value from the {@link #process}
1327
- * method instructs the search algorithm to stop searching further;
1328
- * whereas, returning {@code null} from the {@link #process} method
1329
- * instructs the search algorithm to continue searching for additional
1330
- * annotations. One exception to this rule applies to processors
1331
- * that {@linkplain #aggregates aggregate} results. If an aggregating
1332
- * processor returns a non-null value, that value will be added to the
1333
- * list of {@linkplain #getAggregatedResults aggregated results}
1310
+ * <p>Depending on the use case, a processor may choose to {@linkplain #process}
1311
+ * a single target annotation, multiple target annotations, or all annotations
1312
+ * discovered by the currently executing search. The term "target" in this
1313
+ * context refers to a matching annotation (i.e. a specific annotation type
1314
+ * that was found during the search).
1315
+ * <p>Returning a non-null value from the {@link #process} method instructs
1316
+ * the search algorithm to stop searching further; whereas, returning
1317
+ * {@code null} from the {@link #process} method instructs the search
1318
+ * algorithm to continue searching for additional annotations. One exception
1319
+ * to this rule applies to processors that {@linkplain #aggregates aggregate}
1320
+ * results. If an aggregating processor returns a non-null value, that value
1321
+ * will be added to the {@linkplain #getAggregatedResults aggregated results}
1334
1322
* and the search algorithm will continue.
1335
- * <p>Processors can optionally {@linkplain #postProcess post-process}
1336
- * the result of the {@link #process} method as the search algorithm
1337
- * goes back down the annotation hierarchy from an invocation of
1338
- * {@link #process} that returned a non-null value down to the
1339
- * {@link AnnotatedElement} that was supplied as the starting point to
1340
- * the search algorithm.
1323
+ * <p>Processors can optionally {@linkplain #postProcess post-process} the
1324
+ * result of the {@link #process} method as the search algorithm goes back
1325
+ * down the annotation hierarchy from an invocation of {@link #process} that
1326
+ * returned a non-null value down to the {@link AnnotatedElement} that was
1327
+ * supplied as the starting point to the search algorithm.
1341
1328
* @param <T> the type of result returned by the processor
1342
1329
*/
1343
1330
private interface Processor <T > {
0 commit comments