This repository was archived by the owner on Jan 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +7
-7
lines changed
src/main/kotlin/com/wrongwrong/mapk/core Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,17 @@ package com.wrongwrong.mapk.core
33import kotlin.reflect.KFunction
44import kotlin.reflect.KParameter
55import kotlin.reflect.full.instanceParameter
6+ import kotlin.reflect.jvm.isAccessible
67
78internal class CompanionKFunction <T >(
89 private val function : KFunction <T >,
910 private val instance : Any
1011) : KFunction<T> by function {
12+ init {
13+ // このインスタンスを生成している時点でfunctionにアクセスしたい状況なので、アクセシビリティはここでセットする
14+ function.isAccessible = true
15+ }
16+
1117 private val instanceParam by lazy { mapOf (function.instanceParameter!! to instance) }
1218
1319 override val parameters: List <KParameter > by lazy {
Original file line number Diff line number Diff line change @@ -117,11 +117,7 @@ internal fun <T : Any> getTarget(clazz: KClass<T>): KFunction<T> {
117117 clazz.companionObjectInstance?.let { companionObject ->
118118 companionObject::class .functions
119119 .filter { it.annotations.any { annotation -> annotation is KConstructor } }
120- .map {
121- // isAccessibleの書き換えはKotlinの都合で先に行う必要が有る
122- it.isAccessible = true
123- CompanionKFunction (it, companionObject) as KFunction <T >
124- }
120+ .map { CompanionKFunction (it, companionObject) as KFunction <T > }
125121 } ? : emptyList()
126122
127123 val constructors: List <KFunction <T >> = factoryConstructor + clazz.constructors
Original file line number Diff line number Diff line change @@ -66,8 +66,6 @@ private fun <T : Any> creatorsFromCompanionObject(clazz: KClass<T>): Set<Pair<KC
6666 companionObject::class .functions
6767 .filter { it.annotations.any { annotation -> annotation is KConverter } }
6868 .map { function ->
69- // isAccessibleの書き換えはKotlinの都合で先に行う必要が有る
70- function.isAccessible = true
7169 val func: KFunction <T > = CompanionKFunction (function, companionObject) as KFunction <T >
7270
7371 (func.parameters.single().type.classifier as KClass <* >) to func
You can’t perform that action at this time.
0 commit comments