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

Commit e07ed13

Browse files
committed
完全初期化時の呼び出しのラッパーを追加
1 parent 2658ac4 commit e07ed13

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.mapk.core.internal
2+
3+
import kotlin.reflect.KFunction
4+
import kotlin.reflect.jvm.javaConstructor
5+
import kotlin.reflect.jvm.javaMethod
6+
7+
internal class FullInitializedFunctionWrapper<T>(function: KFunction<T>, instance: Any?, paramSize: Int) {
8+
private val lambda: (Array<Any?>) -> T
9+
10+
init {
11+
val constructor = function.javaConstructor
12+
13+
lambda = when {
14+
constructor != null -> {
15+
{ constructor.newInstance(*it) }
16+
}
17+
instance != null -> {
18+
val method = function.javaMethod!!
19+
20+
@Suppress("UNCHECKED_CAST") { method.invoke(it[0], *(it.copyOfRange(1, paramSize))) as T }
21+
}
22+
else -> {
23+
{ function.call(*it) }
24+
}
25+
}
26+
}
27+
28+
fun call(args: Array<Any?>): T = lambda(args)
29+
}

0 commit comments

Comments
 (0)