From 5e5e95aff76df1d2f2784a81279da75f7923bb06 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 27 Jun 2022 16:29:34 +0200 Subject: [PATCH] Polish RuntimeHintsUtils --- ...iveProcessorBeanRegistrationAotProcessor.java | 2 +- .../aot/hint/support/RuntimeHintsUtils.java | 16 ++++++++-------- .../aot/hint/support/RuntimeHintsUtilsTests.java | 3 --- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorBeanRegistrationAotProcessor.java b/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorBeanRegistrationAotProcessor.java index 87d808523c..02a824ae88 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorBeanRegistrationAotProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorBeanRegistrationAotProcessor.java @@ -45,7 +45,7 @@ import org.springframework.util.ReflectionUtils; /** * AOT {@code BeanRegistrationAotProcessor} that detects the presence of - * {@link Reflective @Reflective} on annotated elements and invoke the + * {@link Reflective @Reflective} on annotated elements and invokes the * underlying {@link ReflectiveProcessor} implementations. * * @author Stephane Nicoll diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java b/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java index 538381f13e..b8eff9c103 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/RuntimeHintsUtils.java @@ -29,7 +29,6 @@ import org.springframework.aot.hint.TypeHint; import org.springframework.aot.hint.TypeHint.Builder; import org.springframework.aot.hint.annotation.Reflective; import org.springframework.core.annotation.AliasFor; -import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.SynthesizedAnnotation; /** @@ -49,10 +48,11 @@ public abstract class RuntimeHintsUtils { /** * Register the necessary hints so that the specified annotation is visible - * at runtime. If an annotation attributes aliases an attribute of another - * annotation, it is registered as well and a JDK proxy hints is defined + * at runtime. + *

If an annotation attribute aliases an attribute of another annotation, + * the other annotation is registered as well and a JDK proxy hint is defined * so that the synthesized annotation can be resolved. - * @param hints the {@link RuntimeHints} instance ot use + * @param hints the {@link RuntimeHints} instance to use * @param annotationType the annotation type * @see SynthesizedAnnotation */ @@ -61,7 +61,7 @@ public abstract class RuntimeHintsUtils { Set> allAnnotations = new LinkedHashSet<>(); collectAliasedAnnotations(new HashSet<>(), allAnnotations, annotationType); allAnnotations.forEach(annotation -> hints.reflection().registerType(annotation, ANNOTATION_HINT)); - if (allAnnotations.size() > 0) { + if (!allAnnotations.isEmpty()) { hints.proxies().registerJdkProxy(annotationType, SynthesizedAnnotation.class); } } @@ -72,9 +72,9 @@ public abstract class RuntimeHintsUtils { } seen.add(annotationType); for (Method method : annotationType.getDeclaredMethods()) { - MergedAnnotations methodAnnotations = MergedAnnotations.from(method); - if (methodAnnotations.isPresent(AliasFor.class)) { - Class annotationAttribute = methodAnnotations.get(AliasFor.class).getClass("annotation"); + AliasFor aliasFor = method.getAnnotation(AliasFor.class); + if (aliasFor != null) { + Class annotationAttribute = aliasFor.annotation(); Class targetAnnotation = (annotationAttribute != Annotation.class ? annotationAttribute : annotationType); if (!types.contains(targetAnnotation)) { diff --git a/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java b/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java index 3533bd7ca7..b851d01de8 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/support/RuntimeHintsUtilsTests.java @@ -104,17 +104,14 @@ class RuntimeHintsUtilsTests { @SampleInvoker static class SampleInvokerClass { - } @RetryInvoker static class RetryInvokerClass { - } @RetryWithEnabledFlagInvoker static class RetryWithEnabledFlagInvokerClass { - } @Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })