Polish KotlinReflectionParameterNameDiscoverer
This commit is contained in:
parent
a638828157
commit
20ddd9f864
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -41,36 +41,34 @@ public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDis
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String @Nullable [] getParameterNames(Method method) {
|
public @Nullable String @Nullable [] getParameterNames(Method method) {
|
||||||
if (!KotlinDetector.isKotlinType(method.getDeclaringClass())) {
|
if (KotlinDetector.isKotlinType(method.getDeclaringClass())) {
|
||||||
return null;
|
try {
|
||||||
}
|
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
|
||||||
|
return (function != null ? getParameterNames(function.getParameters()) : null);
|
||||||
try {
|
}
|
||||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
|
catch (UnsupportedOperationException ignored) {
|
||||||
return (function != null ? getParameterNames(function.getParameters()) : null);
|
}
|
||||||
}
|
|
||||||
catch (UnsupportedOperationException ex) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable String @Nullable [] getParameterNames(Constructor<?> ctor) {
|
public @Nullable String @Nullable [] getParameterNames(Constructor<?> ctor) {
|
||||||
if (ctor.getDeclaringClass().isEnum() || !KotlinDetector.isKotlinType(ctor.getDeclaringClass())) {
|
if (!ctor.getDeclaringClass().isEnum() && KotlinDetector.isKotlinType(ctor.getDeclaringClass())) {
|
||||||
return null;
|
try {
|
||||||
}
|
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
|
||||||
|
if (function != null) {
|
||||||
try {
|
return getParameterNames(function.getParameters());
|
||||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
|
}
|
||||||
return (function != null ? getParameterNames(function.getParameters()) : null);
|
}
|
||||||
}
|
catch (UnsupportedOperationException ignored) {
|
||||||
catch (UnsupportedOperationException ex) {
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable String @Nullable [] getParameterNames(List<KParameter> parameters) {
|
private @Nullable String @Nullable [] getParameterNames(List<KParameter> parameters) {
|
||||||
String[] parameterNames = parameters.stream()
|
@Nullable String[] parameterNames = parameters.stream()
|
||||||
// Extension receivers of extension methods must be included as they appear as normal method parameters in Java
|
// Extension receivers of extension methods must be included as they appear as normal method parameters in Java
|
||||||
.filter(p -> KParameter.Kind.VALUE.equals(p.getKind()) || KParameter.Kind.EXTENSION_RECEIVER.equals(p.getKind()))
|
.filter(p -> KParameter.Kind.VALUE.equals(p.getKind()) || KParameter.Kind.EXTENSION_RECEIVER.equals(p.getKind()))
|
||||||
// extension receivers are not explicitly named, but require a name for Java interoperability
|
// extension receivers are not explicitly named, but require a name for Java interoperability
|
||||||
|
|
Loading…
Reference in New Issue