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

Commit d836a3c

Browse files
committed
共通化対応
1 parent 50421fc commit d836a3c

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import com.mapk.annotations.KConverter
44
import com.mapk.conversion.KConvertBy
55
import com.mapk.core.KFunctionWithInstance
66
import com.mapk.core.ValueParameter
7+
import com.mapk.core.getAnnotatedFunctionsFromCompanionObject
78
import kotlin.reflect.KClass
89
import kotlin.reflect.KFunction
9-
import kotlin.reflect.full.companionObjectInstance
1010
import kotlin.reflect.full.findAnnotation
11-
import kotlin.reflect.full.functions
1211
import kotlin.reflect.full.isSubclassOf
1312
import kotlin.reflect.full.primaryConstructor
1413
import kotlin.reflect.full.staticFunctions
@@ -39,17 +38,12 @@ private fun <T : Any> convertersFromStaticMethods(clazz: KClass<T>): Set<Pair<KC
3938

4039
@Suppress("UNCHECKED_CAST")
4140
private fun <T : Any> convertersFromCompanionObject(clazz: KClass<T>): Set<Pair<KClass<*>, KFunction<T>>> {
42-
return clazz.companionObjectInstance?.let { companionObject ->
43-
companionObject::class.functions
44-
.filter { it.annotations.any { annotation -> annotation is KConverter } }
45-
.map { function ->
46-
val func: KFunction<T> = KFunctionWithInstance(
47-
function,
48-
companionObject
49-
) as KFunction<T>
41+
return clazz.getAnnotatedFunctionsFromCompanionObject<KConverter>()?.let { (instance, functions) ->
42+
functions.map { function ->
43+
val func: KFunction<T> = KFunctionWithInstance(function, instance) as KFunction<T>
5044

51-
(func.parameters.single().type.classifier as KClass<*>) to func
52-
}.toSet()
45+
(func.parameters.single().type.classifier as KClass<*>) to func
46+
}.toSet()
5347
} ?: emptySet()
5448
}
5549

0 commit comments

Comments
 (0)