Support non-standard classes in Kotlin reflection discovery methods
Issue: SPR-15999
This commit is contained in:
parent
65f556c0e2
commit
3996f33399
|
@ -735,6 +735,7 @@ public abstract class BeanUtils {
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
|
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
|
||||||
|
try {
|
||||||
KFunction<T> primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz));
|
KFunction<T> primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz));
|
||||||
if (primaryConstructor == null) {
|
if (primaryConstructor == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -744,6 +745,10 @@ public abstract class BeanUtils {
|
||||||
() -> "Failed to find Java constructor corresponding to Kotlin primary constructor: " + clazz.getName());
|
() -> "Failed to find Java constructor corresponding to Kotlin primary constructor: " + clazz.getName());
|
||||||
return constructor;
|
return constructor;
|
||||||
}
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate a Kotlin class using the provided constructor.
|
* Instantiate a Kotlin class using the provided constructor.
|
||||||
|
|
|
@ -781,6 +781,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
|
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
|
||||||
|
try {
|
||||||
KFunction<T> primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz));
|
KFunction<T> primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz));
|
||||||
if (primaryConstructor == null) {
|
if (primaryConstructor == null) {
|
||||||
return 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());
|
Assert.notNull(constructor, "Can't get the Java constructor corresponding to the Kotlin primary constructor of " + clazz.getName());
|
||||||
return constructor;
|
return constructor;
|
||||||
}
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,9 +62,14 @@ public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDis
|
||||||
if (!useKotlinSupport(method.getDeclaringClass())) {
|
if (!useKotlinSupport(method.getDeclaringClass())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
|
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
|
||||||
return (function != null ? getParameterNames(function.getParameters()) : null);
|
return (function != null ? getParameterNames(function.getParameters()) : null);
|
||||||
}
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -72,9 +77,14 @@ public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDis
|
||||||
if (!useKotlinSupport(ctor.getDeclaringClass())) {
|
if (!useKotlinSupport(ctor.getDeclaringClass())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
|
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
|
||||||
return (function != null ? getParameterNames(function.getParameters()) : null);
|
return (function != null ? getParameterNames(function.getParameters()) : null);
|
||||||
}
|
}
|
||||||
|
catch (UnsupportedOperationException ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String[] getParameterNames(List<KParameter> parameters) {
|
private String[] getParameterNames(List<KParameter> parameters) {
|
||||||
|
|
Loading…
Reference in New Issue