Skip to content

Commit 49ab9bd

Browse files
committed
Reduction of information held in function-related
1 parent 57158ec commit 49ab9bd

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/main/kotlin/io/github/projectmapk/jackson/module/kogera/deser/valueInstantiator/creator/MethodValueCreator.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import io.github.projectmapk.jackson.module.kogera.deser.valueInstantiator.argum
88
import io.github.projectmapk.jackson.module.kogera.deser.valueInstantiator.calcMaskSize
99
import io.github.projectmapk.jackson.module.kogera.getDeclaredMethodBy
1010
import io.github.projectmapk.jackson.module.kogera.jmClass.JmClass
11-
import kotlinx.metadata.KmFunction
1211
import java.lang.reflect.Method
1312

1413
internal class MethodValueCreator<T>(
@@ -26,8 +25,8 @@ internal class MethodValueCreator<T>(
2625
// To prevent the call from failing, save the initial value and then rewrite the flag.
2726
if (!method.isAccessible) method.isAccessible = true
2827

29-
val kmFunction: KmFunction = companion.findFunctionByMethod(method)!!
30-
val kmParameters = kmFunction.valueParameters
28+
val function = companion.findFunctionByMethod(method)!!
29+
val kmParameters = function.valueParameters
3130

3231
valueParameters = kmParameters.map { ValueParameter(it) }
3332
val rawTypes = method.parameterTypes.asList()

src/main/kotlin/io/github/projectmapk/jackson/module/kogera/jmClass/JmClass.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import io.github.projectmapk.jackson.module.kogera.toSignature
77
import kotlinx.metadata.ClassKind
88
import kotlinx.metadata.ClassName
99
import kotlinx.metadata.KmClass
10-
import kotlinx.metadata.KmFunction
1110
import kotlinx.metadata.isNullable
1211
import kotlinx.metadata.jvm.signature
1312
import kotlinx.metadata.kind
@@ -24,8 +23,12 @@ internal sealed interface JmClass {
2423
private val factoryFunctions by lazy {
2524
// Since it is a user-defined factory function that is processed,
2625
// 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
26+
type.toKmClass()!!.functions.mapNotNull { func ->
27+
func
28+
.takeIf {
29+
func.valueParameters.isNotEmpty() && func.returnType.reconstructClassOrNull() == declaringClass
30+
}
31+
?.let { JmFunction(it) }
2932
}
3033
}
3134
val instance: Any by lazy {
@@ -34,7 +37,7 @@ internal sealed interface JmClass {
3437
companionField.get(null)
3538
}
3639

37-
fun findFunctionByMethod(method: Method): KmFunction? {
40+
fun findFunctionByMethod(method: Method): JmFunction? {
3841
val signature = method.toSignature()
3942
return factoryFunctions.find { it.signature == signature }
4043
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.github.projectmapk.jackson.module.kogera.jmClass
2+
3+
import kotlinx.metadata.KmFunction
4+
import kotlinx.metadata.KmValueParameter
5+
import kotlinx.metadata.jvm.JvmMethodSignature
6+
import kotlinx.metadata.jvm.signature
7+
8+
internal class JmFunction(
9+
val signature: JvmMethodSignature?,
10+
val valueParameters: List<KmValueParameter>
11+
) {
12+
constructor(function: KmFunction) : this(function.signature, function.valueParameters)
13+
}

0 commit comments

Comments
 (0)