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

Commit 95555f0

Browse files
committed
アクセシビリティ書き換えの場所を修正
1 parent fa20717 commit 95555f0

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/main/kotlin/com/wrongwrong/mapk/core/CompanionKFunction.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ package com.wrongwrong.mapk.core
33
import kotlin.reflect.KFunction
44
import kotlin.reflect.KParameter
55
import kotlin.reflect.full.instanceParameter
6+
import kotlin.reflect.jvm.isAccessible
67

78
internal 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 {

src/main/kotlin/com/wrongwrong/mapk/core/KMapper.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff 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

src/main/kotlin/com/wrongwrong/mapk/core/ParameterForMap.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)