This repository was archived by the owner on Jan 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
src/main/kotlin/com/wrongwrong/mapk/core Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 11package com.wrongwrong.mapk.core
22
3+ import com.wrongwrong.mapk.annotations.KConstructor
34import com.wrongwrong.mapk.annotations.PropertyAlias
45import com.wrongwrong.mapk.annotations.PropertyIgnore
56import kotlin.reflect.KClass
@@ -9,6 +10,7 @@ import kotlin.reflect.KProperty1
910import kotlin.reflect.KVisibility
1011import kotlin.reflect.full.isSuperclassOf
1112import kotlin.reflect.full.memberProperties
13+ import kotlin.reflect.full.primaryConstructor
1214
1315class KMapper <T : Any >(private val function : KFunction <T >, propertyNameConverter : (String ) -> String = { it }) {
1416 constructor (clazz: KClass <T >, propertyNameConverter: (String ) -> String = { it }): this (
@@ -92,7 +94,14 @@ class KMapper<T: Any>(private val function: KFunction<T>, propertyNameConverter:
9294}
9395
9496private fun <T : Any > getTarget (clazz : KClass <T >): KFunction <T > {
95- TODO ()
97+ val constructors: List <KFunction <T >> = clazz.constructors
98+ .filter { it.annotations.any { annotation -> annotation is KConstructor } }
99+
100+ if (constructors.size == 1 ) return constructors.single()
101+
102+ if (constructors.isEmpty()) return clazz.primaryConstructor!!
103+
104+ throw IllegalArgumentException (" Find multiple target." )
96105}
97106
98107private fun Collection <KProperty1 <* , * >>.filterTargets (): Collection <KProperty1 <* , * >> {
You can’t perform that action at this time.
0 commit comments