1
1
package io.github.projectmapk.jackson.module.kogera.jmClass
2
2
3
+ import io.github.projectmapk.jackson.module.kogera.reconstructClassOrNull
3
4
import io.github.projectmapk.jackson.module.kogera.toDescBuilder
4
5
import io.github.projectmapk.jackson.module.kogera.toKmClass
5
6
import io.github.projectmapk.jackson.module.kogera.toSignature
@@ -20,7 +21,13 @@ internal sealed interface JmClass {
20
21
private val companionField: Field = declaringClass.getDeclaredField(companionObject)
21
22
val type: Class <* > = companionField.type
22
23
val isAccessible: Boolean = companionField.isAccessible
23
- private val functions by lazy { type.toKmClass()!! .functions }
24
+ private val factoryFunctions by lazy {
25
+ // Since it is a user-defined factory function that is processed,
26
+ // it always has arguments and the return value is the same as declaringClass.
27
+ type.toKmClass()!! .functions.filter {
28
+ it.valueParameters.isNotEmpty() && it.returnType.reconstructClassOrNull() == declaringClass
29
+ }
30
+ }
24
31
val instance: Any by lazy {
25
32
// To prevent the call from failing, save the initial value and then rewrite the flag.
26
33
if (! companionField.isAccessible) companionField.isAccessible = true
@@ -29,7 +36,7 @@ internal sealed interface JmClass {
29
36
30
37
fun findFunctionByMethod (method : Method ): KmFunction ? {
31
38
val signature = method.toSignature()
32
- return functions .find { it.signature == signature }
39
+ return factoryFunctions .find { it.signature == signature }
33
40
}
34
41
}
35
42
0 commit comments