This commit is contained in:
Stephane Nicoll 2022-06-07 11:52:40 +02:00
parent 62d98685ce
commit ad0573a91e
5 changed files with 12 additions and 24 deletions

View File

@ -21,7 +21,6 @@ import java.beans.IntrospectionException;
import java.beans.Introspector; import java.beans.Introspector;
import java.beans.PropertyDescriptor; import java.beans.PropertyDescriptor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -138,7 +137,7 @@ class BeanDefinitionPropertiesCodeGenerator {
} }
private void addInitDestroyMethods(Builder builder, private void addInitDestroyMethods(Builder builder,
AbstractBeanDefinition beanDefinition, String[] methodNames, String format) { AbstractBeanDefinition beanDefinition, @Nullable String[] methodNames, String format) {
if (!ObjectUtils.isEmpty(methodNames)) { if (!ObjectUtils.isEmpty(methodNames)) {
Class<?> beanType = ClassUtils Class<?> beanType = ClassUtils
@ -237,15 +236,6 @@ class BeanDefinitionPropertiesCodeGenerator {
return Collections.unmodifiableMap(writeMethods); return Collections.unmodifiableMap(writeMethods);
} }
@Nullable
private Method findWriteMethod(BeanInfo beanInfo, String propertyName) {
return Arrays.stream(beanInfo.getPropertyDescriptors())
.filter(pd -> propertyName.equals(pd.getName()))
.map(java.beans.PropertyDescriptor::getWriteMethod)
.filter(Objects::nonNull).findFirst().orElse(null);
}
private void addAttributes(CodeBlock.Builder builder, BeanDefinition beanDefinition) { private void addAttributes(CodeBlock.Builder builder, BeanDefinition beanDefinition) {
String[] attributeNames = beanDefinition.attributeNames(); String[] attributeNames = beanDefinition.attributeNames();
if (!ObjectUtils.isEmpty(attributeNames)) { if (!ObjectUtils.isEmpty(attributeNames)) {

View File

@ -28,6 +28,7 @@ import org.springframework.lang.Nullable;
* {@link org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter}. * {@link org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Stephane Nicoll
* @since 6.0 * @since 6.0
* @see BeanFactoryInitializationAotContribution * @see BeanFactoryInitializationAotContribution
*/ */
@ -39,15 +40,14 @@ public interface BeanFactoryInitializationAotProcessor {
* ahead-of-time and return a contribution or {@code null}. * ahead-of-time and return a contribution or {@code null}.
* <p> * <p>
* Processors are free to use any techniques they like to analyze the given * Processors are free to use any techniques they like to analyze the given
* instance. Most typically use reflection to find fields or methods to use * bean factory. Most typically use reflection to find fields or methods to
* in the contribution. Contributions typically generate source code or * use in the contribution. Contributions typically generate source code or
* resource files that can be used when the AOT optimized application runs. * resource files that can be used when the AOT optimized application runs.
* <p> * <p>
* If the given instance isn't relevant to the processor, it should return a * If the given bean factory does not contain anything that is relevant to
* {@code null} contribution. * the processor, it should return a {@code null} contribution.
* @param beanFactory the bean factory to process * @param beanFactory the bean factory to process
* @return a {@link BeanFactoryInitializationAotContribution} or * @return a {@link BeanFactoryInitializationAotContribution} or {@code null}
* {@code null}
*/ */
@Nullable @Nullable
BeanFactoryInitializationAotContribution processAheadOfTime( BeanFactoryInitializationAotContribution processAheadOfTime(

View File

@ -48,7 +48,7 @@ public interface BeanRegistrationAotContribution {
/** /**
* Apply this contribution to the given {@link BeanRegistrationCode}. * Apply this contribution to the given {@link BeanRegistrationCode}.
* @param generationContext the active generation context * @param generationContext the generation context
* @param beanRegistrationCode the generated registration * @param beanRegistrationCode the generated registration
*/ */
void applyTo(GenerationContext generationContext, void applyTo(GenerationContext generationContext,
@ -61,7 +61,7 @@ public interface BeanRegistrationAotContribution {
* @param beanRegistrationCodeFragmentsCustomizer the * @param beanRegistrationCodeFragmentsCustomizer the
* {@link BeanRegistrationCodeFragments} customizer * {@link BeanRegistrationCodeFragments} customizer
* @return a new {@link BeanRegistrationAotContribution} instance * @return a new {@link BeanRegistrationAotContribution} instance
* @see #customizeBeanRegistrationCodeFragments(BeanRegistrationCodeFragments) * @see #customizeBeanRegistrationCodeFragments(GenerationContext, BeanRegistrationCodeFragments)
*/ */
static BeanRegistrationAotContribution ofBeanRegistrationCodeFragmentsCustomizer( static BeanRegistrationAotContribution ofBeanRegistrationCodeFragmentsCustomizer(
UnaryOperator<BeanRegistrationCodeFragments> beanRegistrationCodeFragmentsCustomizer) { UnaryOperator<BeanRegistrationCodeFragments> beanRegistrationCodeFragmentsCustomizer) {

View File

@ -20,6 +20,7 @@ import org.springframework.aot.generate.MethodGenerator;
import org.springframework.aot.generate.MethodReference; import org.springframework.aot.generate.MethodReference;
import org.springframework.beans.factory.support.InstanceSupplier; import org.springframework.beans.factory.support.InstanceSupplier;
import org.springframework.javapoet.ClassName; import org.springframework.javapoet.ClassName;
import org.springframework.util.function.ThrowingBiFunction;
/** /**
* Interface that can be used to configure the code that will be generated to * Interface that can be used to configure the code that will be generated to
@ -28,7 +29,6 @@ import org.springframework.javapoet.ClassName;
* @author Phillip Webb * @author Phillip Webb
* @since 6.0 * @since 6.0
* @see BeanRegistrationCodeFragments * @see BeanRegistrationCodeFragments
* @see BeanRegistrationCodeFragmentsCustomizer
*/ */
public interface BeanRegistrationCode { public interface BeanRegistrationCode {
@ -50,7 +50,7 @@ public interface BeanRegistrationCode {
* @param methodReference a reference to the post-process method to call. * @param methodReference a reference to the post-process method to call.
* The referenced method must have a functional signature compatible with * The referenced method must have a functional signature compatible with
* {@link InstanceSupplier#andThen}. * {@link InstanceSupplier#andThen}.
* @see InstanceSupplier#andThen(org.springframework.util.function.ThrowableBiFunction) * @see InstanceSupplier#andThen(ThrowingBiFunction)
*/ */
void addInstancePostProcessor(MethodReference methodReference); void addInstancePostProcessor(MethodReference methodReference);

View File

@ -35,8 +35,6 @@ import org.springframework.util.Assert;
* *
* @author Phillip Webb * @author Phillip Webb
* @since 6.0 * @since 6.0
* @see BeanRegistrationCodeFragmentsWrapper
* @see BeanRegistrationCodeFragmentsCustomizer
*/ */
public abstract class BeanRegistrationCodeFragments { public abstract class BeanRegistrationCodeFragments {
@ -55,7 +53,7 @@ public abstract class BeanRegistrationCodeFragments {
protected BeanRegistrationCodeFragments(BeanRegistrationCodeFragments codeFragments) { protected BeanRegistrationCodeFragments(BeanRegistrationCodeFragments codeFragments) {
Assert.notNull(codeFragments, "'codeFragments' must not be null"); Assert.notNull(codeFragments, "CodeFragments must not be null");
this.codeFragments = codeFragments; this.codeFragments = codeFragments;
} }