Make ReadOnlyProperty and PropertyDelegateProvider fun interfaces
This commit is contained in:
@@ -19,11 +19,11 @@ public abstract class ObservableProperty<V> : kotlin.properties.ReadWritePropert
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.4")
|
||||
public interface PropertyDelegateProvider<in T, out D> {
|
||||
public fun interface PropertyDelegateProvider<in T, out D> {
|
||||
public abstract operator fun provideDelegate(thisRef: T, property: kotlin.reflect.KProperty<*>): D
|
||||
}
|
||||
|
||||
public interface ReadOnlyProperty<in T, out V> {
|
||||
public fun interface ReadOnlyProperty<in T, out V> {
|
||||
public abstract operator fun getValue(thisRef: T, property: kotlin.reflect.KProperty<*>): V
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ public abstract class ObservableProperty<V> : kotlin.properties.ReadWritePropert
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.4")
|
||||
public interface PropertyDelegateProvider<in T, out D> {
|
||||
public fun interface PropertyDelegateProvider<in T, out D> {
|
||||
public abstract operator fun provideDelegate(thisRef: T, property: kotlin.reflect.KProperty<*>): D
|
||||
}
|
||||
|
||||
public interface ReadOnlyProperty<in T, out V> {
|
||||
public fun interface ReadOnlyProperty<in T, out V> {
|
||||
public abstract operator fun getValue(thisRef: T, property: kotlin.reflect.KProperty<*>): V
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,7 @@ import kotlin.reflect.KProperty
|
||||
* @param T the type of object which owns the delegated property.
|
||||
* @param V the type of the property value.
|
||||
*/
|
||||
public interface ReadOnlyProperty<in T, out V> {
|
||||
public fun interface ReadOnlyProperty<in T, out V> {
|
||||
/**
|
||||
* Returns the value of the property for the given object.
|
||||
* @param thisRef the object for which the value is requested.
|
||||
@@ -63,7 +63,7 @@ public interface ReadWriteProperty<in T, V> : ReadOnlyProperty<T, V> {
|
||||
* @param D the type of property delegates this provider provides.
|
||||
*/
|
||||
@SinceKotlin("1.4")
|
||||
public interface PropertyDelegateProvider<in T, out D> {
|
||||
public fun interface PropertyDelegateProvider<in T, out D> {
|
||||
/**
|
||||
* Returns the delegate of the property for the given object.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -64,3 +64,27 @@ class VetoablePropertyTest {
|
||||
assertFalse(result, "fail4: result should be false")
|
||||
}
|
||||
}
|
||||
|
||||
private typealias ReadOnlyPropertyDelegateProvider<T, V> =
|
||||
PropertyDelegateProvider<T, ReadOnlyProperty<T, V>>
|
||||
|
||||
class DelegationInterfacesTest {
|
||||
val a by ReadOnlyProperty { _, property -> property.name }
|
||||
|
||||
private val delegatedToProvider = mutableListOf<String>()
|
||||
private val provider = ReadOnlyPropertyDelegateProvider { thisRef: DelegationInterfacesTest, property ->
|
||||
val index = thisRef.delegatedToProvider.size
|
||||
thisRef.delegatedToProvider.add(property.name)
|
||||
ReadOnlyProperty { _, prop -> "${prop.name} is numbered $index" }
|
||||
}
|
||||
|
||||
val b by provider
|
||||
val c by provider
|
||||
|
||||
@Test fun doTest() {
|
||||
assertEquals("a", a)
|
||||
assertEquals(listOf("b", "c"), delegatedToProvider)
|
||||
assertEquals("b is numbered 0", b)
|
||||
assertEquals("c is numbered 1", c)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user