@@ -8,7 +8,6 @@ import java.lang.reflect.Method
88import kotlin.reflect.KClass
99import kotlin.reflect.KFunction
1010import kotlin.reflect.KParameter
11- import kotlin.reflect.KProperty1
1211import kotlin.reflect.KVisibility
1312import kotlin.reflect.full.companionObjectInstance
1413import kotlin.reflect.full.findAnnotation
@@ -55,16 +54,18 @@ class KMapper<T : Any> private constructor(
5554 }
5655 }
5756
58- fun map (srcMap : Map <String , Any ?>): T {
59- val array: Array <Any ?> = function.argumentArray
60-
61- srcMap.forEach { (key, value) ->
57+ private fun Map <* , * >.bindParameters (targetArray : Array <Any ?>) {
58+ forEach { (key, value) ->
6259 parameterMap[key]?.let { param ->
6360 // 取得した内容がnullでなければ適切にmapする
64- array [param.index] = value?.let { mapObject(param, it) }
61+ targetArray [param.index] = value?.let { mapObject(param, it) }
6562 }
6663 }
64+ }
6765
66+ fun map (srcMap : Map <String , Any ?>): T {
67+ val array: Array <Any ?> = function.argumentArray
68+ srcMap.bindParameters(array)
6869 return function.call(array)
6970 }
7071
@@ -85,12 +86,7 @@ class KMapper<T : Any> private constructor(
8586
8687 listOf (* args).forEach { arg ->
8788 when (arg) {
88- is Map <* , * > -> arg.forEach { (key, value) ->
89- parameterMap[key]?.let { param ->
90- // 取得した内容がnullでなければ適切にmapする
91- array[param.index] = value?.let { mapObject(param, it) }
92- }
93- }
89+ is Map <* , * > -> arg.bindParameters(array)
9490 is Pair <* , * > -> parameterMap.getValue(arg.first as String ).let {
9591 array[it.index] = arg.second?.let { value -> mapObject(it, value) }
9692 }
0 commit comments