This repository was archived by the owner on Jan 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed
src/main/kotlin/com/mapk/fastkfunction Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -129,11 +129,13 @@ sealed class FastKFunction<T> {
129129 }
130130
131131 companion object {
132- private fun List<KParameter>.checkParameters (instance : Any? ) = also {
133- if (isEmpty() || (instance != null && size == 1 ))
132+ private fun List<KParameter>.checkParameters () = also {
133+ val requireInstanceParameter = this [0 ].kind != KParameter .Kind .VALUE
134+
135+ if (isEmpty() || (requireInstanceParameter && size == 1 ))
134136 throw IllegalArgumentException (" This function is not require arguments." )
135137
136- if (3 <= size && get( 0 ).kind != KParameter . Kind . VALUE && get(1 ).kind != KParameter .Kind .VALUE )
138+ if (3 <= size && requireInstanceParameter && get(1 ).kind != KParameter .Kind .VALUE )
137139 throw IllegalArgumentException (" This function is require multiple instances." )
138140 }
139141
@@ -191,7 +193,7 @@ sealed class FastKFunction<T> {
191193
192194 fun <T > of (function : KFunction <T >, instance : Any? = null): FastKFunction <T > {
193195 // 引数を要求しないか、複数のインスタンスを求める場合エラーとする
194- val parameters: List <KParameter > = function.parameters.checkParameters(instance )
196+ val parameters: List <KParameter > = function.parameters.checkParameters()
195197
196198 // この関数には確実にアクセスするためアクセシビリティ書き換え
197199 function.isAccessible = true
Original file line number Diff line number Diff line change @@ -54,11 +54,13 @@ sealed class SingleArgFastKFunction<T> {
5454 }
5555
5656 companion object {
57- private fun List<KParameter>.checkParameters (instance : Any? ) = also {
58- if (isEmpty() || (instance != null && size == 1 ))
57+ private fun List<KParameter>.checkParameters () = also {
58+ val requireInstanceParameter = this [0 ].kind != KParameter .Kind .VALUE
59+
60+ if (isEmpty() || (requireInstanceParameter && size == 1 ))
5961 throw IllegalArgumentException (" This function is not require arguments." )
6062
61- if (! (this .size == 1 || (this .size == 2 && instance != null )))
63+ if (! (this .size == 1 || (this .size == 2 && requireInstanceParameter )))
6264 throw IllegalArgumentException (" This function is require multiple arguments." )
6365 }
6466
@@ -105,7 +107,7 @@ sealed class SingleArgFastKFunction<T> {
105107
106108 fun <T > of (function : KFunction <T >, instance : Any? = null): SingleArgFastKFunction <T > {
107109 // 引数を要求しないか、複数のインスタンスを求める場合エラーとする
108- val parameters: List <KParameter > = function.parameters.checkParameters(instance )
110+ val parameters: List <KParameter > = function.parameters.checkParameters()
109111
110112 // この関数には確実にアクセスするためアクセシビリティ書き換え
111113 function.isAccessible = true
You can’t perform that action at this time.
0 commit comments