From c694bb73de5f570240cf53731d22fa39e5129c7f Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 08:18:03 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E5=88=9D=E6=9C=9F=E5=8C=96=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92=E5=90=8C=E4=B8=80=E3=83=AB=E3=83=BC=E3=83=97?= =?UTF-8?q?=E3=81=AB=E3=81=BE=E3=81=A8=E3=82=81=E3=81=A6=E7=9C=81=E5=8A=9B?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/mapk/core/KFunctionForCall.kt | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt index 06e3036..bd5e73e 100644 --- a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt +++ b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt @@ -55,22 +55,31 @@ class KFunctionForCall internal constructor( instance ) - requiredParameters = binders.fold(ArrayList()) { acc, elm -> - when (elm) { - is ArgumentBinder.Value<*> -> acc.add(elm) - is ArgumentBinder.Function -> acc.addAll(elm.requiredParameters) + val tempList = ArrayList>(binders.size) + val tempMap = HashMap>(binders.size) + + binders.forEach { binder -> + when (binder) { + is ArgumentBinder.Value<*> -> addArgs(binder, tempList, tempMap) + is ArgumentBinder.Function -> binder.requiredParameters.forEach { + addArgs(it, tempList, tempMap) + } } - acc } - requiredParametersMap = HashMap>().apply { - requiredParameters.forEach { - if (containsKey(it.name)) - throw IllegalArgumentException("The argument name ${it.name} is duplicated.") + requiredParameters = tempList + requiredParametersMap = tempMap + } - this[it.name] = it - } - } + private fun addArgs( + parameter: ValueParameter<*>, + tempList: ArrayList>, + tempMap: MutableMap> + ) { + if (tempMap.containsKey(parameter.name)) + throw IllegalArgumentException("The argument name ${parameter.name} is duplicated.") + tempMap[parameter.name] = parameter + tempList.add(parameter) } fun getArgumentAdaptor(): ArgumentAdaptor = ArgumentAdaptor(requiredParametersMap) From 70354b065a75ef6bd1e69a5d3d87aa0e288fd574 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 08:19:05 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88=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, 1 insertion(+), 5 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt index bd5e73e..9328543 100644 --- a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt +++ b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt @@ -49,11 +49,7 @@ class KFunctionForCall internal constructor( .filter { it.kind == KParameter.Kind.VALUE && !it.isUseDefaultArgument() } .map { it.toArgumentBinder(parameterNameConverter) } - bucketGenerator = BucketGenerator( - parameters, - binders, - instance - ) + bucketGenerator = BucketGenerator(parameters, binders, instance) val tempList = ArrayList>(binders.size) val tempMap = HashMap>(binders.size) From 421522b3e03f1c44f184536c4658c3348fa0f6f2 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 08:23:36 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E5=88=9D=E6=9C=9F=E5=8C=96=E5=91=A8?= =?UTF-8?q?=E3=82=8A=E3=82=92=E5=8A=B9=E7=8E=87=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/mapk/core/KFunctionForCall.kt | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt index 9328543..82b3fcc 100644 --- a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt +++ b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt @@ -88,16 +88,19 @@ class KFunctionForCall internal constructor( @Suppress("UNCHECKED_CAST") internal fun KClass.toKConstructor(parameterNameConverter: ParameterNameConverter): KFunctionForCall { - val factoryConstructor: List> = - this.companionObjectInstance?.let { companionObject -> - companionObject::class.functions - .filter { it.annotations.any { annotation -> annotation is KConstructor } } - .map { KFunctionForCall(it, parameterNameConverter, companionObject) as KFunctionForCall } - } ?: emptyList() - - val constructors: List> = factoryConstructor + this.constructors + 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.constructors .filter { it.annotations.any { annotation -> annotation is KConstructor } } - .map { KFunctionForCall(it, parameterNameConverter) } + .forEach { constructors.add(KFunctionForCall(it, parameterNameConverter)) } if (constructors.size == 1) return constructors.single() From 8e5f0443da3c2b1084e2560f3645458f13b6e5b7 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 08:30:03 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=A1?= =?UTF-8?q?=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=82=92=E8=AA=AD=E3=81=BF?= =?UTF-8?q?=E3=82=84=E3=81=99=E3=81=84=E3=82=88=E3=81=86=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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt index 82b3fcc..422d50f 100644 --- a/src/main/kotlin/com/mapk/core/KFunctionForCall.kt +++ b/src/main/kotlin/com/mapk/core/KFunctionForCall.kt @@ -15,6 +15,7 @@ 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 import org.jetbrains.annotations.TestOnly class KFunctionForCall internal constructor( @@ -106,7 +107,7 @@ internal fun KClass.toKConstructor(parameterNameConverter: Paramete if (constructors.isEmpty()) return KFunctionForCall(this.primaryConstructor!!, parameterNameConverter) - throw IllegalArgumentException("Find multiple target.") + throw IllegalArgumentException("${this.jvmName} has multiple ${KConstructor::class.jvmName}.") } @Suppress("UNCHECKED_CAST") From f7c98fffbd9bf640b588bd40c3410aa56de0b8c4 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 16:56:09 +0900 Subject: [PATCH 5/5] =?UTF-8?q?IDE=E5=91=A8=E3=82=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/Shared.iml | 2 ++ .idea/misc.xml | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 .idea/Shared.iml diff --git a/.idea/Shared.iml b/.idea/Shared.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/.idea/Shared.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 38167d7..38b4a97 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,9 @@ + +