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

Commit c08467b

Browse files
committed
コンバータ取得処理を切り出し
ついでに関数のスコープを整理
1 parent 1ef5c10 commit c08467b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import kotlin.reflect.full.functions
99
import kotlin.reflect.full.staticFunctions
1010
import kotlin.reflect.jvm.isAccessible
1111

12-
internal fun <T> Collection<KFunction<T>>.getConverterMapFromFunctions(): Set<Pair<KClass<*>, KFunction<T>>> {
12+
internal fun <T : Any> KClass<T>.getConverters(): Set<Pair<KClass<*>, KFunction<T>>> =
13+
convertersFromConstructors(this) + convertersFromStaticMethods(this) + convertersFromCompanionObject(this)
14+
15+
private fun <T> Collection<KFunction<T>>.getConverterMapFromFunctions(): Set<Pair<KClass<*>, KFunction<T>>> {
1316
return filter { it.annotations.any { annotation -> annotation is KConverter } }
1417
.map { func ->
1518
func.isAccessible = true
@@ -18,19 +21,19 @@ internal fun <T> Collection<KFunction<T>>.getConverterMapFromFunctions(): Set<Pa
1821
}.toSet()
1922
}
2023

21-
internal fun <T : Any> convertersFromConstructors(clazz: KClass<T>): Set<Pair<KClass<*>, KFunction<T>>> {
24+
private fun <T : Any> convertersFromConstructors(clazz: KClass<T>): Set<Pair<KClass<*>, KFunction<T>>> {
2225
return clazz.constructors.getConverterMapFromFunctions()
2326
}
2427

2528
@Suppress("UNCHECKED_CAST")
26-
internal fun <T : Any> convertersFromStaticMethods(clazz: KClass<T>): Set<Pair<KClass<*>, KFunction<T>>> {
29+
private fun <T : Any> convertersFromStaticMethods(clazz: KClass<T>): Set<Pair<KClass<*>, KFunction<T>>> {
2730
val staticFunctions: Collection<KFunction<T>> = clazz.staticFunctions as Collection<KFunction<T>>
2831

2932
return staticFunctions.getConverterMapFromFunctions()
3033
}
3134

3235
@Suppress("UNCHECKED_CAST")
33-
internal fun <T : Any> convertersFromCompanionObject(clazz: KClass<T>): Set<Pair<KClass<*>, KFunction<T>>> {
36+
private fun <T : Any> convertersFromCompanionObject(clazz: KClass<T>): Set<Pair<KClass<*>, KFunction<T>>> {
3437
return clazz.companionObjectInstance?.let { companionObject ->
3538
companionObject::class.functions
3639
.filter { it.annotations.any { annotation -> annotation is KConverter } }

0 commit comments

Comments
 (0)