11package com.wrongwrong.mapk.core
22
33import com.wrongwrong.mapk.annotations.KConstructor
4+ import com.wrongwrong.mapk.annotations.KGetterAlias
45import com.wrongwrong.mapk.annotations.KPropertyAlias
56import com.wrongwrong.mapk.annotations.KPropertyIgnore
7+ import java.lang.reflect.Method
68import kotlin.reflect.KClass
79import kotlin.reflect.KFunction
810import kotlin.reflect.KParameter
@@ -15,6 +17,7 @@ import kotlin.reflect.full.isSuperclassOf
1517import kotlin.reflect.full.memberProperties
1618import kotlin.reflect.full.primaryConstructor
1719import kotlin.reflect.jvm.isAccessible
20+ import kotlin.reflect.jvm.javaGetter
1821
1922class 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