From f9e89596fd4a5ca832e1968f66772b851f797b39 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Mon, 12 Oct 2015 19:37:04 +0300 Subject: [PATCH] Add 'operator' modifier to stdlib property Delegate functions --- .../duplicateJvmSignature/delegatedProperty.kt | 2 +- .../callExpression/callInMemberValDelegateRuntime.kt | 2 +- .../callExpression/callInMemberValDelegateRuntime.kt.after | 2 +- .../compiler/backend/js/ast/metadata/MetadataProperty.kt | 4 ++-- libraries/stdlib/src/kotlin/properties/Interfaces.kt | 6 +++--- libraries/stdlib/src/kotlin/properties/MapAccessors.kt | 6 +++--- libraries/stdlib/src/kotlin/util/Lazy.kt | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/delegatedProperty.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/delegatedProperty.kt index e8d30ddef8e..2af8869417b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/delegatedProperty.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/delegatedProperty.kt @@ -3,5 +3,5 @@ import kotlin.properties.Delegates class C { val `x$delegate`: ReadWriteProperty? = null - val x: String? by Delegates.notNull() + val x: String? by Delegates.notNull() } \ No newline at end of file diff --git a/idea/testData/quickfix/createFromUsage/createClass/callExpression/callInMemberValDelegateRuntime.kt b/idea/testData/quickfix/createFromUsage/createClass/callExpression/callInMemberValDelegateRuntime.kt index 801c0207c05..8b5523f04f4 100644 --- a/idea/testData/quickfix/createFromUsage/createClass/callExpression/callInMemberValDelegateRuntime.kt +++ b/idea/testData/quickfix/createFromUsage/createClass/callExpression/callInMemberValDelegateRuntime.kt @@ -1,5 +1,5 @@ // "Create class 'Foo'" "true" -// ERROR: Class 'Foo' must be declared abstract or implement abstract member
public abstract fun getValue(thisRef: A<T>, property: kotlin.PropertyMetadata): B defined in kotlin.properties.ReadOnlyProperty +// ERROR: Class 'Foo' must be declared abstract or implement abstract member
public abstract operator fun getValue(thisRef: A<T>, property: kotlin.PropertyMetadata): B defined in kotlin.properties.ReadOnlyProperty open class B diff --git a/idea/testData/quickfix/createFromUsage/createClass/callExpression/callInMemberValDelegateRuntime.kt.after b/idea/testData/quickfix/createFromUsage/createClass/callExpression/callInMemberValDelegateRuntime.kt.after index aae6dc72503..037d0fd5f5c 100644 --- a/idea/testData/quickfix/createFromUsage/createClass/callExpression/callInMemberValDelegateRuntime.kt.after +++ b/idea/testData/quickfix/createFromUsage/createClass/callExpression/callInMemberValDelegateRuntime.kt.after @@ -1,7 +1,7 @@ import kotlin.properties.ReadOnlyProperty // "Create class 'Foo'" "true" -// ERROR: Class 'Foo' must be declared abstract or implement abstract member
public abstract fun getValue(thisRef: A<T>, property: kotlin.PropertyMetadata): B defined in kotlin.properties.ReadOnlyProperty +// ERROR: Class 'Foo' must be declared abstract or implement abstract member
public abstract operator fun getValue(thisRef: A<T>, property: kotlin.PropertyMetadata): B defined in kotlin.properties.ReadOnlyProperty open class B diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/metadata/MetadataProperty.kt b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/metadata/MetadataProperty.kt index 9de093654dd..21414e1d7a3 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/metadata/MetadataProperty.kt +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/metadata/MetadataProperty.kt @@ -17,12 +17,12 @@ package com.google.dart.compiler.backend.js.ast.metadata internal class MetadataProperty(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 return thisRef.getData(desc.name) } - fun setValue(thisRef: T, desc: PropertyMetadata, value: R) { + operator fun setValue(thisRef: T, desc: PropertyMetadata, value: R) { thisRef.setData(desc.name, value) } } diff --git a/libraries/stdlib/src/kotlin/properties/Interfaces.kt b/libraries/stdlib/src/kotlin/properties/Interfaces.kt index ee83fcb6988..9e862b20bfe 100644 --- a/libraries/stdlib/src/kotlin/properties/Interfaces.kt +++ b/libraries/stdlib/src/kotlin/properties/Interfaces.kt @@ -17,7 +17,7 @@ public interface ReadOnlyProperty { * @param property the metadata for the property. * @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 { * @param property the metadata for the property. * @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. @@ -44,5 +44,5 @@ public interface ReadWriteProperty { * @param property the metadata for the property. * @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) } diff --git a/libraries/stdlib/src/kotlin/properties/MapAccessors.kt b/libraries/stdlib/src/kotlin/properties/MapAccessors.kt index 49dad03a858..7d76e586b4a 100644 --- a/libraries/stdlib/src/kotlin/properties/MapAccessors.kt +++ b/libraries/stdlib/src/kotlin/properties/MapAccessors.kt @@ -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]). */ -public fun Map.getValue(thisRef: Any?, property: PropertyMetadata): V1 = getOrImplicitDefault(property.name) as V1 +public operator fun Map.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. @@ -22,7 +22,7 @@ public fun Map.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]). */ @kotlin.jvm.JvmName("getVar") -public fun MutableMap.getValue(thisRef: Any?, property: PropertyMetadata): V = getOrImplicitDefault(property.name) as V +public operator fun MutableMap.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. @@ -30,6 +30,6 @@ public fun MutableMap.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 value the value to set. */ -public fun MutableMap.setValue(thisRef: Any?, property: PropertyMetadata, value: V) { +public operator fun MutableMap.setValue(thisRef: Any?, property: PropertyMetadata, value: V) { this.put(property.name, value) } \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/util/Lazy.kt b/libraries/stdlib/src/kotlin/util/Lazy.kt index e88428bbb6b..12be348cb95 100644 --- a/libraries/stdlib/src/kotlin/util/Lazy.kt +++ b/libraries/stdlib/src/kotlin/util/Lazy.kt @@ -74,7 +74,7 @@ public fun lazy(lock: Any?, initializer: () -> T): Lazy = SynchronizedLazy * This extension allows to use instances of Lazy for property delegation: * `val property: String by lazy { initializer }` */ -public fun Lazy.getValue(thisRef: Any?, property: PropertyMetadata): T = value +public operator fun Lazy.getValue(thisRef: Any?, property: PropertyMetadata): T = value /** * Specifies how a [Lazy] instance synchronizes access among multiple threads.