@@ -12,19 +12,17 @@ import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector
12
12
import kotlinx.metadata.jvm.fieldSignature
13
13
import kotlinx.metadata.jvm.getterSignature
14
14
import kotlinx.metadata.jvm.setterSignature
15
+ import kotlinx.metadata.jvm.signature
15
16
import java.lang.reflect.Constructor
16
17
import java.lang.reflect.Method
17
18
import kotlin.reflect.KClass
18
19
import kotlin.reflect.KFunction
19
- import kotlin.reflect.KParameter
20
20
import kotlin.reflect.full.companionObject
21
21
import kotlin.reflect.full.declaredFunctions
22
22
import kotlin.reflect.full.hasAnnotation
23
23
import kotlin.reflect.full.memberProperties
24
24
import kotlin.reflect.full.primaryConstructor
25
- import kotlin.reflect.jvm.internal.KotlinReflectionInternalError
26
25
import kotlin.reflect.jvm.javaType
27
- import kotlin.reflect.jvm.kotlinFunction
28
26
29
27
internal class KotlinNamesAnnotationIntrospector (val module : KotlinModule , val cache : ReflectionCache , val ignoredClassesForImplyingJsonCreator : Set <KClass <* >>) : NopAnnotationIntrospector() {
30
28
// since 2.4
@@ -110,37 +108,27 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
110
108
111
109
@Suppress(" UNCHECKED_CAST" )
112
110
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 }
123
120
}
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 }
138
129
}
139
- } else {
140
- null
130
+ else -> null
141
131
}
142
- } else {
143
- null
144
132
}
145
133
}
146
134
}
0 commit comments