Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 364e4d0

Browse files
committed
クラスから呼び出す際はjavaGetterを使うように修正
1 parent 2eca20f commit 364e4d0

File tree

1 file changed

+15
-8
lines changed
  • src/main/kotlin/com/wrongwrong/mapk/core

1 file changed

+15
-8
lines changed

src/main/kotlin/com/wrongwrong/mapk/core/KMapper.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.wrongwrong.mapk.core
22

33
import com.wrongwrong.mapk.annotations.KConstructor
4+
import com.wrongwrong.mapk.annotations.KGetterAlias
45
import com.wrongwrong.mapk.annotations.KPropertyAlias
56
import com.wrongwrong.mapk.annotations.KPropertyIgnore
7+
import java.lang.reflect.Method
68
import kotlin.reflect.KClass
79
import kotlin.reflect.KFunction
810
import kotlin.reflect.KParameter
@@ -15,6 +17,7 @@ import kotlin.reflect.full.isSuperclassOf
1517
import kotlin.reflect.full.memberProperties
1618
import kotlin.reflect.full.primaryConstructor
1719
import kotlin.reflect.jvm.isAccessible
20+
import kotlin.reflect.jvm.javaGetter
1821

1922
class KMapper<T : Any> private constructor(
2023
private val function: KFunctionForCall<T>,
@@ -62,10 +65,12 @@ class KMapper<T : Any> private constructor(
6265
val array: Array<Any?> = function.argumentArray
6366

6467
src::class.memberProperties.forEach { property ->
65-
if (property.visibility == KVisibility.PUBLIC && property.annotations.none { annotation -> annotation is KPropertyIgnore }) {
66-
val getter = property.getAccessibleGetter()
67-
parameterMap[getter.findAnnotation<KPropertyAlias>()?.value ?: property.name]?.let {
68-
array[it.index] = getter.call(src)?.let { value -> mapObject(it, value) }
68+
val javaGetter: Method? = property.javaGetter
69+
if (javaGetter != null && property.visibility == KVisibility.PUBLIC && property.annotations.none { annotation -> annotation is KPropertyIgnore }) {
70+
parameterMap[property.findAnnotation<KGetterAlias>()?.value ?: property.name]?.let {
71+
// javaGetterを呼び出す方が高速
72+
javaGetter.isAccessible = true
73+
array[it.index] = javaGetter.invoke(src)?.let { value -> mapObject(it, value) }
6974
}
7075
}
7176
}
@@ -88,10 +93,12 @@ class KMapper<T : Any> private constructor(
8893
array[it.index] = arg.second?.let { value -> mapObject(it, value) }
8994
}
9095
else -> arg::class.memberProperties.forEach { property ->
91-
if (property.visibility == KVisibility.PUBLIC && property.annotations.none { annotation -> annotation is KPropertyIgnore }) {
92-
val getter = property.getAccessibleGetter()
93-
parameterMap[getter.findAnnotation<KPropertyAlias>()?.value ?: property.name]?.let {
94-
array[it.index] = getter.call(arg)?.let { value -> mapObject(it, value) }
96+
val javaGetter: Method? = property.javaGetter
97+
if (javaGetter != null && property.visibility == KVisibility.PUBLIC && property.annotations.none { annotation -> annotation is KPropertyIgnore }) {
98+
parameterMap[property.findAnnotation<KGetterAlias>()?.value ?: property.name]?.let {
99+
// javaGetterを呼び出す方が高速
100+
javaGetter.isAccessible = true
101+
array[it.index] = javaGetter.invoke(arg)?.let { value -> mapObject(it, value) }
95102
}
96103
}
97104
}

0 commit comments

Comments
 (0)