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

Commit ece9081

Browse files
committed
KFunctionのスプレッド処理をラップ
1 parent d85fc72 commit ece9081

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.mapk.fastkfunction.spreadwrapper;
2+
3+
import kotlin.reflect.KFunction;
4+
import org.jetbrains.annotations.NotNull;
5+
6+
public class ForKFunction<T> {
7+
private final KFunction<T> kFunction;
8+
9+
public ForKFunction(@NotNull KFunction<T> kFunction) {
10+
this.kFunction = kFunction;
11+
}
12+
13+
public T call(Object[] args) {
14+
return kFunction.call(args);
15+
}
16+
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.mapk.fastkfunction
33
import com.mapk.fastkfunction.argumentbucket.ArgumentBucket
44
import com.mapk.fastkfunction.argumentbucket.BucketGenerator
55
import com.mapk.fastkfunction.spreadwrapper.ForConstructor
6+
import com.mapk.fastkfunction.spreadwrapper.ForKFunction
67
import java.lang.reflect.Method
78
import java.lang.reflect.Modifier
89
import kotlin.reflect.KFunction
@@ -44,17 +45,18 @@ sealed class FastKFunction<T> {
4445
private val function: KFunction<T>,
4546
override val valueParameters: List<KParameter>
4647
) : FastKFunction<T>() {
48+
private val spreadWrapper = ForKFunction(function)
4749
override val bucketGenerator = BucketGenerator(valueParameters, null)
4850

4951
override fun callBy(bucket: ArgumentBucket): T = if (bucket.isFullInitialized()) {
50-
function.call(*bucket.getValueArray())
52+
spreadWrapper.call(bucket.getValueArray())
5153
} else {
5254
function.callBy(bucket)
5355
}
5456

55-
override fun callByCollection(args: Collection<Any?>): T = function.call(*args.toTypedArray())
57+
override fun callByCollection(args: Collection<Any?>): T = spreadWrapper.call(args.toTypedArray())
5658

57-
override fun call(vararg args: Any?): T = function.call(*args)
59+
override fun call(vararg args: Any?): T = spreadWrapper.call(args)
5860
}
5961

6062
internal class TopLevelFunction<T>(

0 commit comments

Comments
 (0)