@@ -12,19 +12,17 @@ import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector
1212import kotlinx.metadata.jvm.fieldSignature
1313import kotlinx.metadata.jvm.getterSignature
1414import kotlinx.metadata.jvm.setterSignature
15+ import kotlinx.metadata.jvm.signature
1516import java.lang.reflect.Constructor
1617import java.lang.reflect.Method
1718import kotlin.reflect.KClass
1819import kotlin.reflect.KFunction
19- import kotlin.reflect.KParameter
2020import kotlin.reflect.full.companionObject
2121import kotlin.reflect.full.declaredFunctions
2222import kotlin.reflect.full.hasAnnotation
2323import kotlin.reflect.full.memberProperties
2424import kotlin.reflect.full.primaryConstructor
25- import kotlin.reflect.jvm.internal.KotlinReflectionInternalError
2625import kotlin.reflect.jvm.javaType
27- import kotlin.reflect.jvm.kotlinFunction
2826
2927internal class KotlinNamesAnnotationIntrospector (val module : KotlinModule , val cache : ReflectionCache , val ignoredClassesForImplyingJsonCreator : Set <KClass <* >>) : NopAnnotationIntrospector() {
3028 // since 2.4
@@ -110,37 +108,27 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
110108
111109 @Suppress(" UNCHECKED_CAST" )
112110 private fun findKotlinParameterName (param : AnnotatedParameter ): String? {
113- return if (param.declaringClass.isKotlinClass()) {
114- val member = param.owner.member
115- if (member is Constructor <* >) {
116- val ctor = (member as Constructor <Any >)
117- val ctorParmCount = ctor.parameterTypes.size
118- val ktorParmCount = try { ctor.kotlinFunction?.parameters?.size ? : 0 } catch (ex: KotlinReflectionInternalError ) { 0 } catch (ex: UnsupportedOperationException ) { 0 }
119- if (ktorParmCount > 0 && ktorParmCount == ctorParmCount) {
120- ctor.kotlinFunction?.parameters?.get(param.index)?.name
121- } else {
122- null
111+ val declaringClass = param.declaringClass
112+
113+ return declaringClass.toKmClass()?.let { kmClass ->
114+ when (val member = param.owner.member) {
115+ is Constructor <* > -> {
116+ val signature = member.toSignature()
117+
118+ kmClass.constructors.find { it.signature?.desc == signature.desc }
119+ ?.let { it.valueParameters[param.index].name }
123120 }
124- } else if (member is Method ) {
125- try {
126- val temp = member.kotlinFunction
127-
128- val firstParamKind = temp?.parameters?.firstOrNull()?.kind
129- val idx = if (firstParamKind != KParameter .Kind .VALUE ) param.index + 1 else param.index
130- val parmCount = temp?.parameters?.size ? : 0
131- if (parmCount > idx) {
132- temp?.parameters?.get(idx)?.name
133- } else {
134- null
135- }
136- } catch (ex: KotlinReflectionInternalError ) {
137- null
121+ is Method -> {
122+ val companionKmClass = declaringClass.getDeclaredField(kmClass.companionObject!! )
123+ .type
124+ .toKmClass()!!
125+ val signature = member.toSignature()
126+
127+ companionKmClass.functions.find { it.signature == signature }
128+ ?.let { it.valueParameters[param.index].name }
138129 }
139- } else {
140- null
130+ else -> null
141131 }
142- } else {
143- null
144132 }
145133 }
146134}
0 commit comments