kotlinx.reflect.lite.impl.KPropertyImpl.kt Maven / Gradle / Ivy
/*
* Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.reflect.lite.impl
import kotlinx.reflect.lite.*
import kotlinx.reflect.lite.descriptors.*
internal abstract class KPropertyImpl(
override val descriptor: PropertyDescriptor
) : KCallableImpl(), KProperty {
override val name: String
get() = descriptor.name
override val isConst: Boolean
get() = descriptor.isConst
override val isLateInit: Boolean
get() = descriptor.isLateInit
override val isSuspend: Boolean
get() = false
abstract override val getter: KProperty.Getter
override fun equals(other: Any?): Boolean =
other is KPropertyImpl<*> && descriptor == other.descriptor
override fun hashCode(): Int = descriptor.hashCode()
abstract class Accessor : KCallableImpl(), KProperty.Accessor, KFunction {
abstract override val descriptor: PropertyAccessorDescriptor
abstract override val property: KPropertyImpl
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 isSuspend: Boolean get() = descriptor.isSuspend
override val isFinal: Boolean get() = descriptor.isFinal
override val isAbstract: Boolean get() = descriptor.isAbstract
override val isOpen: Boolean get() = descriptor.isOpen // todo check inherrited proeprties
}
abstract class Getter : Accessor(), KProperty.Getter {
override val name: String get() = ""
override val descriptor: PropertyGetterDescriptor
get() = property.descriptor.getter ?: TODO("create default property getter")
override fun toString(): String = "getter of $property"
override fun equals(other: Any?): Boolean =
other is Getter<*> && property == other.property
override fun hashCode(): Int = property.hashCode()
}
abstract class Setter : Accessor(), KMutableProperty.Setter {
override val name: String get() = ""
override val descriptor: PropertySetterDescriptor
get() = property.descriptor.setter ?: TODO("create default property setter")
override fun toString(): String = "setter of $property"
override fun equals(other: Any?): Boolean =
other is Setter<*> && property == other.property
override fun hashCode(): Int = property.hashCode()
}
}
internal open class KProperty0Impl(
override val descriptor: PropertyDescriptor
): KPropertyImpl(descriptor), KProperty0 {
override val getter: KProperty0.Getter
get() = Getter(this)
override fun get(): V = getter.call()
override fun invoke(): V = get()
class Getter(
override val property: KProperty0Impl
) : KPropertyImpl.Getter(), KProperty0.Getter {
override fun invoke(): R = property.get()
}
}
internal open class KMutableProperty0Impl(
override val descriptor: PropertyDescriptor
): KProperty0Impl(descriptor), KMutableProperty0 {
override val setter: Setter
get() = Setter(this)
override fun set(value: V) = setter.call(value)
class Setter(override val property: KMutableProperty0Impl) : KPropertyImpl.Setter(), KMutableProperty0.Setter {
override fun invoke(value: R): Unit = property.set(value)
}
}
internal open class KProperty1Impl(
override val descriptor: PropertyDescriptor
): KPropertyImpl(descriptor), KProperty1 {
override val getter: KProperty1.Getter
get() = Getter(this)
override fun get(receiver: T): V = getter.call(receiver)
override fun invoke(receiver: T): V = get(receiver)
class Getter(override val property: KProperty1Impl) :KPropertyImpl.Getter(), KProperty1.Getter {
override fun invoke(receiver: T): V = property.get(receiver)
}
}
internal open class KMutableProperty1Impl(
override val descriptor: PropertyDescriptor
): KProperty1Impl(descriptor), KMutableProperty1 {
override val setter: Setter
get() = Setter(this)
override fun set(receiver: T, value: V) = setter.call(receiver, value)
class Setter(override val property: KMutableProperty1Impl) : KPropertyImpl.Setter(), KMutableProperty1.Setter {
override fun invoke(receiver: T, value: V): Unit = property.set(receiver, value)
}
}
internal open class KProperty2Impl(
override val descriptor: PropertyDescriptor
): KPropertyImpl(descriptor), KProperty2 {
override val getter: Getter
get() = Getter(this)
override fun get(receiver1: D, receiver2: E): V = getter.call(receiver1, receiver2)
override fun invoke(receiver1: D, receiver2: E): V = get(receiver1, receiver2)
class Getter(override val property: KProperty2Impl) :KPropertyImpl.Getter(), KProperty2.Getter {
override fun invoke(receiver1: D, receiver2: E): V = property.get(receiver1, receiver2)
}
}
internal open class KMutableProperty2Impl(
override val descriptor: PropertyDescriptor
): KProperty2Impl(descriptor), KMutableProperty2 {
override val setter: Setter
get() = Setter(this)
override fun set(receiver1: D, receiver2: E, value: V) = setter.call(receiver1, receiver2, value)
class Setter(override val property: KMutableProperty2Impl) : KPropertyImpl.Setter(), KMutableProperty2.Setter {
override fun invoke(receiver1: D, receiver2: E, value: V): Unit = property.set(receiver1, receiver2, value)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy