@@ -16,21 +16,21 @@ sealed class SingleArgFastKFunction<T> {
16
16
internal class Constructor <T >(
17
17
override val valueParameter : KParameter ,
18
18
private val constructor : JavaConstructor <T >
19
- ): SingleArgFastKFunction<T>() {
19
+ ) : SingleArgFastKFunction<T>() {
20
20
override fun call (arg : Any? ): T = constructor .newInstance(arg)
21
21
}
22
22
23
23
internal class Function <T >(
24
24
override val valueParameter : KParameter ,
25
25
private val function : KFunction <T >
26
- ): SingleArgFastKFunction<T>() {
26
+ ) : SingleArgFastKFunction<T>() {
27
27
override fun call (arg : Any? ): T = function.call(arg)
28
28
}
29
29
30
30
internal class TopLevelFunction <T >(
31
31
override val valueParameter : KParameter ,
32
32
private val method : Method
33
- ): SingleArgFastKFunction<T>() {
33
+ ) : SingleArgFastKFunction<T>() {
34
34
@Suppress(" UNCHECKED_CAST" )
35
35
override fun call (arg : Any? ): T = method.invoke(null , arg) as T
36
36
}
@@ -39,7 +39,7 @@ sealed class SingleArgFastKFunction<T> {
39
39
override val valueParameter : KParameter ,
40
40
private val method : Method ,
41
41
private val extensionReceiver : Any
42
- ): SingleArgFastKFunction<T>() {
42
+ ) : SingleArgFastKFunction<T>() {
43
43
@Suppress(" UNCHECKED_CAST" )
44
44
override fun call (arg : Any? ): T = method.invoke(null , extensionReceiver, arg) as T
45
45
}
@@ -48,7 +48,7 @@ sealed class SingleArgFastKFunction<T> {
48
48
override val valueParameter : KParameter ,
49
49
private val method : Method ,
50
50
private val instance : Any
51
- ): SingleArgFastKFunction<T>() {
51
+ ) : SingleArgFastKFunction<T>() {
52
52
@Suppress(" UNCHECKED_CAST" )
53
53
override fun call (arg : Any? ): T = method.invoke(instance, arg) as T
54
54
}
@@ -81,9 +81,10 @@ sealed class SingleArgFastKFunction<T> {
81
81
}
82
82
// javaMethodのパラメータサイズとKFunctionのパラメータサイズが違う場合も拡張関数
83
83
// インスタンスが設定されていれば高速呼び出し、そうじゃなければ通常の関数呼び出し
84
- method.parameters.size != parameters.size -> instance
85
- ?.let { TopLevelExtensionFunction (parameters[0 ], method, instance) }
86
- ? : Function (parameters[0 ], function)
84
+ method.parameters.size != parameters.size ->
85
+ instance
86
+ ?.let { TopLevelExtensionFunction (parameters[0 ], method, instance) }
87
+ ? : Function (parameters[0 ], function)
87
88
// トップレベル関数
88
89
else -> TopLevelFunction (parameters[0 ], method)
89
90
}
@@ -97,9 +98,10 @@ sealed class SingleArgFastKFunction<T> {
97
98
val instance = inputtedInstance ? : method.declaringObject
98
99
99
100
return when {
100
- parameters[0 ].kind == KParameter .Kind .INSTANCE -> instance
101
- ?.let { InstanceFunction (parameters[1 ], method, it) }
102
- ? : throw IllegalArgumentException (" Function requires INSTANCE parameter, but is not present." )
101
+ parameters[0 ].kind == KParameter .Kind .INSTANCE ->
102
+ instance
103
+ ?.let { InstanceFunction (parameters[1 ], method, it) }
104
+ ? : throw IllegalArgumentException (" Function requires INSTANCE parameter, but is not present." )
103
105
instance != null -> InstanceFunction (parameters[0 ], method, instance)
104
106
else -> Function (parameters[0 ], function)
105
107
}
0 commit comments