Support non-standard classes in Kotlin reflection discovery methods

Issue: SPR-15999
This commit is contained in:
Sebastien Deleuze 2017-09-24 22:44:07 +02:00
parent 65f556c0e2
commit 3996f33399
3 changed files with 35 additions and 15 deletions

View File

@ -735,6 +735,7 @@ public abstract class BeanUtils {
*/
@Nullable
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
try {
KFunction<T> primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz));
if (primaryConstructor == null) {
return null;
@ -744,6 +745,10 @@ public abstract class BeanUtils {
() -> "Failed to find Java constructor corresponding to Kotlin primary constructor: " + clazz.getName());
return constructor;
}
catch (UnsupportedOperationException ex) {
return null;
}
}
/**
* Instantiate a Kotlin class using the provided constructor.

View File

@ -781,6 +781,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
*/
@Nullable
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
try {
KFunction<T> primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz));
if (primaryConstructor == null) {
return null;
@ -789,6 +790,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
Assert.notNull(constructor, "Can't get the Java constructor corresponding to the Kotlin primary constructor of " + clazz.getName());
return constructor;
}
catch (UnsupportedOperationException ex) {
return null;
}
}
}

View File

@ -62,9 +62,14 @@ public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDis
if (!useKotlinSupport(method.getDeclaringClass())) {
return null;
}
try {
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
return (function != null ? getParameterNames(function.getParameters()) : null);
}
catch (UnsupportedOperationException ex) {
return null;
}
}
@Override
@Nullable
@ -72,9 +77,14 @@ public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDis
if (!useKotlinSupport(ctor.getDeclaringClass())) {
return null;
}
try {
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
return (function != null ? getParameterNames(function.getParameters()) : null);
}
catch (UnsupportedOperationException ex) {
return null;
}
}
@Nullable
private String[] getParameterNames(List<KParameter> parameters) {