Skip to content

Commit

Permalink
Make use of Executable abstraction in ProxyRuntimeHintsRegistrar
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Oct 4, 2024
1 parent 911d1b0 commit 2569aa1
Showing 1 changed file with 5 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,7 @@ private void registerRuntimeHintsIfNecessary(RegisteredBean registeredBean, Exec
if (registeredBean.getBeanFactory() instanceof DefaultListableBeanFactory dlbf) {
RuntimeHints runtimeHints = this.generationContext.getRuntimeHints();
ProxyRuntimeHintsRegistrar registrar = new ProxyRuntimeHintsRegistrar(dlbf.getAutowireCandidateResolver());
if (constructorOrFactoryMethod instanceof Method method) {
registrar.registerRuntimeHints(runtimeHints, method);
}
else if (constructorOrFactoryMethod instanceof Constructor<?> constructor) {
registrar.registerRuntimeHints(runtimeHints, constructor);
}
registrar.registerRuntimeHints(runtimeHints, constructorOrFactoryMethod);
}
}

Expand Down Expand Up @@ -419,33 +414,17 @@ public static boolean hasConstructorWithOptionalParameter(Class<?> beanClass) {
}


private static class ProxyRuntimeHintsRegistrar {

private final AutowireCandidateResolver candidateResolver;

public ProxyRuntimeHintsRegistrar(AutowireCandidateResolver candidateResolver) {
this.candidateResolver = candidateResolver;
}
private record ProxyRuntimeHintsRegistrar(AutowireCandidateResolver candidateResolver) {

public void registerRuntimeHints(RuntimeHints runtimeHints, Method method) {
Class<?>[] parameterTypes = method.getParameterTypes();
public void registerRuntimeHints(RuntimeHints runtimeHints, Executable executable) {
Class<?>[] parameterTypes = executable.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
MethodParameter methodParam = new MethodParameter(method, i);
MethodParameter methodParam = MethodParameter.forExecutable(executable, i);
DependencyDescriptor dependencyDescriptor = new DependencyDescriptor(methodParam, true);
registerProxyIfNecessary(runtimeHints, dependencyDescriptor);
}
}

public void registerRuntimeHints(RuntimeHints runtimeHints, Constructor<?> constructor) {
Class<?>[] parameterTypes = constructor.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
MethodParameter methodParam = new MethodParameter(constructor, i);
DependencyDescriptor dependencyDescriptor = new DependencyDescriptor(
methodParam, true);
registerProxyIfNecessary(runtimeHints, dependencyDescriptor);
}
}

private void registerProxyIfNecessary(RuntimeHints runtimeHints, DependencyDescriptor dependencyDescriptor) {
Class<?> proxyType = this.candidateResolver.getLazyResolutionProxyClass(dependencyDescriptor, null);
if (proxyType != null && Proxy.isProxyClass(proxyType)) {
Expand Down

0 comments on commit 2569aa1

Please sign in to comment.