Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit d4b5f8b

Browse files
committed
バリデーションを追加
1 parent b641874 commit d4b5f8b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/main/kotlin/com/mapk/fastkfunction/FastKFunction.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ class FastKFunction<T>(private val function: KFunction<T>, instance: Any?) {
1717
private val bucketGenerator: BucketGenerator
1818

1919
init {
20+
// 引数を要求しないか、複数のインスタンスを求める場合エラーとする
2021
val parameters: List<KParameter> = function.parameters.apply {
2122
if (isEmpty() || (instance != null && size == 1))
2223
throw IllegalArgumentException("This function is not require arguments.")
24+
25+
if (3 <= size && get(0).kind != KParameter.Kind.VALUE && get(1).kind != KParameter.Kind.VALUE)
26+
throw IllegalArgumentException("This function is require multiple instances.")
2327
}
2428

2529
// この関数には確実にアクセスするためアクセシビリティ書き換え
@@ -39,7 +43,6 @@ class FastKFunction<T>(private val function: KFunction<T>, instance: Any?) {
3943
@Suppress("UNCHECKED_CAST") // methodはTを返せないため強制キャスト
4044
when (parameters[0].kind) {
4145
KParameter.Kind.EXTENSION_RECEIVER -> {
42-
// TODO: インスタンスに定義した拡張関数 = インスタンスとレシーバ両方が要求される場合throw
4346
// 対象が拡張関数なら、instanceはreceiver
4447
bucketGenerator = BucketGenerator(parameters, instance)
4548
fullInitializedFunction = { method.invoke(null, instance, *it) as T }

0 commit comments

Comments
 (0)