From 08241acb6f18f35b994de51f6b1565e555da84b2 Mon Sep 17 00:00:00 2001 From: Sebastian Sellmair Date: Fri, 13 Oct 2023 11:13:46 +0200 Subject: [PATCH] [Gradle] Demote ExtrasProperty APIs with little usage Those APIs can either be replaced with StoredProperty Some APIs also have shown to be 'hard to understand' KT-61634 --- .../kotlin/tooling/core/ExtrasProperty.kt | 140 +++++++++++------- .../kotlin/tooling/core/ExtrasPropertyTest.kt | 2 +- 2 files changed, 86 insertions(+), 56 deletions(-) diff --git a/libraries/tools/kotlin-tooling-core/src/main/kotlin/org/jetbrains/kotlin/tooling/core/ExtrasProperty.kt b/libraries/tools/kotlin-tooling-core/src/main/kotlin/org/jetbrains/kotlin/tooling/core/ExtrasProperty.kt index 8e277fc785c..48a222999e8 100644 --- a/libraries/tools/kotlin-tooling-core/src/main/kotlin/org/jetbrains/kotlin/tooling/core/ExtrasProperty.kt +++ b/libraries/tools/kotlin-tooling-core/src/main/kotlin/org/jetbrains/kotlin/tooling/core/ExtrasProperty.kt @@ -2,6 +2,7 @@ * Copyright 2010-2022 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. */ +@file:Suppress("DeprecatedCallableAddReplaceWith") package org.jetbrains.kotlin.tooling.core @@ -14,72 +15,30 @@ interface ExtrasProperty { val key: Extras.Key } -val Extras.Key.readProperty get() = extrasReadProperty(this) - val Extras.Key.readWriteProperty get() = extrasReadWriteProperty(this) -fun Extras.Key.factoryProperty(factory: () -> T) = extrasFactoryProperty(this, factory) - fun Extras.Key.lazyProperty(factory: Receiver.() -> T) = extrasLazyProperty(this, factory) -fun Extras.Key>.nullableLazyProperty(factory: Receiver.() -> T?) = - extrasNullableLazyProperty(this, factory) - -fun extrasReadProperty(key: Extras.Key): ExtrasReadOnlyProperty = object : ExtrasReadOnlyProperty { - override val key: Extras.Key = key -} - fun extrasReadWriteProperty(key: Extras.Key): ExtrasReadWriteProperty = object : ExtrasReadWriteProperty { override val key: Extras.Key = key } -fun extrasFactoryProperty(key: Extras.Key, factory: () -> T) = object : ExtrasFactoryProperty { - override val key: Extras.Key = key - override val factory: () -> T = factory -} - fun extrasLazyProperty( - key: Extras.Key, factory: Receiver.() -> T + key: Extras.Key, factory: Receiver.() -> T, ): ExtrasLazyProperty = object : ExtrasLazyProperty { override val key: Extras.Key = key override val factory: Receiver.() -> T = factory } -fun extrasNullableLazyProperty( - key: Extras.Key>, factory: Receiver.() -> T? -): NullableExtrasLazyProperty = - object : NullableExtrasLazyProperty { - override val key: Extras.Key> = key - override val factory: Receiver.() -> T? = factory - } inline fun extrasReadWriteProperty(name: String? = null) = extrasReadWriteProperty(extrasKeyOf(name)) -inline fun extrasReadProperty(name: String? = null) = - extrasReadProperty(extrasKeyOf(name)) - -inline fun extrasFactoryProperty(name: String? = null, noinline factory: () -> T) = - extrasFactoryProperty(extrasKeyOf(name), factory) inline fun extrasLazyProperty(name: String? = null, noinline factory: Receiver.() -> T) = extrasLazyProperty(extrasKeyOf(name), factory) -inline fun extrasNullableLazyProperty( - name: String? = null, noinline factory: Receiver.() -> T? -) = extrasNullableLazyProperty(extrasKeyOf(name), factory) - -interface ExtrasReadOnlyProperty : ExtrasProperty, ReadOnlyProperty { - override fun getValue(thisRef: HasExtras, property: KProperty<*>): T? { - return thisRef.extras[key] - } - - fun notNull(defaultValue: T): NotNullExtrasReadOnlyProperty = object : NotNullExtrasReadOnlyProperty { - override val defaultValue: T = defaultValue - override val key: Extras.Key = this@ExtrasReadOnlyProperty.key - } -} interface NotNullExtrasReadOnlyProperty : ExtrasProperty, ReadOnlyProperty { val defaultValue: T @@ -117,18 +76,6 @@ interface NotNullExtrasReadWriteProperty : ExtrasProperty, ReadWrite } } -interface ExtrasFactoryProperty : ExtrasProperty, ReadWriteProperty { - val factory: () -> T - - override fun getValue(thisRef: HasMutableExtras, property: KProperty<*>): T { - return thisRef.extras.getOrPut(key, factory) - } - - override fun setValue(thisRef: HasMutableExtras, property: KProperty<*>, value: T) { - thisRef.extras[key] = value - } -} - interface ExtrasLazyProperty : ExtrasProperty, ReadWriteProperty { val factory: Receiver.() -> T @@ -141,6 +88,89 @@ interface ExtrasLazyProperty : ExtrasPrope } } +/* +DEPRECATED APIs + */ + +@Deprecated("Scheduled for removal in Kotlin 2.2") +@Suppress("DEPRECATION") +val Extras.Key.readProperty get() = extrasReadProperty(this) + +@Deprecated("Scheduled for removal in Kotlin 2.2") +@Suppress("DEPRECATION") +fun Extras.Key.factoryProperty(factory: () -> T) = extrasFactoryProperty(this, factory) + +@Deprecated("Scheduled for removal in Kotlin 2.2") +@Suppress("DEPRECATION") +fun Extras.Key>.nullableLazyProperty(factory: Receiver.() -> T?) = + extrasNullableLazyProperty(this, factory) + +@Deprecated("Scheduled for removal in Kotlin 2.2") +@Suppress("DEPRECATION") +fun extrasReadProperty(key: Extras.Key): ExtrasReadOnlyProperty = object : ExtrasReadOnlyProperty { + override val key: Extras.Key = key +} + +@Deprecated("Scheduled for removal in Kotlin 2.2") +@Suppress("DEPRECATION") +fun extrasFactoryProperty(key: Extras.Key, factory: () -> T) = object : ExtrasFactoryProperty { + override val key: Extras.Key = key + override val factory: () -> T = factory +} + +@Deprecated("Scheduled for removal in Kotlin 2.2") +@Suppress("DEPRECATION") +fun extrasNullableLazyProperty( + key: Extras.Key>, factory: Receiver.() -> T?, +): NullableExtrasLazyProperty = + object : NullableExtrasLazyProperty { + override val key: Extras.Key> = key + override val factory: Receiver.() -> T? = factory + } + +@Deprecated("Scheduled for removal in Kotlin 2.2") +@Suppress("DEPRECATION", "UNUSED") +inline fun extrasReadProperty(name: String? = null) = + extrasReadProperty(extrasKeyOf(name)) + + +@Deprecated("Scheduled for removal in Kotlin 2.2") +@Suppress("DEPRECATION", "UNUSED") +inline fun extrasFactoryProperty(name: String? = null, noinline factory: () -> T) = + extrasFactoryProperty(extrasKeyOf(name), factory) + +@Deprecated("Scheduled for removal in Kotlin 2.2") +@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith") +inline fun extrasNullableLazyProperty( + name: String? = null, noinline factory: Receiver.() -> T?, +) = extrasNullableLazyProperty(extrasKeyOf(name), factory) + +@Deprecated("Scheduled for removal in Kotlin 2.2") +interface ExtrasReadOnlyProperty : ExtrasProperty, ReadOnlyProperty { + override fun getValue(thisRef: HasExtras, property: KProperty<*>): T? { + return thisRef.extras[key] + } + + fun notNull(defaultValue: T): NotNullExtrasReadOnlyProperty = object : NotNullExtrasReadOnlyProperty { + override val defaultValue: T = defaultValue + override val key: Extras.Key = this@ExtrasReadOnlyProperty.key + } +} + +@Deprecated("Scheduled for removal in Kotlin 2.2") +interface ExtrasFactoryProperty : ExtrasProperty, ReadWriteProperty { + val factory: () -> T + + override fun getValue(thisRef: HasMutableExtras, property: KProperty<*>): T { + return thisRef.extras.getOrPut(key, factory) + } + + override fun setValue(thisRef: HasMutableExtras, property: KProperty<*>, value: T) { + thisRef.extras[key] = value + } +} + +@Deprecated("Scheduled for removal in Kotlin 2.2") interface NullableExtrasLazyProperty : ExtrasProperty>, ReadOnlyProperty { val factory: Receiver.() -> T? diff --git a/libraries/tools/kotlin-tooling-core/src/test/kotlin/org/jetbrains/kotlin/tooling/core/ExtrasPropertyTest.kt b/libraries/tools/kotlin-tooling-core/src/test/kotlin/org/jetbrains/kotlin/tooling/core/ExtrasPropertyTest.kt index 9eee574741f..3bd3fb94ac8 100644 --- a/libraries/tools/kotlin-tooling-core/src/test/kotlin/org/jetbrains/kotlin/tooling/core/ExtrasPropertyTest.kt +++ b/libraries/tools/kotlin-tooling-core/src/test/kotlin/org/jetbrains/kotlin/tooling/core/ExtrasPropertyTest.kt @@ -7,9 +7,9 @@ package org.jetbrains.kotlin.tooling.core import kotlin.test.* +@Suppress("DEPRECATION") class ExtrasPropertyTest { - class Subject : HasMutableExtras { override val extras: MutableExtras = mutableExtrasOf() }