[Gradle] Remove HasExtras delegates in favor of new ExtrasProperty

KT-55189
This commit is contained in:
Sebastian Sellmair
2022-12-01 13:29:26 +01:00
committed by Space Team
parent 4ea77f7836
commit ba68977f52
8 changed files with 17 additions and 81 deletions
@@ -34,7 +34,8 @@ data class IdeaKotlinProjectArtifactDependency(
internal companion object {
const val serialVersionUID = 0L
var IdeaKotlinSourceDependency.projectArtifactDependencyOrigin by extrasKeyOf<IdeaKotlinProjectArtifactDependency>("origin")
var IdeaKotlinSourceDependency.projectArtifactDependencyOrigin
by extrasReadWriteProperty<IdeaKotlinProjectArtifactDependency>("origin")
private set
}
}
@@ -8,11 +8,10 @@ package org.jetbrains.kotlin.gradle.idea.tcs.extras
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinBinaryDependency
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinExtra
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
import org.jetbrains.kotlin.tooling.core.getValue
import org.jetbrains.kotlin.tooling.core.setValue
import org.jetbrains.kotlin.tooling.core.readWriteProperty
import java.io.Serializable
var IdeaKotlinBinaryDependency.klibExtra by KlibExtra.key
var IdeaKotlinBinaryDependency.klibExtra by KlibExtra.key.readWriteProperty
@IdeaKotlinExtra
data class KlibExtra(
@@ -8,9 +8,7 @@ package org.jetbrains.kotlin.gradle.plugin.ide
import org.gradle.api.artifacts.result.ResolvedArtifactResult
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
import org.jetbrains.kotlin.tooling.core.getValue
import org.jetbrains.kotlin.tooling.core.setValue
import org.jetbrains.kotlin.tooling.core.extrasReadWriteProperty
fun interface IdeDependencyResolver {
fun resolve(sourceSet: KotlinSourceSet): Set<IdeaKotlinDependency>
@@ -20,8 +18,8 @@ fun interface IdeDependencyResolver {
}
companion object {
var IdeaKotlinDependency.resolvedBy: IdeDependencyResolver? by extrasKeyOf("resolvedBy")
var IdeaKotlinDependency.gradleArtifact: ResolvedArtifactResult? by extrasKeyOf("gradleArtifact")
var IdeaKotlinDependency.resolvedBy: IdeDependencyResolver? by extrasReadWriteProperty("resolvedBy")
var IdeaKotlinDependency.gradleArtifact: ResolvedArtifactResult? by extrasReadWriteProperty("gradleArtifact")
}
}
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.gradle.plugin.sources.defaultSourceSetLanguageSettin
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import org.jetbrains.kotlin.gradle.utils.addExtendsFromRelation
import org.jetbrains.kotlin.tooling.core.extrasFactoryProperty
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
import java.util.concurrent.Callable
internal class KotlinCompilationSourceSetInclusion(
@@ -75,7 +74,7 @@ internal class KotlinCompilationSourceSetInclusion(
* to avoid re-processing of unnecessary source sets!
*/
val InternalKotlinCompilation<*>.includedSourceSets: MutableSet<KotlinSourceSet>
by extrasFactoryProperty(extrasKeyOf(KotlinCompilationSourceSetInclusion::class.java.name), { hashSetOf() })
by extrasFactoryProperty(KotlinCompilationSourceSetInclusion::class.java.name, { hashSetOf() })
}
@@ -128,11 +128,6 @@ public abstract interface class org/jetbrains/kotlin/tooling/core/HasExtras {
public abstract fun getExtras ()Lorg/jetbrains/kotlin/tooling/core/Extras;
}
public final class org/jetbrains/kotlin/tooling/core/HasExtrasKt {
public static final fun getValue (Lorg/jetbrains/kotlin/tooling/core/Extras$Key;Lorg/jetbrains/kotlin/tooling/core/HasExtras;Lkotlin/reflect/KProperty;)Ljava/lang/Object;
public static final fun setValue (Lorg/jetbrains/kotlin/tooling/core/Extras$Key;Lorg/jetbrains/kotlin/tooling/core/HasMutableExtras;Lkotlin/reflect/KProperty;Ljava/lang/Object;)V
}
public abstract interface class org/jetbrains/kotlin/tooling/core/HasMutableExtras : org/jetbrains/kotlin/tooling/core/HasExtras {
public abstract fun getExtras ()Lorg/jetbrains/kotlin/tooling/core/MutableExtras;
}
@@ -32,6 +32,15 @@ fun <T : Any> extrasFactoryProperty(key: Extras.Key<T>, factory: () -> T) = obje
override val factory: () -> T = factory
}
inline fun <reified T : Any> extrasReadWriteProperty(name: String? = null) =
extrasReadWriteProperty(extrasKeyOf<T>(name))
inline fun <reified T : Any> extrasReadProperty(name: String? = null) =
extrasReadProperty(extrasKeyOf<T>(name))
inline fun <reified T : Any> extrasFactoryProperty(name: String? = null, noinline factory: () -> T) =
extrasFactoryProperty(extrasKeyOf<T>(name), factory)
interface ExtrasReadOnlyProperty<T : Any> : ExtrasProperty<T>, ReadOnlyProperty<HasExtras, T?> {
override fun getValue(thisRef: HasExtras, property: KProperty<*>): T? {
return thisRef.extras[key]
@@ -5,8 +5,6 @@
package org.jetbrains.kotlin.tooling.core
import kotlin.reflect.KProperty
interface HasExtras {
val extras: Extras
@@ -15,17 +13,3 @@ interface HasExtras {
interface HasMutableExtras : HasExtras {
override val extras: MutableExtras
}
operator fun <T : Any> Extras.Key<T>.getValue(receiver: HasExtras, property: KProperty<*>): T? {
return receiver.extras[this]
}
operator fun <T : Any> Extras.Key<T>.setValue(receiver: HasMutableExtras, property: KProperty<*>, value: T?) {
if (value == null) {
receiver.extras.remove(this)
} else {
receiver.extras[this] = value
}
}
@@ -1,49 +0,0 @@
/*
* 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.
*/
package org.jetbrains.kotlin.tooling.core
import org.jetbrains.kotlin.tooling.core.HasExtrasTest.Subject.Companion.value1
import org.jetbrains.kotlin.tooling.core.HasExtrasTest.Subject.Companion.value2
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
class HasExtrasTest {
class Subject : HasMutableExtras {
override val extras: MutableExtras = mutableExtrasOf()
companion object {
var Subject.value1: Int? by extrasKeyOf()
var Subject.value2: Int? by extrasKeyOf("2")
}
}
@Test
fun `test - non-null value`() {
val subject = Subject()
assertNull(subject.value1)
assertNull(subject.value2)
subject.value1 = 1
assertEquals(1, subject.value1)
assertNull(subject.value2)
subject.value2 = 2
assertEquals(1, subject.value1)
assertEquals(2, subject.value2)
}
@Test
fun `test - set null`() {
val subject = Subject()
subject.value1 = 1
assertEquals(1, subject.value1)
subject.value1 = null
assertNull(subject.value1)
}
}