diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java index e43425b8345..1e6221424ab 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationBeanNameGenerator.java @@ -101,15 +101,13 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator { @Nullable protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) { AnnotationMetadata metadata = annotatedDef.getMetadata(); - Set annotationTypes = metadata.getAnnotationTypes(); - String explicitBeanName = getExplicitBeanName(metadata); - if (explicitBeanName != null) { - return explicitBeanName; + String beanName = getExplicitBeanName(metadata); + if (beanName != null) { + return beanName; } - String beanName = null; - for (String annotationType : annotationTypes) { + for (String annotationType : metadata.getAnnotationTypes()) { AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(metadata, annotationType); if (attributes != null) { Set metaAnnotationTypes = this.metaAnnotationTypesCache.computeIfAbsent(annotationType, key -> { diff --git a/spring-core/src/main/java/org/springframework/core/type/AnnotationMetadata.java b/spring-core/src/main/java/org/springframework/core/type/AnnotationMetadata.java index 532630a76b0..49a8f38eaa6 100644 --- a/spring-core/src/main/java/org/springframework/core/type/AnnotationMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/AnnotationMetadata.java @@ -40,8 +40,8 @@ import org.springframework.core.annotation.MergedAnnotations; public interface AnnotationMetadata extends ClassMetadata, AnnotatedTypeMetadata { /** - * Get the fully qualified class names of all annotation types that - * are present on the underlying class. + * Get the fully-qualified class names of all annotation types that are + * directly present on the underlying class. * @return the annotation type names */ default Set getAnnotationTypes() { @@ -52,9 +52,9 @@ public interface AnnotationMetadata extends ClassMetadata, AnnotatedTypeMetadata } /** - * Get the fully qualified class names of all meta-annotation types that - * are present on the given annotation type on the underlying class. - * @param annotationName the fully qualified class name of the annotation + * Get the fully-qualified class names of all meta-annotation types that are + * present on the given annotation type on the underlying class. + * @param annotationName the fully-qualified class name of the annotation * type to look for meta-annotations on * @return the meta-annotation type names, or an empty set if none found */ @@ -69,11 +69,11 @@ public interface AnnotationMetadata extends ClassMetadata, AnnotatedTypeMetadata } /** - * Determine whether an annotation of the given type is present on - * the underlying class. - * @param annotationName the fully qualified class name of the annotation + * Determine whether an annotation of the given type is directly present + * on the underlying class. + * @param annotationName the fully-qualified class name of the annotation * type to look for - * @return {@code true} if a matching annotation is present + * @return {@code true} if a matching annotation is directly present */ default boolean hasAnnotation(String annotationName) { return getAnnotations().isDirectlyPresent(annotationName); @@ -82,7 +82,7 @@ public interface AnnotationMetadata extends ClassMetadata, AnnotatedTypeMetadata /** * Determine whether the underlying class has an annotation that is itself * annotated with the meta-annotation of the given type. - * @param metaAnnotationName the fully qualified class name of the + * @param metaAnnotationName the fully-qualified class name of the * meta-annotation type to look for * @return {@code true} if a matching meta-annotation is present */ @@ -94,7 +94,7 @@ public interface AnnotationMetadata extends ClassMetadata, AnnotatedTypeMetadata /** * Determine whether the underlying class has any methods that are * annotated (or meta-annotated) with the given annotation type. - * @param annotationName the fully qualified class name of the annotation + * @param annotationName the fully-qualified class name of the annotation * type to look for */ default boolean hasAnnotatedMethods(String annotationName) { @@ -106,7 +106,7 @@ public interface AnnotationMetadata extends ClassMetadata, AnnotatedTypeMetadata * (or meta-annotated) with the given annotation type. *

For any returned method, {@link MethodMetadata#isAnnotated} will * return {@code true} for the given annotation type. - * @param annotationName the fully qualified class name of the annotation + * @param annotationName the fully-qualified class name of the annotation * type to look for * @return a set of {@link MethodMetadata} for methods that have a matching * annotation. The return value will be an empty set if no methods match