From 93f0ec2fa18cf1aad0c88e1b881a5014ac59a49f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 20 Feb 2024 15:42:15 +0100 Subject: [PATCH] Polishing --- ...ifierAnnotationAutowireCandidateResolver.java | 6 +++--- .../context/annotation/Primary.java | 3 ++- ...tionContextAotGeneratorRuntimeHintsTests.java | 16 ++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java index 2f0b6bc2a0..0c238f4d56 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java @@ -282,7 +282,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa } if (actualValue == null && attributeName.equals(AutowireCandidateQualifier.VALUE_KEY) && expectedValue instanceof String name && bdHolder.matchesName(name)) { - // Fall back on bean name (or alias) match + // Finally, check bean name (or alias) match continue; } if (actualValue == null && qualifier != null) { @@ -333,8 +333,8 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa */ @Override public boolean hasQualifier(DependencyDescriptor descriptor) { - for (Annotation ann : descriptor.getAnnotations()) { - if (isQualifier(ann.annotationType())) { + for (Annotation annotation : descriptor.getAnnotations()) { + if (isQualifier(annotation.annotationType())) { return true; } } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Primary.java b/spring-context/src/main/java/org/springframework/context/annotation/Primary.java index 3832996e44..2183d3d6e1 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Primary.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Primary.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,6 +81,7 @@ import java.lang.annotation.Target; * @see Bean * @see ComponentScan * @see org.springframework.stereotype.Component + * @see org.springframework.beans.factory.config.BeanDefinition#setPrimary */ @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) diff --git a/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java b/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java index 8034870a00..f15f3589ee 100644 --- a/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java +++ b/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,8 +59,8 @@ class ApplicationContextAotGeneratorRuntimeHintsTests { void generateApplicationContextWithAutowiring() { GenericApplicationContext context = new AnnotationConfigApplicationContext(); context.registerBeanDefinition("autowiredComponent", new RootBeanDefinition(AutowiredComponent.class)); - context.registerBeanDefinition("number", BeanDefinitionBuilder.rootBeanDefinition(Integer.class, "valueOf") - .addConstructorArgValue("42").getBeanDefinition()); + context.registerBeanDefinition("number", BeanDefinitionBuilder.rootBeanDefinition( + Integer.class, "valueOf").addConstructorArgValue("42").getBeanDefinition()); compile(context, (hints, invocations) -> assertThat(invocations).match(hints)); } @@ -89,8 +89,10 @@ class ApplicationContextAotGeneratorRuntimeHintsTests { compile(context, (hints, invocations) -> assertThat(invocations).match(hints)); } - @SuppressWarnings({ "rawtypes", "unchecked" }) - private void compile(GenericApplicationContext applicationContext, BiConsumer initializationResult) { + @SuppressWarnings({"rawtypes", "unchecked"}) + private void compile(GenericApplicationContext applicationContext, + BiConsumer initializationResult) { + ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator(); TestGenerationContext generationContext = new TestGenerationContext(); generator.processAheadOfTime(applicationContext, generationContext); @@ -107,17 +109,15 @@ class ApplicationContextAotGeneratorRuntimeHintsTests { }); } + public interface Destroyable { @PreDestroy default void destroy() { - } - } public static class InheritedDestroy implements Destroyable { - } }