Polishing
This commit is contained in:
@@ -29,7 +29,7 @@ import org.springframework.core.annotation.AliasFor;
|
||||
*
|
||||
* <p>When present, either directly or as a meta-annotation, this annotation
|
||||
* triggers the configured {@linkplain ReflectiveProcessor processors} against
|
||||
* the annotated element. By default, a reflection hint is added on the
|
||||
* the annotated element. By default, a reflection hint is registered for the
|
||||
* annotated element so that it can be discovered and invoked if necessary.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
@@ -37,6 +37,7 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* @since 6.0
|
||||
* @see SimpleReflectiveProcessor
|
||||
* @see ReflectiveRuntimeHintsRegistrar
|
||||
* @see RegisterReflectionForBinding @RegisterReflectionForBinding
|
||||
*/
|
||||
@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.CONSTRUCTOR,
|
||||
ElementType.FIELD, ElementType.METHOD })
|
||||
|
||||
@@ -24,8 +24,12 @@ import org.springframework.aot.hint.ReflectionHints;
|
||||
* Process an {@link AnnotatedElement} and register the necessary reflection
|
||||
* hints for it.
|
||||
*
|
||||
* <p>{@code ReflectiveProcessor} implementations are registered via
|
||||
* {@link Reflective#processors() @Reflective(processors = ...)}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 6.0
|
||||
* @see Reflective @Reflective
|
||||
*/
|
||||
public interface ReflectiveProcessor {
|
||||
|
||||
|
||||
@@ -96,12 +96,12 @@ public class ReflectiveRuntimeHintsRegistrar {
|
||||
.stream(Reflective.class)
|
||||
.map(annotation -> annotation.getClassArray("value"))
|
||||
.flatMap(Arrays::stream)
|
||||
.map(type -> (Class<? extends ReflectiveProcessor>) type)
|
||||
.distinct()
|
||||
.map(type -> (Class<? extends ReflectiveProcessor>) type)
|
||||
.map(processorClass -> this.processors.computeIfAbsent(processorClass, this::instantiateClass))
|
||||
.toList();
|
||||
ReflectiveProcessor processorToUse = (processors.size() == 1 ? processors.get(0)
|
||||
: new DelegatingReflectiveProcessor(processors));
|
||||
ReflectiveProcessor processorToUse = (processors.size() == 1 ? processors.get(0) :
|
||||
new DelegatingReflectiveProcessor(processors));
|
||||
return new Entry(element, processorToUse);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,25 +25,24 @@ import java.lang.annotation.Target;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Indicate that the classes specified in the annotation attributes require some
|
||||
* Indicates that the classes specified in the annotation attributes require some
|
||||
* reflection hints for binding or reflection-based serialization purposes. For each
|
||||
* class specified, hints on constructors, fields, properties, record components,
|
||||
* including types transitively used on properties and record components are registered.
|
||||
* At least one class must be specified in the {@code value} or {@code classes} annotation
|
||||
* attributes.
|
||||
*
|
||||
* <p>The annotated element can be a configuration class, for example:
|
||||
* <p>The annotated element can be a configuration class — for example:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Configuration
|
||||
* @RegisterReflectionForBinding({ Foo.class, Bar.class })
|
||||
* public class MyConfig {
|
||||
*
|
||||
* // ...
|
||||
* }</pre>
|
||||
*
|
||||
* <p>The annotated element can also be any Spring bean class, constructor, field, or method.
|
||||
* For example:
|
||||
* <p>The annotated element can be any Spring bean class, constructor, field,
|
||||
* or method — for example:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Service
|
||||
@@ -56,9 +55,13 @@ import org.springframework.core.annotation.AliasFor;
|
||||
*
|
||||
* }</pre>
|
||||
*
|
||||
* <p>The annotated element can also be any test class that uses the <em>Spring
|
||||
* TestContext Framework</em> to load an {@code ApplicationContext}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 6.0
|
||||
* @see org.springframework.aot.hint.BindingReflectionHintsRegistrar
|
||||
* @see Reflective @Reflective
|
||||
*/
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@@ -67,10 +70,7 @@ import org.springframework.core.annotation.AliasFor;
|
||||
public @interface RegisterReflectionForBinding {
|
||||
|
||||
/**
|
||||
* Classes for which reflection hints should be registered.
|
||||
* <p>At least one class must be specified either via {@link #value} or
|
||||
* {@link #classes}.
|
||||
* @see #classes()
|
||||
* Alias for {@link #classes()}.
|
||||
*/
|
||||
@AliasFor("classes")
|
||||
Class<?>[] value() default {};
|
||||
|
||||
@@ -36,9 +36,11 @@ public class RegisterReflectionForBindingProcessor implements ReflectiveProcesso
|
||||
|
||||
private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
|
||||
|
||||
|
||||
@Override
|
||||
public void registerReflectionHints(ReflectionHints hints, AnnotatedElement element) {
|
||||
RegisterReflectionForBinding registerReflection = AnnotationUtils.getAnnotation(element, RegisterReflectionForBinding.class);
|
||||
RegisterReflectionForBinding registerReflection =
|
||||
AnnotationUtils.getAnnotation(element, RegisterReflectionForBinding.class);
|
||||
if (registerReflection != null) {
|
||||
Class<?>[] classes = registerReflection.classes();
|
||||
Assert.state(classes.length != 0, () -> "A least one class should be specified in " +
|
||||
|
||||
Reference in New Issue
Block a user