From ad99add429139420217a28b6dc4701f07b270efa Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 30 Jul 2022 10:50:50 +0300 Subject: [PATCH] Polish AOT support --- .../beans/factory/aot/AotServices.java | 21 +++++++++---------- ...nFactoryInitializationAotContribution.java | 3 +-- ...BeanFactoryInitializationAotProcessor.java | 13 +++++------- .../aot/BeanFactoryInitializationCode.java | 4 ++-- .../aot/ApplicationContextAotInitializer.java | 2 +- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotServices.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotServices.java index b632556d8e6..6c171764c3d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotServices.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotServices.java @@ -71,8 +71,7 @@ public final class AotServices implements Iterable { return Collections.unmodifiableList(services); } - private Map collectSources(Collection loaded, - Collection beans) { + private Map collectSources(Collection loaded, Collection beans) { Map sources = new IdentityHashMap<>(); loaded.forEach(service -> sources.put(service, Source.SPRING_FACTORIES_LOADER)); beans.forEach(service -> sources.put(service, Source.BEAN_FACTORY)); @@ -80,7 +79,7 @@ public final class AotServices implements Iterable { } /** - * Return a new {@link Loader} that will obtain AOT services from + * Create a new {@link Loader} that will obtain AOT services from * {@value #FACTORIES_RESOURCE_LOCATION}. * @return a new {@link Loader} instance */ @@ -89,7 +88,7 @@ public final class AotServices implements Iterable { } /** - * Return a new {@link Loader} that will obtain AOT services from + * Create a new {@link Loader} that will obtain AOT services from * {@value #FACTORIES_RESOURCE_LOCATION}. * @param classLoader the class loader used to load the factories resource * @return a new {@link Loader} instance @@ -99,7 +98,7 @@ public final class AotServices implements Iterable { } /** - * Return a new {@link Loader} that will obtain AOT services from the given + * Create a new {@link Loader} that will obtain AOT services from the given * {@link SpringFactoriesLoader}. * @param springFactoriesLoader the spring factories loader * @return a new {@link Loader} instance @@ -110,20 +109,20 @@ public final class AotServices implements Iterable { } /** - * Return a new {@link Loader} that will obtain AOT services from + * Create a new {@link Loader} that will obtain AOT services from * {@value #FACTORIES_RESOURCE_LOCATION} as well as the given * {@link ListableBeanFactory}. * @param beanFactory the bean factory * @return a new {@link Loader} instance */ public static Loader factoriesAndBeans(ListableBeanFactory beanFactory) { - ClassLoader classLoader = (beanFactory instanceof ConfigurableBeanFactory configurableBeanFactory) - ? configurableBeanFactory.getBeanClassLoader() : null; + ClassLoader classLoader = (beanFactory instanceof ConfigurableBeanFactory configurableBeanFactory ? + configurableBeanFactory.getBeanClassLoader() : null); return factoriesAndBeans(getSpringFactoriesLoader(classLoader), beanFactory); } /** - * Return a new {@link Loader} that will obtain AOT services from the given + * Create a new {@link Loader} that will obtain AOT services from the given * {@link SpringFactoriesLoader} and {@link ListableBeanFactory}. * @param springFactoriesLoader the spring factories loader * @param beanFactory the bean factory @@ -163,7 +162,7 @@ public final class AotServices implements Iterable { } /** - * Return the AOT services that was loaded for the given bean name. + * Find the AOT service that was loaded for the given bean name. * @param beanName the bean name * @return the AOT service or {@code null} */ @@ -173,7 +172,7 @@ public final class AotServices implements Iterable { } /** - * Return the source of the given service. + * Get the source of the given service. * @param service the service instance * @return the source of the service */ diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotContribution.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotContribution.java index 2cfffc4a87b..d2242102ff6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotContribution.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotContribution.java @@ -34,8 +34,7 @@ import org.springframework.aot.generate.GenerationContext; public interface BeanFactoryInitializationAotContribution { /** - * Apply this contribution to the given - * {@link BeanFactoryInitializationCode}. + * Apply this contribution to the given {@link BeanFactoryInitializationCode}. * @param generationContext the active generation context * @param beanFactoryInitializationCode the bean factory initialization code */ diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotProcessor.java index b0c12743d35..fb9504992ed 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotProcessor.java @@ -28,10 +28,9 @@ import org.springframework.lang.Nullable; * registered in a {@value AotServices#FACTORIES_RESOURCE_LOCATION} resource or * as a bean. * - *

- * Note: Using this interface on a registered bean will cause the bean + *

Note: Using this interface on a registered bean will cause the bean * and all of its dependencies to be initialized during AOT processing. - * We generally recommend that interface is only used with infrastructure beans + * We generally recommend that this interface is only used with infrastructure beans * such as {@link BeanFactoryPostProcessor} which have limited dependencies and * are already initialized early in the bean factory lifecycle. * @@ -46,14 +45,12 @@ public interface BeanFactoryInitializationAotProcessor { /** * Process the given {@link ConfigurableListableBeanFactory} instance * ahead-of-time and return a contribution or {@code null}. - *

- * 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 * bean factory. Most typically use reflection to find fields or methods to * use in the contribution. Contributions typically generate source code or * resource files that can be used when the AOT optimized application runs. - *

- * If the given bean factory does not contain anything that is relevant to - * the processor, it should return a {@code null} contribution. + *

If the given bean factory does not contain anything that is relevant to + * the processor, this method should return a {@code null} contribution. * @param beanFactory the bean factory to process * @return a {@link BeanFactoryInitializationAotContribution} or {@code null} */ diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationCode.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationCode.java index 269911787e1..654fdda5866 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationCode.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationCode.java @@ -30,12 +30,12 @@ import org.springframework.aot.generate.MethodReference; public interface BeanFactoryInitializationCode { /** - * The recommended variable name to used referring to the bean factory. + * The recommended variable name to use to refer to the bean factory. */ String BEAN_FACTORY_VARIABLE = "beanFactory"; /** - * Return the {@link GeneratedMethods} being used by the Initializing code. + * Get the {@link GeneratedMethods} used by the initializing code. * @return the generated methods */ GeneratedMethods getMethods(); diff --git a/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotInitializer.java b/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotInitializer.java index 766758496c3..efc148ba762 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotInitializer.java +++ b/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotInitializer.java @@ -37,7 +37,7 @@ public class ApplicationContextAotInitializer { /** * Initialize the specified application context using the specified - * {@link ApplicationContextInitializer} class names. Each class name is + * {@link ApplicationContextInitializer} class names. Each class is * expected to have a default constructor. * @param context the context to initialize * @param initializerClassNames the application context initializer class names