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

Commit f129f62

Browse files
committed
instanceパラメータバリデーション時の「Nullならthrow」の共通化用関数を定義
1 parent 8d4eeef commit f129f62

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mapk.fastkfunction
22

33
import java.lang.reflect.Method
4+
import kotlin.reflect.KParameter
45

56
/**
67
* Get object instance if receiver declared in object.
@@ -10,3 +11,14 @@ import java.lang.reflect.Method
1011
* @throws UnsupportedOperationException Method declared on top level.
1112
*/
1213
internal val Method.declaringObject: Any? get() = declaringClass.kotlin.objectInstance
14+
15+
/**
16+
* Throw IllegalArgumentException if instance is null.
17+
*
18+
* @receiver Instance parameter.
19+
* @param kind Instance Kind.
20+
* @return instance.
21+
* @throws IllegalArgumentException Instance is null.
22+
*/
23+
internal fun <T : Any> T?.instanceOrThrow(kind: KParameter.Kind): T =
24+
this ?: throw IllegalArgumentException("Function requires ${kind.name} parameter, but is not present.")

0 commit comments

Comments
 (0)