Add 'operator' modifier to stdlib property Delegate functions
This commit is contained in:
+1
-1
@@ -3,5 +3,5 @@ import kotlin.properties.Delegates
|
|||||||
|
|
||||||
class C {
|
class C {
|
||||||
val `x$delegate`: ReadWriteProperty<Any, Any>? = null
|
val `x$delegate`: ReadWriteProperty<Any, Any>? = null
|
||||||
val x: String? by <!OPERATOR_MODIFIER_REQUIRED!>Delegates.notNull()<!>
|
val x: String? by Delegates.notNull()
|
||||||
}
|
}
|
||||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// "Create class 'Foo'" "true"
|
// "Create class 'Foo'" "true"
|
||||||
// ERROR: <html>Class 'Foo' must be declared abstract or implement abstract member<br/><b>public</b> <b>abstract</b> <b>fun</b> getValue(thisRef: A<T>, property: kotlin.PropertyMetadata): B <i>defined in</i> kotlin.properties.ReadOnlyProperty</html>
|
// ERROR: <html>Class 'Foo' must be declared abstract or implement abstract member<br/><b>public</b> <b>abstract</b> operator <b>fun</b> getValue(thisRef: A<T>, property: kotlin.PropertyMetadata): B <i>defined in</i> kotlin.properties.ReadOnlyProperty</html>
|
||||||
|
|
||||||
open class B
|
open class B
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import kotlin.properties.ReadOnlyProperty
|
import kotlin.properties.ReadOnlyProperty
|
||||||
|
|
||||||
// "Create class 'Foo'" "true"
|
// "Create class 'Foo'" "true"
|
||||||
// ERROR: <html>Class 'Foo' must be declared abstract or implement abstract member<br/><b>public</b> <b>abstract</b> <b>fun</b> getValue(thisRef: A<T>, property: kotlin.PropertyMetadata): B <i>defined in</i> kotlin.properties.ReadOnlyProperty</html>
|
// ERROR: <html>Class 'Foo' must be declared abstract or implement abstract member<br/><b>public</b> <b>abstract</b> operator <b>fun</b> getValue(thisRef: A<T>, property: kotlin.PropertyMetadata): B <i>defined in</i> kotlin.properties.ReadOnlyProperty</html>
|
||||||
|
|
||||||
open class B
|
open class B
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -17,12 +17,12 @@
|
|||||||
package com.google.dart.compiler.backend.js.ast.metadata
|
package com.google.dart.compiler.backend.js.ast.metadata
|
||||||
|
|
||||||
internal class MetadataProperty<in T : HasMetadata, R>(val default: R) {
|
internal class MetadataProperty<in T : HasMetadata, R>(val default: R) {
|
||||||
fun getValue(thisRef: T, desc: PropertyMetadata): R {
|
operator fun getValue(thisRef: T, desc: PropertyMetadata): R {
|
||||||
if (!thisRef.hasData(desc.name)) return default
|
if (!thisRef.hasData(desc.name)) return default
|
||||||
return thisRef.getData<R>(desc.name)
|
return thisRef.getData<R>(desc.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setValue(thisRef: T, desc: PropertyMetadata, value: R) {
|
operator fun setValue(thisRef: T, desc: PropertyMetadata, value: R) {
|
||||||
thisRef.setData(desc.name, value)
|
thisRef.setData(desc.name, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public interface ReadOnlyProperty<in R, out T> {
|
|||||||
* @param property the metadata for the property.
|
* @param property the metadata for the property.
|
||||||
* @return the property value.
|
* @return the property value.
|
||||||
*/
|
*/
|
||||||
public fun getValue(thisRef: R, property: PropertyMetadata): T
|
public operator fun getValue(thisRef: R, property: PropertyMetadata): T
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,7 +36,7 @@ public interface ReadWriteProperty<in R, T> {
|
|||||||
* @param property the metadata for the property.
|
* @param property the metadata for the property.
|
||||||
* @return the property value.
|
* @return the property value.
|
||||||
*/
|
*/
|
||||||
public fun getValue(thisRef: R, property: PropertyMetadata): T
|
public operator fun getValue(thisRef: R, property: PropertyMetadata): T
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the value of the property for the given object.
|
* Sets the value of the property for the given object.
|
||||||
@@ -44,5 +44,5 @@ public interface ReadWriteProperty<in R, T> {
|
|||||||
* @param property the metadata for the property.
|
* @param property the metadata for the property.
|
||||||
* @param value the value to set.
|
* @param value the value to set.
|
||||||
*/
|
*/
|
||||||
public fun setValue(thisRef: R, property: PropertyMetadata, value: T)
|
public operator fun setValue(thisRef: R, property: PropertyMetadata, value: T)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ package kotlin.properties
|
|||||||
*
|
*
|
||||||
* @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]).
|
* @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]).
|
||||||
*/
|
*/
|
||||||
public fun <V, V1: V> Map<in String, @Exact V>.getValue(thisRef: Any?, property: PropertyMetadata): V1 = getOrImplicitDefault(property.name) as V1
|
public operator fun <V, V1: V> Map<in String, @Exact V>.getValue(thisRef: Any?, property: PropertyMetadata): V1 = getOrImplicitDefault(property.name) as V1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the property for the given object from this mutable map.
|
* Returns the value of the property for the given object from this mutable map.
|
||||||
@@ -22,7 +22,7 @@ public fun <V, V1: V> Map<in String, @Exact V>.getValue(thisRef: Any?, property:
|
|||||||
* @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]).
|
* @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]).
|
||||||
*/
|
*/
|
||||||
@kotlin.jvm.JvmName("getVar")
|
@kotlin.jvm.JvmName("getVar")
|
||||||
public fun <V> MutableMap<in String, in V>.getValue(thisRef: Any?, property: PropertyMetadata): V = getOrImplicitDefault(property.name) as V
|
public operator fun <V> MutableMap<in String, in V>.getValue(thisRef: Any?, property: PropertyMetadata): V = getOrImplicitDefault(property.name) as V
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the value of the property for the given object in this mutable map.
|
* Stores the value of the property for the given object in this mutable map.
|
||||||
@@ -30,6 +30,6 @@ public fun <V> MutableMap<in String, in V>.getValue(thisRef: Any?, property: Pro
|
|||||||
* @param property the metadata for the property, used to get the name of property and store the value associated with that name in the map.
|
* @param property the metadata for the property, used to get the name of property and store the value associated with that name in the map.
|
||||||
* @param value the value to set.
|
* @param value the value to set.
|
||||||
*/
|
*/
|
||||||
public fun <V> MutableMap<in String, in V>.setValue(thisRef: Any?, property: PropertyMetadata, value: V) {
|
public operator fun <V> MutableMap<in String, in V>.setValue(thisRef: Any?, property: PropertyMetadata, value: V) {
|
||||||
this.put(property.name, value)
|
this.put(property.name, value)
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ public fun lazy<T>(lock: Any?, initializer: () -> T): Lazy<T> = SynchronizedLazy
|
|||||||
* This extension allows to use instances of Lazy for property delegation:
|
* This extension allows to use instances of Lazy for property delegation:
|
||||||
* `val property: String by lazy { initializer }`
|
* `val property: String by lazy { initializer }`
|
||||||
*/
|
*/
|
||||||
public fun <T> Lazy<T>.getValue(thisRef: Any?, property: PropertyMetadata): T = value
|
public operator fun <T> Lazy<T>.getValue(thisRef: Any?, property: PropertyMetadata): T = value
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies how a [Lazy] instance synchronizes access among multiple threads.
|
* Specifies how a [Lazy] instance synchronizes access among multiple threads.
|
||||||
|
|||||||
Reference in New Issue
Block a user