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

Commit cf7f5bb

Browse files
committed
インスタンスパラメータのバリデーション用共通関数を追加
1 parent 6fe1779 commit cf7f5bb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.mapk.fastkfunction
33
import java.lang.reflect.Method
44
import kotlin.reflect.KClass
55
import kotlin.reflect.KParameter
6+
import kotlin.reflect.full.isSuperclassOf
67

78
/**
89
* Get object instance if receiver declared in object.
@@ -21,6 +22,20 @@ internal val Method.declaringObject: Any? get() = declaringClass.kotlin.objectIn
2122
*/
2223
internal val KParameter.clazz: KClass<*> get() = this.type.classifier as KClass<*>
2324

25+
/**
26+
* Check instance class is valid.
27+
*
28+
* @param expected Required clazz.
29+
* @param actual Actual clazz.
30+
* @throws IllegalArgumentException If actual is not required class.
31+
*/
32+
internal fun checkInstanceClass(expected: KClass<*>, actual: KClass<*>) {
33+
if (!expected.isSuperclassOf(actual))
34+
throw IllegalArgumentException(
35+
"INSTANCE parameter required ${expected.simpleName}, but ${actual.simpleName} is present."
36+
)
37+
}
38+
2439
/**
2540
* Throw IllegalArgumentException if instance is null.
2641
*

0 commit comments

Comments
 (0)