Reflection: add KVisibility, KClass.visibility, KCallable.visibility
This commit is contained in:
@@ -63,6 +63,9 @@ internal interface KCallableImpl<out R> : KCallable<R>, KAnnotatedElementImpl {
|
||||
override val typeParameters: List<KTypeParameter>
|
||||
get() = descriptor.typeParameters.map(::KTypeParameterImpl)
|
||||
|
||||
override val visibility: KVisibility?
|
||||
get() = descriptor.visibility.toKVisibility()
|
||||
|
||||
override val isFinal: Boolean
|
||||
get() = descriptor.modality == Modality.FINAL
|
||||
|
||||
|
||||
@@ -170,6 +170,9 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) :
|
||||
}
|
||||
}
|
||||
|
||||
override val visibility: KVisibility?
|
||||
get() = descriptor.visibility.toKVisibility()
|
||||
|
||||
override val isFinal: Boolean
|
||||
get() = descriptor.modality == Modality.FINAL
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package kotlin.reflect.jvm.internal
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.load.java.components.RuntimeSourceElementFactory
|
||||
import org.jetbrains.kotlin.load.java.reflect.tryLoadClass
|
||||
import org.jetbrains.kotlin.load.java.structure.reflect.ReflectJavaClass
|
||||
@@ -30,6 +32,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
import kotlin.jvm.internal.FunctionReference
|
||||
import kotlin.jvm.internal.PropertyReference
|
||||
import kotlin.reflect.IllegalCallableAccessException
|
||||
import kotlin.reflect.KVisibility
|
||||
|
||||
internal val JVM_STATIC = FqName("kotlin.jvm.JvmStatic")
|
||||
|
||||
@@ -73,6 +76,15 @@ internal fun loadClass(classLoader: ClassLoader, packageName: String, className:
|
||||
return classLoader.tryLoadClass("$packageName.${className.replace('.', '$')}")
|
||||
}
|
||||
|
||||
internal fun Visibility.toKVisibility(): KVisibility? =
|
||||
when (this) {
|
||||
Visibilities.PUBLIC -> KVisibility.PUBLIC
|
||||
Visibilities.PROTECTED -> KVisibility.PROTECTED
|
||||
Visibilities.INTERNAL -> KVisibility.INTERNAL
|
||||
Visibilities.PRIVATE, Visibilities.PRIVATE_TO_THIS -> KVisibility.PRIVATE
|
||||
else -> null
|
||||
}
|
||||
|
||||
// TODO: wrap other exceptions
|
||||
internal inline fun <R> reflectionCall(block: () -> R): R =
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user