Skip to content

Commit

Permalink
Consider Kotlin when checking if parameter names are available
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Nov 17, 2022
1 parent cd455a9 commit b9e57c7
Showing 1 changed file with 14 additions and 2 deletions.
Expand Up @@ -33,7 +33,10 @@
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.core.KotlinDetector;
import org.springframework.core.KotlinReflectionParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.PrioritizedParameterNameDiscoverer;
import org.springframework.core.ResolvableType;
import org.springframework.core.StandardReflectionParameterNameDiscoverer;
import org.springframework.core.annotation.MergedAnnotations;
Expand Down Expand Up @@ -109,7 +112,16 @@ public static BindableRuntimeHintsRegistrar forTypes(Class<?>... types) {
*/
private final class Processor {

private static final ParameterNameDiscoverer PARAMETER_NAME_DISCOVERER = new StandardReflectionParameterNameDiscoverer();
private static final ParameterNameDiscoverer parameterNameDiscoverer;

static {
PrioritizedParameterNameDiscoverer discoverer = new PrioritizedParameterNameDiscoverer();
if (KotlinDetector.isKotlinReflectPresent()) {
discoverer.addDiscoverer(new KotlinReflectionParameterNameDiscoverer());
}
discoverer.addDiscoverer(new StandardReflectionParameterNameDiscoverer());
parameterNameDiscoverer = discoverer;
}

private final Class<?> type;

Expand Down Expand Up @@ -159,7 +171,7 @@ private void handleConstructor(ReflectionHints hints) {
}

private void verifyParameterNamesAreAvailable() {
String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(this.bindConstructor);
String[] parameterNames = parameterNameDiscoverer.getParameterNames(this.bindConstructor);
if (parameterNames == null) {
this.compiledWithoutParameters.add(this.bindConstructor.getDeclaringClass());
}
Expand Down

0 comments on commit b9e57c7

Please sign in to comment.