KProperty and ReadOnlyProperty type parameter names #KT-16529

This commit is contained in:
Abduqodiri Qurbonzoda
2020-02-17 15:40:57 +03:00
parent 5ed28b38be
commit fe50bb4b93
13 changed files with 127 additions and 127 deletions
@@ -13,17 +13,17 @@ import kotlin.reflect.KProperty
* This is provided only for convenience; you don't have to extend this interface
* as long as your property delegate has methods with the same signatures.
*
* @param R the type of object which owns the delegated property.
* @param T the type of the property value.
* @param T the type of object which owns the delegated property.
* @param V the type of the property value.
*/
public interface ReadOnlyProperty<in R, out T> {
public 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.
* @param property the metadata for the property.
* @return the property value.
*/
public operator fun getValue(thisRef: R, property: KProperty<*>): T
public operator fun getValue(thisRef: T, property: KProperty<*>): V
}
/**
@@ -32,17 +32,17 @@ public interface ReadOnlyProperty<in R, out T> {
* This is provided only for convenience; you don't have to extend this interface
* as long as your property delegate has methods with the same signatures.
*
* @param R the type of object which owns the delegated property.
* @param T the type of the property value.
* @param T the type of object which owns the delegated property.
* @param V the type of the property value.
*/
public interface ReadWriteProperty<in R, T> {
public interface ReadWriteProperty<in T, V> {
/**
* Returns the value of the property for the given object.
* @param thisRef the object for which the value is requested.
* @param property the metadata for the property.
* @return the property value.
*/
public operator fun getValue(thisRef: R, property: KProperty<*>): T
public operator fun getValue(thisRef: T, property: KProperty<*>): V
/**
* Sets the value of the property for the given object.
@@ -50,7 +50,7 @@ public interface ReadWriteProperty<in R, T> {
* @param property the metadata for the property.
* @param value the value to set.
*/
public operator fun setValue(thisRef: R, property: KProperty<*>, value: T)
public operator fun setValue(thisRef: T, property: KProperty<*>, value: V)
}
/**
@@ -11,7 +11,7 @@ import kotlin.reflect.KProperty
* Implements the core logic of a property delegate for a read/write property that calls callback functions when changed.
* @param initialValue the initial value of the property.
*/
public abstract class ObservableProperty<T>(initialValue: T) : ReadWriteProperty<Any?, T> {
public abstract class ObservableProperty<V>(initialValue: V) : ReadWriteProperty<Any?, V> {
private var value = initialValue
/**
@@ -20,19 +20,19 @@ public abstract class ObservableProperty<T>(initialValue: T) : ReadWriteProperty
* If the callback returns `true` the value of the property is being set to the new value,
* and if the callback returns `false` the new value is discarded and the property remains its old value.
*/
protected open fun beforeChange(property: KProperty<*>, oldValue: T, newValue: T): Boolean = true
protected open fun beforeChange(property: KProperty<*>, oldValue: V, newValue: V): Boolean = true
/**
* The callback which is called after the change of the property is made. The value of the property
* has already been changed when this callback is invoked.
*/
protected open fun afterChange(property: KProperty<*>, oldValue: T, newValue: T): Unit {}
protected open fun afterChange(property: KProperty<*>, oldValue: V, newValue: V): Unit {}
public override fun getValue(thisRef: Any?, property: KProperty<*>): T {
public override fun getValue(thisRef: Any?, property: KProperty<*>): V {
return value
}
public override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
public override fun setValue(thisRef: Any?, property: KProperty<*>, value: V) {
val oldValue = this.value
if (!beforeChange(property, oldValue, value)) {
return
@@ -13,15 +13,15 @@ package kotlin.reflect
* See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/reflection.html)
* for more information.
*
* @param R the type of the property.
* @param V the type of the property value.
*/
public expect interface KProperty<out R> : KCallable<R> {
public expect interface KProperty<out V> : KCallable<V> {
}
/**
* Represents a property declared as a `var`.
*/
public expect interface KMutableProperty<R> : KProperty<R> {
public expect interface KMutableProperty<V> : KProperty<V> {
}
@@ -30,23 +30,23 @@ public expect interface KMutableProperty<R> : KProperty<R> {
* Such property is either originally declared in a receiverless context such as a package,
* or has the receiver bound to it.
*/
public expect interface KProperty0<out R> : KProperty<R>, () -> R {
public expect interface KProperty0<out V> : KProperty<V>, () -> V {
/**
* Returns the current value of the property.
*/
public fun get(): R
public fun get(): V
}
/**
* Represents a `var`-property without any kind of receiver.
*/
public expect interface KMutableProperty0<R> : KProperty0<R>, KMutableProperty<R> {
public expect interface KMutableProperty0<V> : KProperty0<V>, KMutableProperty<V> {
/**
* Modifies the value of the property.
*
* @param value the new value to be assigned to this property.
*/
public fun set(value: R)
public fun set(value: V)
}
@@ -54,9 +54,9 @@ public expect interface KMutableProperty0<R> : KProperty0<R>, KMutableProperty<R
* Represents a property, operations on which take one receiver as a parameter.
*
* @param T the type of the receiver which should be used to obtain the value of the property.
* @param R the type of the property.
* @param V the type of the property value.
*/
public expect interface KProperty1<T, out R> : KProperty<R>, (T) -> R {
public expect interface KProperty1<T, out V> : KProperty<V>, (T) -> V {
/**
* Returns the current value of the property.
*
@@ -64,13 +64,13 @@ public expect interface KProperty1<T, out R> : KProperty<R>, (T) -> R {
* For example, it should be a class instance if this is a member property of that class,
* or an extension receiver if this is a top level extension property.
*/
public fun get(receiver: T): R
public fun get(receiver: T): V
}
/**
* Represents a `var`-property, operations on which take one receiver as a parameter.
*/
public expect interface KMutableProperty1<T, R> : KProperty1<T, R>, KMutableProperty<R> {
public expect interface KMutableProperty1<T, V> : KProperty1<T, V>, KMutableProperty<V> {
/**
* Modifies the value of the property.
*
@@ -79,7 +79,7 @@ public expect interface KMutableProperty1<T, R> : KProperty1<T, R>, KMutableProp
* or an extension receiver if this is a top level extension property.
* @param value the new value to be assigned to this property.
*/
public fun set(receiver: T, value: R)
public fun set(receiver: T, value: V)
}
@@ -91,9 +91,9 @@ public expect interface KMutableProperty1<T, R> : KProperty1<T, R>, KMutableProp
* the type of the declaring class of the property, or any subclass of that class.
* @param E the type of the second receiver. In case of the extension property in a class this is
* the type of the extension receiver.
* @param R the type of the property.
* @param V the type of the property value.
*/
public expect interface KProperty2<D, E, out R> : KProperty<R>, (D, E) -> R {
public expect interface KProperty2<D, E, out V> : KProperty<V>, (D, E) -> V {
/**
* Returns the current value of the property. In case of the extension property in a class,
* the instance of the class should be passed first and the instance of the extension receiver second.
@@ -101,13 +101,13 @@ public expect interface KProperty2<D, E, out R> : KProperty<R>, (D, E) -> R {
* @param receiver1 the instance of the first receiver.
* @param receiver2 the instance of the second receiver.
*/
public fun get(receiver1: D, receiver2: E): R
public fun get(receiver1: D, receiver2: E): V
}
/**
* Represents a `var`-property, operations on which take two receivers as parameters.
*/
public expect interface KMutableProperty2<D, E, R> : KProperty2<D, E, R>, KMutableProperty<R> {
public expect interface KMutableProperty2<D, E, V> : KProperty2<D, E, V>, KMutableProperty<V> {
/**
* Modifies the value of the property.
*
@@ -115,5 +115,5 @@ public expect interface KMutableProperty2<D, E, R> : KProperty2<D, E, R>, KMutab
* @param receiver2 the instance of the second receiver.
* @param value the new value to be assigned to this property.
*/
public fun set(receiver1: D, receiver2: E, value: R)
public fun set(receiver1: D, receiver2: E, value: V)
}