kotlin.reflect.jvm.internal.KProperty1Impl.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-reflect Show documentation
Show all versions of kotlin-reflect Show documentation
Kotlin Full Reflection Library
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlin.reflect.jvm.internal
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import kotlin.LazyThreadSafetyMode.PUBLICATION
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KProperty1
internal open class KProperty1Impl : KProperty1, KPropertyImpl {
constructor(container: KDeclarationContainerImpl, name: String, signature: String, boundReceiver: Any?) : super(
container, name, signature, boundReceiver
)
constructor(container: KDeclarationContainerImpl, descriptor: PropertyDescriptor) : super(container, descriptor)
private val _getter = lazy(PUBLICATION) { Getter(this) }
override val getter: Getter get() = _getter.value
override fun get(receiver: T): V = getter.call(receiver)
private val delegateSource = lazy(PUBLICATION) { computeDelegateSource() }
override fun getDelegate(receiver: T): Any? = getDelegateImpl(delegateSource.value, receiver, null)
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 class KMutableProperty1Impl : KProperty1Impl, KMutableProperty1 {
constructor(container: KDeclarationContainerImpl, name: String, signature: String, boundReceiver: Any?) : super(
container, name, signature, boundReceiver
)
constructor(container: KDeclarationContainerImpl, descriptor: PropertyDescriptor) : super(container, descriptor)
private val _setter = lazy(PUBLICATION) { Setter(this) }
override val setter: Setter get() = _setter.value
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)
}
}