From 50421fca8d56fe6f6d57e97e6005b0a740482d0a Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 17 May 2020 01:19:05 +0900 Subject: [PATCH 1/4] =?UTF-8?q?shared=E3=81=AE=E3=82=A2=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index feb3af9..b9b731c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -30,7 +30,7 @@ repositories { dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation(kotlin("reflect")) - api("com.github.ProjectMapK:Shared:0.12") + api("com.github.ProjectMapK:Shared:0.13") // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter testImplementation(group = "org.junit.jupiter", name = "junit-jupiter", version = "5.6.2") { From d836a3c32012892faf835d97ab7be28ab64fcd56 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 23:39:42 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=8C=96=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/mapk/kmapper/ParameterUtils.kt | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt b/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt index 9dd4d97..1277fe8 100644 --- a/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt +++ b/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt @@ -4,11 +4,10 @@ import com.mapk.annotations.KConverter import com.mapk.conversion.KConvertBy import com.mapk.core.KFunctionWithInstance import com.mapk.core.ValueParameter +import com.mapk.core.getAnnotatedFunctionsFromCompanionObject import kotlin.reflect.KClass import kotlin.reflect.KFunction -import kotlin.reflect.full.companionObjectInstance import kotlin.reflect.full.findAnnotation -import kotlin.reflect.full.functions import kotlin.reflect.full.isSubclassOf import kotlin.reflect.full.primaryConstructor import kotlin.reflect.full.staticFunctions @@ -39,17 +38,12 @@ private fun convertersFromStaticMethods(clazz: KClass): Set convertersFromCompanionObject(clazz: KClass): Set, KFunction>> { - return clazz.companionObjectInstance?.let { companionObject -> - companionObject::class.functions - .filter { it.annotations.any { annotation -> annotation is KConverter } } - .map { function -> - val func: KFunction = KFunctionWithInstance( - function, - companionObject - ) as KFunction + return clazz.getAnnotatedFunctionsFromCompanionObject()?.let { (instance, functions) -> + functions.map { function -> + val func: KFunction = KFunctionWithInstance(function, instance) as KFunction - (func.parameters.single().type.classifier as KClass<*>) to func - }.toSet() + (func.parameters.single().type.classifier as KClass<*>) to func + }.toSet() } ?: emptySet() } From c69c967c7aa5c70880244b7e148e8de035ba9991 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 23:40:35 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=8C=96=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt b/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt index 1277fe8..d4024ef 100644 --- a/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt +++ b/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt @@ -4,6 +4,7 @@ import com.mapk.annotations.KConverter import com.mapk.conversion.KConvertBy import com.mapk.core.KFunctionWithInstance import com.mapk.core.ValueParameter +import com.mapk.core.getAnnotatedFunctions import com.mapk.core.getAnnotatedFunctionsFromCompanionObject import kotlin.reflect.KClass import kotlin.reflect.KFunction @@ -17,7 +18,7 @@ internal fun KClass.getConverters(): Set, KFunction< convertersFromConstructors(this) + convertersFromStaticMethods(this) + convertersFromCompanionObject(this) private fun Collection>.getConvertersFromFunctions(): Set, KFunction>> { - return filter { it.annotations.any { annotation -> annotation is KConverter } } + return this.getAnnotatedFunctions() .map { func -> func.isAccessible = true From 9d5f18842161ee041ca12294032a4d9094ae5745 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 23:55:55 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=8C=96=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt b/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt index d4024ef..e7048d7 100644 --- a/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt +++ b/src/main/kotlin/com/mapk/kmapper/ParameterUtils.kt @@ -6,6 +6,7 @@ import com.mapk.core.KFunctionWithInstance import com.mapk.core.ValueParameter import com.mapk.core.getAnnotatedFunctions import com.mapk.core.getAnnotatedFunctionsFromCompanionObject +import com.mapk.core.getKClass import kotlin.reflect.KClass import kotlin.reflect.KFunction import kotlin.reflect.full.findAnnotation @@ -22,7 +23,7 @@ private fun Collection>.getConvertersFromFunctions(): Set func.isAccessible = true - (func.parameters.single().type.classifier as KClass<*>) to func + func.parameters.single().getKClass() to func }.toSet() } @@ -43,7 +44,7 @@ private fun convertersFromCompanionObject(clazz: KClass): Set val func: KFunction = KFunctionWithInstance(function, instance) as KFunction - (func.parameters.single().type.classifier as KClass<*>) to func + func.parameters.single().getKClass() to func }.toSet() } ?: emptySet() }