@@ -386,13 +386,14 @@ 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 );
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 ;
396397 }
397398
398399 // Exhaustive retrieval of merged annotation attributes...
@@ -671,13 +672,9 @@ public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedEleme
671672 @ Nullable
672673 public static <A extends Annotation > A findMergedAnnotation (AnnotatedElement element , Class <A > annotationType ) {
673674 // 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 );
681678 }
682679
683680 // 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) {
11451142 Set <Method > annotatedMethods = AnnotationUtils .getAnnotatedMethodsInBaseType (clazz );
11461143 if (!annotatedMethods .isEmpty ()) {
11471144 for (Method annotatedMethod : annotatedMethods ) {
1148- if (annotatedMethod .getName ().equals (method .getName ()) &&
1149- Arrays .equals (annotatedMethod .getParameterTypes (), method .getParameterTypes ())) {
1145+ if (AnnotationUtils .isOverride (method , annotatedMethod )) {
11501146 Method resolvedSuperMethod = BridgeMethodResolver .findBridgedMethod (annotatedMethod );
11511147 result = searchWithFindSemantics (resolvedSuperMethod , annotationType , annotationName ,
11521148 containerType , processor , visited , metaDepth );
@@ -1203,8 +1199,7 @@ private static <T> T searchOnInterfaces(Method method, @Nullable Class<? extends
12031199 Set <Method > annotatedMethods = AnnotationUtils .getAnnotatedMethodsInBaseType (ifc );
12041200 if (!annotatedMethods .isEmpty ()) {
12051201 for (Method annotatedMethod : annotatedMethods ) {
1206- if (annotatedMethod .getName ().equals (method .getName ()) &&
1207- Arrays .equals (annotatedMethod .getParameterTypes (), method .getParameterTypes ())) {
1202+ if (AnnotationUtils .isOverride (method , annotatedMethod )) {
12081203 T result = searchWithFindSemantics (annotatedMethod , annotationType , annotationName ,
12091204 containerType , processor , visited , metaDepth );
12101205 if (result != null ) {
@@ -1280,7 +1275,7 @@ private static Class<? extends Annotation> resolveContainerType(Class<? extends
12801275
12811276 /**
12821277 * 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.
12841279 * that it declares a {@code value} attribute that holds an array of the
12851280 * {@code annotationType}).
12861281 * @throws AnnotationConfigurationException if the supplied {@code containerType}
@@ -1322,27 +1317,24 @@ private static <A extends Annotation> Set<A> postProcessAndSynthesizeAggregatedR
13221317
13231318 /**
13241319 * 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}
13391332 * 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.
13461338 * @param <T> the type of result returned by the processor
13471339 */
13481340 private interface Processor <T > {
0 commit comments