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

Commit 5663ade

Browse files
committed
拡張関数の方を使うように修正
BoundKMapperに関しては別扱いの処理なので修正していない
1 parent bbea5e4 commit 5663ade

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

src/main/kotlin/com/mapk/kmapper/ParameterForMap.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.mapk.core.EnumMapper
44
import kotlin.reflect.KClass
55
import kotlin.reflect.KFunction
66
import kotlin.reflect.KParameter
7-
import kotlin.reflect.full.isSubclassOf
87
import kotlin.reflect.full.isSuperclassOf
98

109
internal class ParameterForMap<T : Any> private constructor(val param: KParameter, private val clazz: KClass<T>) {
@@ -28,7 +27,7 @@ internal class ParameterForMap<T : Any> private constructor(val param: KParamete
2827
return value
2928
}
3029

31-
val converter: KFunction<*>? = getConverter(valueClazz)
30+
val converter: KFunction<*>? = converters.getConverter(valueClazz)
3231

3332
val lambda: (Any) -> Any? = when {
3433
// converterに一致する組み合わせが有れば設定されていればそれを使う
@@ -43,10 +42,6 @@ internal class ParameterForMap<T : Any> private constructor(val param: KParamete
4342
return lambda(value)
4443
}
4544

46-
// 引数の型がconverterに対して入力可能ならconverterを返す
47-
private fun <R : Any> getConverter(input: KClass<out R>): KFunction<T>? =
48-
converters.find { (key, _) -> input.isSubclassOf(key) }?.second
49-
5045
companion object {
5146
fun newInstance(param: KParameter): ParameterForMap<*> {
5247
return ParameterForMap(param, param.type.classifier as KClass<*>)

src/main/kotlin/com/mapk/kmapper/PlainParameterForMap.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.mapk.core.EnumMapper
44
import kotlin.reflect.KClass
55
import kotlin.reflect.KFunction
66
import kotlin.reflect.KParameter
7-
import kotlin.reflect.full.isSubclassOf
87
import kotlin.reflect.full.isSuperclassOf
98

109
internal class PlainParameterForMap<T : Any> private constructor(val param: KParameter, private val clazz: KClass<T>) {
@@ -20,7 +19,7 @@ internal class PlainParameterForMap<T : Any> private constructor(val param: KPar
2019
// パラメータに対してvalueが代入可能(同じもしくは親クラス)であればそのまま用いる
2120
if (clazz.isSuperclassOf(valueClazz)) return value
2221

23-
val converter: KFunction<*>? = getConverter(valueClazz)
22+
val converter: KFunction<*>? = converters.getConverter(valueClazz)
2423

2524
return when {
2625
// converterに一致する組み合わせが有れば設定されていればそれを使う
@@ -33,10 +32,6 @@ internal class PlainParameterForMap<T : Any> private constructor(val param: KPar
3332
}
3433
}
3534

36-
// 引数の型がconverterに対して入力可能ならconverterを返す
37-
private fun <R : Any> getConverter(input: KClass<out R>): KFunction<T>? =
38-
converters.find { (key, _) -> input.isSubclassOf(key) }?.second
39-
4035
companion object {
4136
fun newInstance(param: KParameter): PlainParameterForMap<*> {
4237
return PlainParameterForMap(param, param.type.classifier as KClass<*>)

0 commit comments

Comments
 (0)