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> {
129
129
}
130
130
131
131
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 ))
134
136
throw IllegalArgumentException (" This function is not require arguments." )
135
137
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 )
137
139
throw IllegalArgumentException (" This function is require multiple instances." )
138
140
}
139
141
@@ -191,7 +193,7 @@ sealed class FastKFunction<T> {
191
193
192
194
fun <T > of (function : KFunction <T >, instance : Any? = null): FastKFunction <T > {
193
195
// 引数を要求しないか、複数のインスタンスを求める場合エラーとする
194
- val parameters: List <KParameter > = function.parameters.checkParameters(instance )
196
+ val parameters: List <KParameter > = function.parameters.checkParameters()
195
197
196
198
// この関数には確実にアクセスするためアクセシビリティ書き換え
197
199
function.isAccessible = true
Original file line number Diff line number Diff line change @@ -54,11 +54,13 @@ sealed class SingleArgFastKFunction<T> {
54
54
}
55
55
56
56
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 ))
59
61
throw IllegalArgumentException (" This function is not require arguments." )
60
62
61
- if (! (this .size == 1 || (this .size == 2 && instance != null )))
63
+ if (! (this .size == 1 || (this .size == 2 && requireInstanceParameter )))
62
64
throw IllegalArgumentException (" This function is require multiple arguments." )
63
65
}
64
66
@@ -105,7 +107,7 @@ sealed class SingleArgFastKFunction<T> {
105
107
106
108
fun <T > of (function : KFunction <T >, instance : Any? = null): SingleArgFastKFunction <T > {
107
109
// 引数を要求しないか、複数のインスタンスを求める場合エラーとする
108
- val parameters: List <KParameter > = function.parameters.checkParameters(instance )
110
+ val parameters: List <KParameter > = function.parameters.checkParameters()
109
111
110
112
// この関数には確実にアクセスするためアクセシビリティ書き換え
111
113
function.isAccessible = true
You can’t perform that action at this time.
0 commit comments