From 5b75236c17443d298e4eb2d7ced5a9dbca93be3b Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 22:55:14 +0900 Subject: [PATCH 01/10] =?UTF-8?q?=E3=82=B3=E3=83=B3=E3=83=91=E3=83=8B?= =?UTF-8?q?=E3=82=AA=E3=83=B3=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=81=8B=E3=82=89=E9=96=A2=E6=95=B0=E3=82=92=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=99=E3=82=8B=E9=96=A2=E6=95=B0=E3=82=92=E5=88=87?= =?UTF-8?q?=E3=82=8A=E5=87=BA=E3=81=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ついでに処理コストの重いcompanionObjectInstance呼び出しを後に回すよう修正 --- src/main/kotlin/com/mapk/core/Functions.kt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/kotlin/com/mapk/core/Functions.kt diff --git a/src/main/kotlin/com/mapk/core/Functions.kt b/src/main/kotlin/com/mapk/core/Functions.kt new file mode 100644 index 0000000..3f8bf53 --- /dev/null +++ b/src/main/kotlin/com/mapk/core/Functions.kt @@ -0,0 +1,20 @@ +package com.mapk.core + +import kotlin.reflect.KClass +import kotlin.reflect.KFunction +import kotlin.reflect.full.companionObject +import kotlin.reflect.full.functions + +inline fun KClass<*>.getAnnotatedFunctionFromCompanionObject(): List, Any>>? { + return this.companionObject?.let { companionObject -> + val temp = companionObject.functions.filter { functions -> functions.annotations.any { it is A } } + + if (temp.isEmpty()) { + // 空ならその後の処理をしてもしょうがないのでnullに合わせる + null + } else { + val instance = companionObject.objectInstance!! + temp.map { it to instance } + } + } +} From 9bb744b07c858ea387fe118ae30369e82fffd145 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 22:55:51 +0900 Subject: [PATCH 02/10] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=8C=96=E3=81=97?= =?UTF-8?q?=E3=81=9F=E9=96=A2=E6=95=B0=E3=82=92=E4=BD=BF=E3=81=86=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/KFunctionForCall.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt index 422d50f..0ea527f 100644 --- a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt +++ b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt @@ -10,9 +10,7 @@ import com.mapk.core.internal.isUseDefaultArgument import kotlin.reflect.KClass import kotlin.reflect.KFunction import kotlin.reflect.KParameter -import kotlin.reflect.full.companionObjectInstance import kotlin.reflect.full.findAnnotation -import kotlin.reflect.full.functions import kotlin.reflect.full.primaryConstructor import kotlin.reflect.jvm.isAccessible import kotlin.reflect.jvm.jvmName @@ -91,12 +89,8 @@ class KFunctionForCall internal constructor( internal fun KClass.toKConstructor(parameterNameConverter: ParameterNameConverter): KFunctionForCall { val constructors = ArrayList>() - this.companionObjectInstance?.let { companionObject -> - companionObject::class.functions - .filter { it.annotations.any { annotation -> annotation is KConstructor } } - .forEach { - constructors.add(KFunctionForCall(it, parameterNameConverter, companionObject) as KFunctionForCall) - } + this.getAnnotatedFunctionFromCompanionObject()?.forEach { (function, instance) -> + constructors.add(KFunctionForCall(function as KFunction, parameterNameConverter, instance)) } this.constructors From 3a6b27aea138d21a7cf67d7044596cbd366d68cc Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 23:06:24 +0900 Subject: [PATCH 03/10] =?UTF-8?q?=E9=87=8D=E8=A4=87=E3=81=97=E3=81=9F?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E3=82=92=E8=BF=94=E3=81=95=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/Functions.kt | 5 ++--- src/main/kotlin/com/mapk/core/KFunctionForCall.kt | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/Functions.kt b/src/main/kotlin/com/mapk/core/Functions.kt index 3f8bf53..b93aec9 100644 --- a/src/main/kotlin/com/mapk/core/Functions.kt +++ b/src/main/kotlin/com/mapk/core/Functions.kt @@ -5,7 +5,7 @@ import kotlin.reflect.KFunction import kotlin.reflect.full.companionObject import kotlin.reflect.full.functions -inline fun KClass<*>.getAnnotatedFunctionFromCompanionObject(): List, Any>>? { +inline fun KClass<*>.getAnnotatedFunctionFromCompanionObject(): Pair>>? { return this.companionObject?.let { companionObject -> val temp = companionObject.functions.filter { functions -> functions.annotations.any { it is A } } @@ -13,8 +13,7 @@ inline fun KClass<*>.getAnnotatedFunctionFromCompanionO // 空ならその後の処理をしてもしょうがないのでnullに合わせる null } else { - val instance = companionObject.objectInstance!! - temp.map { it to instance } + companionObject.objectInstance!! to temp } } } diff --git a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt index 0ea527f..42ea85b 100644 --- a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt +++ b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt @@ -89,8 +89,10 @@ class KFunctionForCall internal constructor( internal fun KClass.toKConstructor(parameterNameConverter: ParameterNameConverter): KFunctionForCall { val constructors = ArrayList>() - this.getAnnotatedFunctionFromCompanionObject()?.forEach { (function, instance) -> - constructors.add(KFunctionForCall(function as KFunction, parameterNameConverter, instance)) + this.getAnnotatedFunctionFromCompanionObject()?.let { (instance, functions) -> + functions.forEach { + constructors.add(KFunctionForCall(it as KFunction, parameterNameConverter, instance)) + } } this.constructors From 1ff7adf8158e29dcba1c1e7f3331f3d91e0c9b10 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 23:27:45 +0900 Subject: [PATCH 04/10] =?UTF-8?q?=E3=82=A2=E3=83=8E=E3=83=86=E3=83=BC?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E3=82=92=E6=8C=81=E3=81=A4=E9=96=A2?= =?UTF-8?q?=E6=95=B0=E3=82=92=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=83=AA?= =?UTF-8?q?=E3=83=B3=E3=82=B0=E3=81=99=E3=82=8B=E9=96=A2=E6=95=B0=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/Functions.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/com/mapk/core/Functions.kt b/src/main/kotlin/com/mapk/core/Functions.kt index b93aec9..c6333fe 100644 --- a/src/main/kotlin/com/mapk/core/Functions.kt +++ b/src/main/kotlin/com/mapk/core/Functions.kt @@ -17,3 +17,7 @@ inline fun KClass<*>.getAnnotatedFunctionFromCompanionO } } } + +inline fun Collection>.getAnnotatedFunctions(): List> { + return filter { function -> function.annotations.any { it is A } } +} From 206b84ca3be4c0aeb524751beeff08fae22eb953 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 23:27:54 +0900 Subject: [PATCH 05/10] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=8C=96=E3=81=AB?= =?UTF-8?q?=E5=90=88=E3=82=8F=E3=81=9B=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/KFunctionForCall.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt index 42ea85b..956feff 100644 --- a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt +++ b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt @@ -95,9 +95,9 @@ internal fun KClass.toKConstructor(parameterNameConverter: Paramete } } - this.constructors - .filter { it.annotations.any { annotation -> annotation is KConstructor } } - .forEach { constructors.add(KFunctionForCall(it, parameterNameConverter)) } + this.constructors.getAnnotatedFunctions().forEach { + constructors.add(KFunctionForCall(it, parameterNameConverter)) + } if (constructors.size == 1) return constructors.single() From e98892714e33b715a1ddec526d4dce106048e1d7 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 23:29:36 +0900 Subject: [PATCH 06/10] =?UTF-8?q?=E9=96=A2=E6=95=B0=E5=90=8D=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/Functions.kt | 2 +- src/main/kotlin/com/mapk/core/KFunctionForCall.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/Functions.kt b/src/main/kotlin/com/mapk/core/Functions.kt index c6333fe..814dbc0 100644 --- a/src/main/kotlin/com/mapk/core/Functions.kt +++ b/src/main/kotlin/com/mapk/core/Functions.kt @@ -5,7 +5,7 @@ import kotlin.reflect.KFunction import kotlin.reflect.full.companionObject import kotlin.reflect.full.functions -inline fun KClass<*>.getAnnotatedFunctionFromCompanionObject(): Pair>>? { +inline fun KClass<*>.getAnnotatedFunctionsFromCompanionObject(): Pair>>? { return this.companionObject?.let { companionObject -> val temp = companionObject.functions.filter { functions -> functions.annotations.any { it is A } } diff --git a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt index 956feff..579c0c4 100644 --- a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt +++ b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt @@ -89,7 +89,7 @@ class KFunctionForCall internal constructor( internal fun KClass.toKConstructor(parameterNameConverter: ParameterNameConverter): KFunctionForCall { val constructors = ArrayList>() - this.getAnnotatedFunctionFromCompanionObject()?.let { (instance, functions) -> + this.getAnnotatedFunctionsFromCompanionObject()?.let { (instance, functions) -> functions.forEach { constructors.add(KFunctionForCall(it as KFunction, parameterNameConverter, instance)) } From 0d3aecbe0387df0fa2b868d41a2ddac8e364b4bd Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 23:34:22 +0900 Subject: [PATCH 07/10] =?UTF-8?q?=E4=BD=99=E8=A8=88=E3=81=AA=E3=82=B8?= =?UTF-8?q?=E3=82=A7=E3=83=8D=E3=83=AA=E3=82=AF=E3=82=B9=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/Functions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mapk/core/Functions.kt b/src/main/kotlin/com/mapk/core/Functions.kt index 814dbc0..61bbde8 100644 --- a/src/main/kotlin/com/mapk/core/Functions.kt +++ b/src/main/kotlin/com/mapk/core/Functions.kt @@ -18,6 +18,6 @@ inline fun KClass<*>.getAnnotatedFunctionsFromCompanion } } -inline fun Collection>.getAnnotatedFunctions(): List> { +inline fun Collection>.getAnnotatedFunctions(): List> { return filter { function -> function.annotations.any { it is A } } } From 9f437392db573e42aa139bb7e95b0ab9a8f10e2b Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 23:48:19 +0900 Subject: [PATCH 08/10] =?UTF-8?q?KParameter=E3=81=8B=E3=82=89=E3=81=AE?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E5=8F=96=E5=BE=97=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/Functions.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/com/mapk/core/Functions.kt b/src/main/kotlin/com/mapk/core/Functions.kt index 61bbde8..7ef037e 100644 --- a/src/main/kotlin/com/mapk/core/Functions.kt +++ b/src/main/kotlin/com/mapk/core/Functions.kt @@ -2,6 +2,7 @@ package com.mapk.core import kotlin.reflect.KClass import kotlin.reflect.KFunction +import kotlin.reflect.KParameter import kotlin.reflect.full.companionObject import kotlin.reflect.full.functions @@ -21,3 +22,5 @@ inline fun KClass<*>.getAnnotatedFunctionsFromCompanion inline fun Collection>.getAnnotatedFunctions(): List> { return filter { function -> function.annotations.any { it is A } } } + +fun KParameter.getKClass(): KClass<*> = type.classifier as KClass<*> From e7f105cf42c8108a65c253fbfac2fb8ac959c6e0 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 16 May 2020 23:48:59 +0900 Subject: [PATCH 09/10] =?UTF-8?q?=E5=85=B1=E9=80=9A=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/KFunctionForCall.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt index 579c0c4..a9fdc52 100644 --- a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt +++ b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt @@ -123,12 +123,12 @@ private fun KParameter.toArgumentBinder(parameterNameConverter: ParameterNameCon parameterNameConverter.toSimple() } - ArgumentBinder.Function((type.classifier as KClass<*>).toKConstructor(converter), index, annotations) + ArgumentBinder.Function(getKClass().toKConstructor(converter), index, annotations) } ?: ArgumentBinder.Value( index, annotations, isOptional, parameterNameConverter.convert(name), - type.classifier as KClass<*> + getKClass() ) } From 08a18ef372a2a2c0ea648f17701cf1b517d8850a Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 17 May 2020 00:06:00 +0900 Subject: [PATCH 10/10] =?UTF-8?q?=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=82=A2=E3=83=83=E3=83=97?= 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 97cba33..52c988f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "com.mapk" -version = "0.12" +version = "0.13" java { sourceCompatibility = JavaVersion.VERSION_1_8