@@ -2,17 +2,14 @@ package com.mapk.kmapper
22
33import com.mapk.annotations.KGetterAlias
44import com.mapk.annotations.KGetterIgnore
5- import com.mapk.core.ArgumentBucket
5+ import com.mapk.core.ArgumentAdaptor
66import com.mapk.core.KFunctionForCall
7- import com.mapk.core.getAliasOrName
8- import com.mapk.core.isUseDefaultArgument
97import com.mapk.core.toKConstructor
108import java.lang.reflect.Method
119import java.util.concurrent.ConcurrentHashMap
1210import java.util.concurrent.ConcurrentMap
1311import kotlin.reflect.KClass
1412import kotlin.reflect.KFunction
15- import kotlin.reflect.KParameter
1613import kotlin.reflect.KVisibility
1714import kotlin.reflect.full.memberProperties
1815import kotlin.reflect.jvm.javaGetter
@@ -35,13 +32,13 @@ class KMapper<T : Any> private constructor(
3532
3633 private val getCache: ConcurrentMap <KClass <* >, List <ArgumentBinder >> = ConcurrentHashMap ()
3734
38- private fun bindArguments (argumentBucket : ArgumentBucket , src : Any ) {
35+ private fun bindArguments (argumentAdaptor : ArgumentAdaptor , src : Any ) {
3936 val clazz = src::class
4037
4138 // キャッシュヒットしたら登録した内容に沿って取得処理を行う
4239 getCache[clazz]?.let { getters ->
4340 // 取得対象フィールドは十分絞り込んでいると考えられるため、終了判定は行わない
44- getters.forEach { it.bindArgument(src, argumentBucket ) }
41+ getters.forEach { it.bindArgument(src, argumentAdaptor ) }
4542 return
4643 }
4744
@@ -66,64 +63,66 @@ class KMapper<T : Any> private constructor(
6663
6764 val binder = ArgumentBinder (param, javaGetter)
6865
69- binder.bindArgument(src, argumentBucket )
66+ binder.bindArgument(src, argumentAdaptor )
7067 tempBinderArrayList.add(binder)
7168 // キャッシュの整合性を保つため、ここでは終了判定を行わない
7269 }
7370 }
7471 getCache.putIfAbsent(clazz, tempBinderArrayList)
7572 }
7673
77- private fun bindArguments (argumentBucket : ArgumentBucket , src : Map <* , * >) {
74+ private fun bindArguments (argumentAdaptor : ArgumentAdaptor , src : Map <* , * >) {
7875 src.forEach { (key, value) ->
7976 parameterMap[key]?.let { param ->
8077 // 取得した内容がnullでなければ適切にmapする
81- argumentBucket .putIfAbsent(param.param , value?.let { param.mapObject(value) })
78+ argumentAdaptor .putIfAbsent(param.name , value?.let { param.mapObject(value) })
8279 // 終了判定
83- if (argumentBucket.isInitialized ) return
80+ if (argumentAdaptor.isFullInitialized() ) return
8481 }
8582 }
8683 }
8784
88- private fun bindArguments (argumentBucket : ArgumentBucket , srcPair : Pair <* , * >) {
89- parameterMap[srcPair.first.toString()]?.let {
90- argumentBucket.putIfAbsent(it.param, srcPair.second?.let { value -> it.mapObject(value) })
85+ private fun bindArguments (argumentAdaptor : ArgumentAdaptor , srcPair : Pair <* , * >) {
86+ val key = srcPair.first.toString()
87+
88+ parameterMap[key]?.let {
89+ argumentAdaptor.putIfAbsent(key, srcPair.second?.let { value -> it.mapObject(value) })
9190 }
9291 }
9392
9493 fun map (srcMap : Map <String , Any ?>): T {
95- val bucket : ArgumentBucket = function.getArgumentBucket ()
96- bindArguments(bucket , srcMap)
94+ val adaptor : ArgumentAdaptor = function.getArgumentAdaptor ()
95+ bindArguments(adaptor , srcMap)
9796
98- return function.call(bucket )
97+ return function.call(adaptor )
9998 }
10099
101100 fun map (srcPair : Pair <String , Any ?>): T {
102- val bucket : ArgumentBucket = function.getArgumentBucket ()
103- bindArguments(bucket , srcPair)
101+ val adaptor : ArgumentAdaptor = function.getArgumentAdaptor ()
102+ bindArguments(adaptor , srcPair)
104103
105- return function.call(bucket )
104+ return function.call(adaptor )
106105 }
107106
108107 fun map (src : Any ): T {
109- val bucket : ArgumentBucket = function.getArgumentBucket ()
110- bindArguments(bucket , src)
108+ val adaptor : ArgumentAdaptor = function.getArgumentAdaptor ()
109+ bindArguments(adaptor , src)
111110
112- return function.call(bucket )
111+ return function.call(adaptor )
113112 }
114113
115114 fun map (vararg args : Any ): T {
116- val bucket : ArgumentBucket = function.getArgumentBucket ()
115+ val adaptor : ArgumentAdaptor = function.getArgumentAdaptor ()
117116
118117 listOf (* args).forEach { arg ->
119118 when (arg) {
120- is Map <* , * > -> bindArguments(bucket , arg)
121- is Pair <* , * > -> bindArguments(bucket , arg)
122- else -> bindArguments(bucket , arg)
119+ is Map <* , * > -> bindArguments(adaptor , arg)
120+ is Pair <* , * > -> bindArguments(adaptor , arg)
121+ else -> bindArguments(adaptor , arg)
123122 }
124123 }
125124
126- return function.call(bucket )
125+ return function.call(adaptor )
127126 }
128127}
129128
0 commit comments