Polish RuntimeHintsUtils

This commit is contained in:
Sam Brannen
2022-06-27 16:29:34 +02:00
parent 897e47d76d
commit 5e5e95aff7
3 changed files with 9 additions and 12 deletions

View File

@@ -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

View File

@@ -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.
* <p>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<Class<?>> 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)) {

View File

@@ -104,17 +104,14 @@ class RuntimeHintsUtilsTests {
@SampleInvoker
static class SampleInvokerClass {
}
@RetryInvoker
static class RetryInvokerClass {
}
@RetryWithEnabledFlagInvoker
static class RetryWithEnabledFlagInvokerClass {
}
@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })