@@ -386,13 +386,9 @@ public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElemen
386386 @ Nullable
387387 public static <A extends Annotation > A getMergedAnnotation (AnnotatedElement element , Class <A > annotationType ) {
388388 // 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 );
396392 }
397393
398394 // Exhaustive retrieval of merged annotation attributes...
@@ -671,13 +667,9 @@ public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedEleme
671667 @ Nullable
672668 public static <A extends Annotation > A findMergedAnnotation (AnnotatedElement element , Class <A > annotationType ) {
673669 // 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 );
681673 }
682674
683675 // Exhaustive retrieval of merged annotation attributes...
@@ -1140,8 +1132,7 @@ else if (currentAnnotationType == containerType) {
11401132 Set <Method > annotatedMethods = AnnotationUtils .getAnnotatedMethodsInBaseType (clazz );
11411133 if (!annotatedMethods .isEmpty ()) {
11421134 for (Method annotatedMethod : annotatedMethods ) {
1143- if (annotatedMethod .getName ().equals (method .getName ()) &&
1144- Arrays .equals (annotatedMethod .getParameterTypes (), method .getParameterTypes ())) {
1135+ if (AnnotationUtils .isOverride (method , annotatedMethod )) {
11451136 Method resolvedSuperMethod = BridgeMethodResolver .findBridgedMethod (annotatedMethod );
11461137 result = searchWithFindSemantics (resolvedSuperMethod , annotationType , annotationName ,
11471138 containerType , processor , visited , metaDepth );
@@ -1198,8 +1189,7 @@ private static <T> T searchOnInterfaces(Method method, @Nullable Class<? extends
11981189 Set <Method > annotatedMethods = AnnotationUtils .getAnnotatedMethodsInBaseType (ifc );
11991190 if (!annotatedMethods .isEmpty ()) {
12001191 for (Method annotatedMethod : annotatedMethods ) {
1201- if (annotatedMethod .getName ().equals (method .getName ()) &&
1202- Arrays .equals (annotatedMethod .getParameterTypes (), method .getParameterTypes ())) {
1192+ if (AnnotationUtils .isOverride (method , annotatedMethod )) {
12031193 T result = searchWithFindSemantics (annotatedMethod , annotationType , annotationName ,
12041194 containerType , processor , visited , metaDepth );
12051195 if (result != null ) {
@@ -1275,7 +1265,7 @@ private static Class<? extends Annotation> resolveContainerType(Class<? extends
12751265
12761266 /**
12771267 * 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.
12791269 * that it declares a {@code value} attribute that holds an array of the
12801270 * {@code annotationType}).
12811271 * @throws AnnotationConfigurationException if the supplied {@code containerType}
@@ -1317,27 +1307,24 @@ private static <A extends Annotation> Set<A> postProcessAndSynthesizeAggregatedR
13171307
13181308 /**
13191309 * 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}
13341322 * 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.
13411328 * @param <T> the type of result returned by the processor
13421329 */
13431330 private interface Processor <T > {
0 commit comments