Reflection: add API for declaration modifiers
#KT-10447 Fixed
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package kotlin.reflect.jvm.internal
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import java.lang.reflect.Type
|
||||
import java.util.*
|
||||
@@ -62,6 +63,15 @@ internal interface KCallableImpl<out R> : KCallable<R>, KAnnotatedElementImpl {
|
||||
override val typeParameters: List<KTypeParameter>
|
||||
get() = descriptor.typeParameters.map(::KTypeParameterImpl)
|
||||
|
||||
override val isFinal: Boolean
|
||||
get() = descriptor.modality == Modality.FINAL
|
||||
|
||||
override val isOpen: Boolean
|
||||
get() = descriptor.modality == Modality.OPEN
|
||||
|
||||
override val isAbstract: Boolean
|
||||
get() = descriptor.modality == Modality.ABSTRACT
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun call(vararg args: Any?): R = reflectionCall {
|
||||
return caller.call(args) as R
|
||||
|
||||
@@ -170,6 +170,27 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) :
|
||||
}
|
||||
}
|
||||
|
||||
override val isFinal: Boolean
|
||||
get() = descriptor.modality == Modality.FINAL
|
||||
|
||||
override val isOpen: Boolean
|
||||
get() = descriptor.modality == Modality.OPEN
|
||||
|
||||
override val isAbstract: Boolean
|
||||
get() = descriptor.modality == Modality.ABSTRACT
|
||||
|
||||
override val isSealed: Boolean
|
||||
get() = descriptor.modality == Modality.SEALED
|
||||
|
||||
override val isData: Boolean
|
||||
get() = descriptor.isData
|
||||
|
||||
override val isInner: Boolean
|
||||
get() = descriptor.isInner
|
||||
|
||||
override val isCompanion: Boolean
|
||||
get() = descriptor.isCompanionObject
|
||||
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is KClassImpl<*> && jClass == other.jClass
|
||||
|
||||
|
||||
@@ -109,6 +109,24 @@ internal open class KFunctionImpl protected constructor(
|
||||
(if (descriptor.extensionReceiverParameter != null) 1 else 0)
|
||||
}
|
||||
|
||||
override val isInline: Boolean
|
||||
get() = descriptor.isInline
|
||||
|
||||
override val isExternal: Boolean
|
||||
get() = descriptor.isExternal
|
||||
|
||||
override val isOperator: Boolean
|
||||
get() = descriptor.isOperator
|
||||
|
||||
override val isInfix: Boolean
|
||||
get() = descriptor.isInfix
|
||||
|
||||
override val isTailrec: Boolean
|
||||
get() = descriptor.isTailrec
|
||||
|
||||
override val isSuspend: Boolean
|
||||
get() = descriptor.isSuspend
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
val that = other.asKFunctionImpl() ?: return false
|
||||
return container == that.container && name == that.name && signature == that.signature
|
||||
|
||||
@@ -46,6 +46,18 @@ internal class KParameterImpl(
|
||||
override val isOptional: Boolean
|
||||
get() = (descriptor as? ValueParameterDescriptor)?.hasDefaultValue() ?: false
|
||||
|
||||
override val isVararg: Boolean
|
||||
get() = descriptor.let { it is ValueParameterDescriptor && it.varargElementType != null }
|
||||
|
||||
override val isNoinline: Boolean
|
||||
get() = descriptor.let { it is ValueParameterDescriptor && it.isNoinline }
|
||||
|
||||
override val isCrossinline: Boolean
|
||||
get() = descriptor.let { it is ValueParameterDescriptor && it.isCrossinline }
|
||||
|
||||
override val isCoroutine: Boolean
|
||||
get() = descriptor.let { it is ValueParameterDescriptor && it.isCoroutine }
|
||||
|
||||
override fun equals(other: Any?) =
|
||||
other is KParameterImpl && callable == other.callable && descriptor == other.descriptor
|
||||
|
||||
|
||||
@@ -42,10 +42,40 @@ internal interface KPropertyImpl<out R> : KProperty<R>, KCallableImpl<R> {
|
||||
|
||||
override val defaultCaller: FunctionCaller<*>? get() = getter.defaultCaller
|
||||
|
||||
override val isLateinit: Boolean
|
||||
get() = descriptor.isLateInit
|
||||
|
||||
override val isConst: Boolean
|
||||
get() = descriptor.isConst
|
||||
|
||||
abstract class Accessor<out R> : KProperty.Accessor<R> {
|
||||
abstract override val property: KPropertyImpl<R>
|
||||
|
||||
internal abstract val descriptor: PropertyAccessorDescriptor
|
||||
|
||||
@Suppress("unused") // Used as an implementation of KFunction#isInline in subclasses
|
||||
val isInline: Boolean
|
||||
get() = descriptor.isInline
|
||||
|
||||
@Suppress("unused")
|
||||
val isExternal: Boolean
|
||||
get() = descriptor.isExternal
|
||||
|
||||
@Suppress("unused")
|
||||
val isOperator: Boolean
|
||||
get() = descriptor.isOperator
|
||||
|
||||
@Suppress("unused")
|
||||
val isInfix: Boolean
|
||||
get() = descriptor.isInfix
|
||||
|
||||
@Suppress("unused")
|
||||
val isTailrec: Boolean
|
||||
get() = descriptor.isTailrec
|
||||
|
||||
@Suppress("unused")
|
||||
val isSuspend: Boolean
|
||||
get() = descriptor.isSuspend
|
||||
}
|
||||
|
||||
abstract class Getter<out R> : Accessor<R>(), KProperty.Getter<R>, KCallableImpl<R> {
|
||||
|
||||
@@ -40,6 +40,9 @@ internal class KTypeParameterImpl(override val descriptor: TypeParameterDescript
|
||||
Variance.OUT_VARIANCE -> KVariance.OUT
|
||||
}
|
||||
|
||||
override val isReified: Boolean
|
||||
get() = descriptor.isReified
|
||||
|
||||
override fun equals(other: Any?) =
|
||||
other is KTypeParameterImpl && descriptor == other.descriptor
|
||||
|
||||
|
||||
Reference in New Issue
Block a user