[kpm] kotlin-tooling-core: Move Type into Extras.Type
^KT-52568 Verification Pending
This commit is contained in:
committed by
Space
parent
08bb163021
commit
12b6d32e73
+10
-10
@@ -51,11 +51,11 @@ public final class org/jetbrains/kotlin/tooling/core/Extras$Entry : java/io/Seri
|
|||||||
|
|
||||||
public final class org/jetbrains/kotlin/tooling/core/Extras$Key : java/io/Serializable {
|
public final class org/jetbrains/kotlin/tooling/core/Extras$Key : java/io/Serializable {
|
||||||
public static final field Companion Lorg/jetbrains/kotlin/tooling/core/Extras$Key$Companion;
|
public static final field Companion Lorg/jetbrains/kotlin/tooling/core/Extras$Key$Companion;
|
||||||
public fun <init> (Lorg/jetbrains/kotlin/tooling/core/Type;Ljava/lang/String;)V
|
public fun <init> (Lorg/jetbrains/kotlin/tooling/core/Extras$Type;Ljava/lang/String;)V
|
||||||
public fun equals (Ljava/lang/Object;)Z
|
public fun equals (Ljava/lang/Object;)Z
|
||||||
public final fun getName ()Ljava/lang/String;
|
public final fun getName ()Ljava/lang/String;
|
||||||
public final fun getStableString ()Ljava/lang/String;
|
public final fun getStableString ()Ljava/lang/String;
|
||||||
public final fun getType ()Lorg/jetbrains/kotlin/tooling/core/Type;
|
public final fun getType ()Lorg/jetbrains/kotlin/tooling/core/Extras$Type;
|
||||||
public fun hashCode ()I
|
public fun hashCode ()I
|
||||||
public fun toString ()Ljava/lang/String;
|
public fun toString ()Ljava/lang/String;
|
||||||
}
|
}
|
||||||
@@ -64,6 +64,13 @@ public final class org/jetbrains/kotlin/tooling/core/Extras$Key$Companion {
|
|||||||
public final fun fromString (Ljava/lang/String;)Lorg/jetbrains/kotlin/tooling/core/Extras$Key;
|
public final fun fromString (Ljava/lang/String;)Lorg/jetbrains/kotlin/tooling/core/Extras$Key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final class org/jetbrains/kotlin/tooling/core/Extras$Type : java/io/Serializable {
|
||||||
|
public fun <init> (Ljava/lang/String;)V
|
||||||
|
public fun equals (Ljava/lang/Object;)Z
|
||||||
|
public fun hashCode ()I
|
||||||
|
public fun toString ()Ljava/lang/String;
|
||||||
|
}
|
||||||
|
|
||||||
public final class org/jetbrains/kotlin/tooling/core/ExtrasUtilsKt {
|
public final class org/jetbrains/kotlin/tooling/core/ExtrasUtilsKt {
|
||||||
public static final fun emptyExtras ()Lorg/jetbrains/kotlin/tooling/core/Extras;
|
public static final fun emptyExtras ()Lorg/jetbrains/kotlin/tooling/core/Extras;
|
||||||
public static final fun extrasOf ()Lorg/jetbrains/kotlin/tooling/core/Extras;
|
public static final fun extrasOf ()Lorg/jetbrains/kotlin/tooling/core/Extras;
|
||||||
@@ -133,14 +140,7 @@ public abstract interface class org/jetbrains/kotlin/tooling/core/MutableExtras
|
|||||||
public abstract fun set (Lorg/jetbrains/kotlin/tooling/core/Extras$Key;Ljava/lang/Object;)Ljava/lang/Object;
|
public abstract fun set (Lorg/jetbrains/kotlin/tooling/core/Extras$Key;Ljava/lang/Object;)Ljava/lang/Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class org/jetbrains/kotlin/tooling/core/Type : java/io/Serializable {
|
public final class org/jetbrains/kotlin/tooling/core/TypeUtils {
|
||||||
public fun <init> (Ljava/lang/String;)V
|
|
||||||
public fun equals (Ljava/lang/Object;)Z
|
|
||||||
public fun hashCode ()I
|
|
||||||
public fun toString ()Ljava/lang/String;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final class org/jetbrains/kotlin/tooling/core/TypeKt {
|
|
||||||
public static final fun renderReifiedTypeSignatureString (Lkotlin/reflect/KType;)Ljava/lang/String;
|
public static final fun renderReifiedTypeSignatureString (Lkotlin/reflect/KType;)Ljava/lang/String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -8,8 +8,8 @@ package org.jetbrains.kotlin.gradle.kpm.idea.testFixtures
|
|||||||
import org.jetbrains.kotlin.gradle.kpm.idea.serialize.IdeaKpmExtrasSerializationExtension
|
import org.jetbrains.kotlin.gradle.kpm.idea.serialize.IdeaKpmExtrasSerializationExtension
|
||||||
import org.jetbrains.kotlin.gradle.kpm.idea.serialize.IdeaKpmExtrasSerializer
|
import org.jetbrains.kotlin.gradle.kpm.idea.serialize.IdeaKpmExtrasSerializer
|
||||||
import org.jetbrains.kotlin.tooling.core.Extras
|
import org.jetbrains.kotlin.tooling.core.Extras
|
||||||
import org.jetbrains.kotlin.tooling.core.Type
|
|
||||||
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
|
import org.jetbrains.kotlin.tooling.core.extrasKeyOf
|
||||||
|
import org.jetbrains.kotlin.tooling.core.extrasTypeOf
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
object TestIdeaKpmExtrasSerializationExtension : IdeaKpmExtrasSerializationExtension {
|
object TestIdeaKpmExtrasSerializationExtension : IdeaKpmExtrasSerializationExtension {
|
||||||
@@ -20,8 +20,8 @@ object TestIdeaKpmExtrasSerializationExtension : IdeaKpmExtrasSerializationExten
|
|||||||
override fun <T : Any> serializer(key: Extras.Key<T>): IdeaKpmExtrasSerializer<T>? = when {
|
override fun <T : Any> serializer(key: Extras.Key<T>): IdeaKpmExtrasSerializer<T>? = when {
|
||||||
key == ignoredStringKey -> null
|
key == ignoredStringKey -> null
|
||||||
key == anySerializableKey -> IdeaKpmExtrasSerializer.javaIoSerializable<Any>()
|
key == anySerializableKey -> IdeaKpmExtrasSerializer.javaIoSerializable<Any>()
|
||||||
key.type == Type<String>() -> TestIdeaKpmStringExtrasSerializer
|
key.type == extrasTypeOf<String>() -> TestIdeaKpmStringExtrasSerializer
|
||||||
key.type == Type<Int>() -> TestIdeaKpmIntExtrasSerializer
|
key.type == extrasTypeOf<Int>() -> TestIdeaKpmIntExtrasSerializer
|
||||||
else -> null
|
else -> null
|
||||||
} as? IdeaKpmExtrasSerializer<T>
|
} as? IdeaKpmExtrasSerializer<T>
|
||||||
}
|
}
|
||||||
|
|||||||
+21
@@ -63,6 +63,27 @@ import java.io.Serializable
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
interface Extras : Collection<Entry<out Any>> {
|
interface Extras : Collection<Entry<out Any>> {
|
||||||
|
class Type<T> @UnsafeApi("Use 'extrasTypeOf()' instead") @PublishedApi internal constructor(
|
||||||
|
internal val signature: String
|
||||||
|
) : Serializable {
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (this === other) return true
|
||||||
|
if (other !is Type<*>) return false
|
||||||
|
if (other.signature != this.signature) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return 31 * signature.hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String = signature
|
||||||
|
|
||||||
|
internal companion object {
|
||||||
|
private const val serialVersionUID = 0L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Not implemented as data class to ensure more controllable binary compatibility */
|
/* Not implemented as data class to ensure more controllable binary compatibility */
|
||||||
class Key<T : Any> @PublishedApi internal constructor(
|
class Key<T : Any> @PublishedApi internal constructor(
|
||||||
val type: Type<T>,
|
val type: Type<T>,
|
||||||
|
|||||||
+8
-1
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.tooling.core
|
package org.jetbrains.kotlin.tooling.core
|
||||||
|
|
||||||
|
import kotlin.reflect.typeOf
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a value based key for accessing any [Extras] container
|
* Creates a value based key for accessing any [Extras] container
|
||||||
*
|
*
|
||||||
@@ -25,7 +27,7 @@ package org.jetbrains.kotlin.tooling.core
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
inline fun <reified T : Any> extrasKeyOf(name: String? = null): Extras.Key<T> =
|
inline fun <reified T : Any> extrasKeyOf(name: String? = null): Extras.Key<T> =
|
||||||
Extras.Key(Type(), name)
|
Extras.Key(extrasTypeOf(), name)
|
||||||
|
|
||||||
fun emptyExtras(): Extras = EmptyExtras
|
fun emptyExtras(): Extras = EmptyExtras
|
||||||
|
|
||||||
@@ -37,6 +39,11 @@ fun mutableExtrasOf(): MutableExtras = MutableExtrasImpl()
|
|||||||
|
|
||||||
fun mutableExtrasOf(vararg entries: Extras.Entry<*>): MutableExtras = MutableExtrasImpl(entries.toList())
|
fun mutableExtrasOf(vararg entries: Extras.Entry<*>): MutableExtras = MutableExtrasImpl(entries.toList())
|
||||||
|
|
||||||
|
inline fun <reified T> extrasTypeOf(): Extras.Type<T> {
|
||||||
|
@OptIn(UnsafeApi::class, ExperimentalStdlibApi::class)
|
||||||
|
return Extras.Type(renderReifiedTypeSignatureString(typeOf<T>()))
|
||||||
|
}
|
||||||
|
|
||||||
fun Iterable<Extras.Entry<*>>.toExtras(): Extras = ImmutableExtrasImpl(this)
|
fun Iterable<Extras.Entry<*>>.toExtras(): Extras = ImmutableExtrasImpl(this)
|
||||||
|
|
||||||
fun Iterable<Extras.Entry<*>>.toMutableExtras(): MutableExtras = MutableExtrasImpl(this)
|
fun Iterable<Extras.Entry<*>>.toMutableExtras(): MutableExtras = MutableExtrasImpl(this)
|
||||||
|
|||||||
+1
-29
@@ -4,41 +4,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("FunctionName")
|
@file:Suppress("FunctionName")
|
||||||
|
@file:JvmName("TypeUtils")
|
||||||
|
|
||||||
package org.jetbrains.kotlin.tooling.core
|
package org.jetbrains.kotlin.tooling.core
|
||||||
|
|
||||||
import java.io.Serializable
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.KType
|
import kotlin.reflect.KType
|
||||||
import kotlin.reflect.KVariance
|
import kotlin.reflect.KVariance
|
||||||
import kotlin.reflect.typeOf
|
|
||||||
|
|
||||||
inline fun <reified T> Type(): Type<T> {
|
|
||||||
@OptIn(UnsafeApi::class, ExperimentalStdlibApi::class)
|
|
||||||
return Type(renderReifiedTypeSignatureString(typeOf<T>()))
|
|
||||||
}
|
|
||||||
|
|
||||||
class Type<T>
|
|
||||||
@UnsafeApi("Use 'Type' instead")
|
|
||||||
@PublishedApi internal constructor(internal val signature: String) : Serializable {
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
if (this === other) return true
|
|
||||||
if (other !is Type<*>) return false
|
|
||||||
if (other.signature != this.signature) return false
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return 31 * signature.hashCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String = signature
|
|
||||||
|
|
||||||
internal companion object {
|
|
||||||
private const val serialVersionUID = 0L
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@UnsafeApi("Use 'ReifiedTypeSignature' instead")
|
@UnsafeApi("Use 'ReifiedTypeSignature' instead")
|
||||||
+14
-14
@@ -24,21 +24,21 @@ class TypeTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `test - sample 0`() {
|
fun `test - sample 0`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"kotlin.collections.List<kotlin.Int>", Type<List<Int>>().signature
|
"kotlin.collections.List<kotlin.Int>", extrasTypeOf<List<Int>>().signature
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test - sample 1`() {
|
fun `test - sample 1`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"kotlin.collections.List<*>", Type<List<*>>().signature
|
"kotlin.collections.List<*>", extrasTypeOf<List<*>>().signature
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test - sample 2`() {
|
fun `test - sample 2`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"kotlin.String", Type<String>().signature
|
"kotlin.String", extrasTypeOf<String>().signature
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ class TypeTest {
|
|||||||
fun `test - sample 3`() {
|
fun `test - sample 3`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"kotlin.collections.Map<kotlin.String, kotlin.collections.List<kotlin.Pair<kotlin.Int, kotlin.String>>>",
|
"kotlin.collections.Map<kotlin.String, kotlin.collections.List<kotlin.Pair<kotlin.Int, kotlin.String>>>",
|
||||||
Type<Map<String, List<Pair<Int, String>>>>().signature
|
extrasTypeOf<Map<String, List<Pair<Int, String>>>>().signature
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ class TypeTest {
|
|||||||
fun `test - sample 5 - inner class`() {
|
fun `test - sample 5 - inner class`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"org.jetbrains.kotlin.tooling.core.TypeTest.Outer.Inner",
|
"org.jetbrains.kotlin.tooling.core.TypeTest.Outer.Inner",
|
||||||
Type<Outer.Inner>().signature
|
extrasTypeOf<Outer.Inner>().signature
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,43 +63,43 @@ class TypeTest {
|
|||||||
fun `test - sample 6 - recursive types`() {
|
fun `test - sample 6 - recursive types`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"org.jetbrains.kotlin.tooling.core.TypeTest.Recursive<*>",
|
"org.jetbrains.kotlin.tooling.core.TypeTest.Recursive<*>",
|
||||||
Type<Recursive<*>>().signature
|
extrasTypeOf<Recursive<*>>().signature
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"org.jetbrains.kotlin.tooling.core.TypeTest.AnyRecursive",
|
"org.jetbrains.kotlin.tooling.core.TypeTest.AnyRecursive",
|
||||||
Type<AnyRecursive>().signature
|
extrasTypeOf<AnyRecursive>().signature
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"org.jetbrains.kotlin.tooling.core.TypeTest" +
|
"org.jetbrains.kotlin.tooling.core.TypeTest" +
|
||||||
".Recursive<org.jetbrains.kotlin.tooling.core.TypeTest.AnyRecursive>",
|
".Recursive<org.jetbrains.kotlin.tooling.core.TypeTest.AnyRecursive>",
|
||||||
Type<Recursive<AnyRecursive>>().signature
|
extrasTypeOf<Recursive<AnyRecursive>>().signature
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test sample 7 - nullable`() {
|
fun `test sample 7 - nullable`() {
|
||||||
assertEquals("kotlin.collections.List<*>?", Type<List<*>?>().signature)
|
assertEquals("kotlin.collections.List<*>?", extrasTypeOf<List<*>?>().signature)
|
||||||
assertEquals("kotlin.collections.List<kotlin.Int?>", Type<List<Int?>>().signature)
|
assertEquals("kotlin.collections.List<kotlin.Int?>", extrasTypeOf<List<Int?>>().signature)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test sample 8 - variance`() {
|
fun `test sample 8 - variance`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"org.jetbrains.kotlin.tooling.core.TypeTest.Box<out kotlin.Int>",
|
"org.jetbrains.kotlin.tooling.core.TypeTest.Box<out kotlin.Int>",
|
||||||
Type<Box<out Int>>().signature
|
extrasTypeOf<Box<out Int>>().signature
|
||||||
)
|
)
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"org.jetbrains.kotlin.tooling.core.TypeTest.Box<in kotlin.Int>",
|
"org.jetbrains.kotlin.tooling.core.TypeTest.Box<in kotlin.Int>",
|
||||||
Type<Box<in Int>>().signature
|
extrasTypeOf<Box<in Int>>().signature
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("RemoveExplicitTypeArguments", "TYPE_INFERENCE_ONLY_INPUT_TYPES_WARNING")
|
@Suppress("RemoveExplicitTypeArguments", "TYPE_INFERENCE_ONLY_INPUT_TYPES_WARNING")
|
||||||
@Test
|
@Test
|
||||||
fun `test - equals`() {
|
fun `test - equals`() {
|
||||||
assertEquals(Type<List<Int>>(), Type<List<Int>>())
|
assertEquals(extrasTypeOf<List<Int>>(), extrasTypeOf<List<Int>>())
|
||||||
assertNotEquals(Type<List<Int?>>(), Type<List<Int>>())
|
assertNotEquals(extrasTypeOf<List<Int?>>(), extrasTypeOf<List<Int>>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user