Update AOT support after RuntimeHints changes
This commit adapts AOT support in various modules after the RuntimeHints and related deprecation changes. `MemberCategory.INTROSPECT_*` hints are now removed and `MemberCategory.*_FIELDS` are replaced with `MemberCategory.INVOKE*_FIELDS` when invocation is needed. Usage of `RuntimeHintsAgent` are also deprecated. Closes gh-33847
This commit is contained in:
@@ -1065,7 +1065,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
|
||||
}
|
||||
else {
|
||||
codeWarnings.detectDeprecation(method);
|
||||
hints.reflection().registerMethod(method, ExecutableMode.INTROSPECT);
|
||||
hints.reflection().registerType(method.getDeclaringClass());
|
||||
CodeBlock arguments = new AutowiredArgumentsCodeGenerator(this.target,
|
||||
method).generateCode(method.getParameterTypes());
|
||||
CodeBlock injectionCode = CodeBlock.of("args -> $L.$L($L)",
|
||||
|
||||
@@ -252,10 +252,10 @@ class BeanDefinitionPropertiesCodeGenerator {
|
||||
// ReflectionUtils#findField searches recursively in the type hierarchy
|
||||
Class<?> searchType = beanDefinition.getTargetType();
|
||||
while (searchType != null && searchType != writeMethod.getDeclaringClass()) {
|
||||
this.hints.reflection().registerType(searchType, MemberCategory.DECLARED_FIELDS);
|
||||
this.hints.reflection().registerType(searchType, MemberCategory.INVOKE_DECLARED_FIELDS);
|
||||
searchType = searchType.getSuperclass();
|
||||
}
|
||||
this.hints.reflection().registerType(writeMethod.getDeclaringClass(), MemberCategory.DECLARED_FIELDS);
|
||||
this.hints.reflection().registerType(writeMethod.getDeclaringClass(), MemberCategory.INVOKE_DECLARED_FIELDS);
|
||||
}
|
||||
|
||||
private void addQualifiers(CodeBlock.Builder code, RootBeanDefinition beanDefinition) {
|
||||
|
||||
@@ -26,9 +26,9 @@ import org.springframework.aot.generate.GeneratedMethods;
|
||||
import org.springframework.aot.generate.GenerationContext;
|
||||
import org.springframework.aot.generate.MethodReference;
|
||||
import org.springframework.aot.generate.MethodReference.ArgumentCodeGenerator;
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.ReflectionHints;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.TypeHint;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.RegisteredBean;
|
||||
import org.springframework.javapoet.ClassName;
|
||||
@@ -100,8 +100,8 @@ class BeanRegistrationsAotContribution
|
||||
registrations.forEach(registration -> {
|
||||
ReflectionHints hints = runtimeHints.reflection();
|
||||
Class<?> beanClass = registration.registeredBean.getBeanClass();
|
||||
hints.registerType(beanClass, MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS);
|
||||
hints.registerForInterfaces(beanClass, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
|
||||
hints.registerType(beanClass);
|
||||
hints.registerForInterfaces(beanClass, TypeHint.Builder::withMembers);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -172,8 +172,7 @@ public class InstanceSupplierCodeGenerator {
|
||||
}
|
||||
|
||||
private CodeBlock generateCodeForAccessibleConstructor(String beanName, Constructor<?> constructor) {
|
||||
this.generationContext.getRuntimeHints().reflection().registerConstructor(
|
||||
constructor, ExecutableMode.INTROSPECT);
|
||||
this.generationContext.getRuntimeHints().reflection().registerType(constructor.getDeclaringClass());
|
||||
|
||||
if (constructor.getParameterCount() == 0) {
|
||||
if (!this.allowDirectSupplierShortcut) {
|
||||
@@ -265,7 +264,7 @@ public class InstanceSupplierCodeGenerator {
|
||||
private CodeBlock generateCodeForAccessibleFactoryMethod(String beanName,
|
||||
Method factoryMethod, Class<?> targetClass, @Nullable String factoryBeanName) {
|
||||
|
||||
this.generationContext.getRuntimeHints().reflection().registerMethod(factoryMethod, ExecutableMode.INTROSPECT);
|
||||
this.generationContext.getRuntimeHints().reflection().registerType(factoryMethod.getDeclaringClass());
|
||||
|
||||
if (factoryBeanName == null && factoryMethod.getParameterCount() == 0) {
|
||||
Class<?> suppliedType = ClassUtils.resolvePrimitiveIfNecessary(factoryMethod.getReturnType());
|
||||
|
||||
Reference in New Issue
Block a user