Harmonize hint registration

Previously, a shortcut method for the default ExecutableMode was
provided, but we found out that the shortcut makes it harder to
determine the intent.

This commit harmonizes hints registration for types, methods, and
fields. An ExecutableMode is now mandatory to register a method or
constructor. Previous methods that infer a mode or provided a
customizer of the builder are deprecated.

Closes gh-29135
This commit is contained in:
Stephane Nicoll
2022-08-24 07:21:02 +02:00
parent c8f7a76659
commit 58a2b79699
14 changed files with 97 additions and 165 deletions

View File

@@ -1007,7 +1007,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
AccessVisibility visibility = AccessVisibility.forMember(method);
if (visibility == AccessVisibility.PRIVATE
|| visibility == AccessVisibility.PROTECTED) {
hints.reflection().registerMethod(method);
hints.reflection().registerMethod(method, ExecutableMode.INVOKE);
code.add(".resolveAndInvoke($L, $L)", REGISTERED_BEAN_PARAMETER,
INSTANCE_PARAMETER);
}

View File

@@ -145,7 +145,7 @@ class BeanDefinitionPropertiesCodeGenerator {
private void addInitDestroyHint(Class<?> beanUserClass, String methodName) {
Method method = ReflectionUtils.findMethod(beanUserClass, methodName);
if (method != null) {
this.hints.reflection().registerMethod(method);
this.hints.reflection().registerMethod(method, ExecutableMode.INVOKE);
}
}

View File

@@ -147,7 +147,7 @@ class InstanceSupplierCodeGenerator {
Class<?> beanClass, Constructor<?> constructor, boolean dependsOnBean) {
this.generationContext.getRuntimeHints().reflection()
.registerConstructor(constructor);
.registerConstructor(constructor, ExecutableMode.INVOKE);
GeneratedMethod generatedMethod = generateGetInstanceSupplierMethod(method -> {
method.addJavadoc("Get the bean instance supplier for '$L'.", beanName);
method.addModifiers(PRIVATE_STATIC);
@@ -240,7 +240,7 @@ class InstanceSupplierCodeGenerator {
Method factoryMethod, Class<?> declaringClass) {
this.generationContext.getRuntimeHints().reflection()
.registerMethod(factoryMethod);
.registerMethod(factoryMethod, ExecutableMode.INVOKE);
GeneratedMethod getInstanceMethod = generateGetInstanceSupplierMethod(method -> {
method.addJavadoc("Get the bean instance supplier for '$L'.", beanName);
method.addModifiers(PRIVATE_STATIC);