From 71ba7bc5e0406c4dc80982375ed2900278033b25 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Wed, 23 Aug 2023 15:49:48 +0200 Subject: [PATCH] Polishing --- .../annotation/AnnotationBeanNameGenerator.java | 14 +++++++------- .../AnnotationBeanNameGeneratorTests.java | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) 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 6d696e7140..3b335be175 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 @@ -95,17 +95,17 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator { */ @Nullable protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) { - AnnotationMetadata amd = annotatedDef.getMetadata(); - Set types = amd.getAnnotationTypes(); + AnnotationMetadata metadata = annotatedDef.getMetadata(); + Set annotationTypes = metadata.getAnnotationTypes(); String beanName = null; - for (String type : types) { - AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(amd, type); + for (String annotationType : annotationTypes) { + AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(metadata, annotationType); if (attributes != null) { - Set metaTypes = this.metaAnnotationTypesCache.computeIfAbsent(type, key -> { - Set result = amd.getMetaAnnotationTypes(key); + Set metaAnnotationTypes = this.metaAnnotationTypesCache.computeIfAbsent(annotationType, key -> { + Set result = metadata.getMetaAnnotationTypes(key); return (result.isEmpty() ? Collections.emptySet() : result); }); - if (isStereotypeWithNameValue(type, metaTypes, attributes)) { + if (isStereotypeWithNameValue(annotationType, metaAnnotationTypes, attributes)) { Object value = attributes.get("value"); if (value instanceof String currentName && !currentName.isBlank()) { if (beanName != null && !currentName.equals(beanName)) { diff --git a/spring-context/src/test/java/org/springframework/context/annotation/AnnotationBeanNameGeneratorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/AnnotationBeanNameGeneratorTests.java index c2d9c70efa..1d127d2102 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/AnnotationBeanNameGeneratorTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/AnnotationBeanNameGeneratorTests.java @@ -65,6 +65,11 @@ class AnnotationBeanNameGeneratorTests { assertGeneratedName(ComponentWithName.class, "walden"); } + @Test + void generateBeanNameWithNamedComponentWhereTheNameIsBlank() { + assertGeneratedNameIsDefault(ComponentWithBlankName.class); + } + @Test void generateBeanNameWithJakartaNamedComponent() { assertGeneratedName(JakartaNamedComponent.class, "myJakartaNamedComponent"); @@ -80,11 +85,6 @@ class AnnotationBeanNameGeneratorTests { assertGeneratedName(DefaultNamedComponent.class, "thoreau"); } - @Test - void generateBeanNameWithNamedComponentWhereTheNameIsBlank() { - assertGeneratedNameIsDefault(ComponentWithBlankName.class); - } - @Test void generateBeanNameWithAnonymousComponentYieldsGeneratedBeanName() { assertGeneratedNameIsDefault(AnonymousComponent.class);