Change extension properties on ClassName into functions, to be more distinct from other String extensions.
This commit is contained in:
committed by
Space Team
parent
db53b83822
commit
165e779e3e
@@ -1,5 +1,6 @@
|
||||
public final class kotlinx/metadata/ClassNameKt {
|
||||
public static final fun isLocal (Ljava/lang/String;)Z
|
||||
public static final fun isLocalClassName (Ljava/lang/String;)Z
|
||||
}
|
||||
|
||||
public abstract interface annotation class kotlinx/metadata/ExperimentalContextReceivers : java/lang/annotation/Annotation {
|
||||
@@ -1143,6 +1144,7 @@ public final class kotlinx/metadata/jvm/JvmMetadataUtil {
|
||||
public static final fun Metadata (Ljava/lang/Integer;[I[Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;)Lkotlin/Metadata;
|
||||
public static synthetic fun Metadata$default (Ljava/lang/Integer;[I[Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;ILjava/lang/Object;)Lkotlin/Metadata;
|
||||
public static final fun getJvmInternalName (Ljava/lang/String;)Ljava/lang/String;
|
||||
public static final fun toJvmInternalName (Ljava/lang/String;)Ljava/lang/String;
|
||||
}
|
||||
|
||||
public final class kotlinx/metadata/jvm/JvmMethodSignature : kotlinx/metadata/jvm/JvmMemberSignature {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@@ -8,16 +8,22 @@
|
||||
package kotlinx.metadata.jvm
|
||||
|
||||
import kotlinx.metadata.ClassName
|
||||
import kotlinx.metadata.isLocal
|
||||
import kotlinx.metadata.isLocalClassName
|
||||
|
||||
/**
|
||||
* JVM internal name of the class, where package names are separated by '/', and class names are separated by '$',
|
||||
* for example: `"org/foo/bar/Baz$Nested"`
|
||||
* Converts [this] to a JVM internal name of the class, where package names are separated by '/', and class names are separated by '$',
|
||||
* for example: `"org/foo/bar/Baz.Nested"` -> `"org/foo/bar/Baz$Nested"`
|
||||
*/
|
||||
val ClassName.jvmInternalName: String
|
||||
get() =
|
||||
if (this.isLocal) substring(1)
|
||||
else replace('.', '$')
|
||||
fun ClassName.toJvmInternalName(): String =
|
||||
if (this.isLocalClassName()) substring(1)
|
||||
else replace('.', '$')
|
||||
|
||||
@Deprecated(
|
||||
"Renamed to toJvmInternalName() to avoid confusion with String properties",
|
||||
ReplaceWith("toJvmInternalName()"),
|
||||
level = DeprecationLevel.WARNING
|
||||
)
|
||||
val ClassName.jvmInternalName: String get() = toJvmInternalName()
|
||||
|
||||
/**
|
||||
* Helper function to instantiate [Metadata].
|
||||
|
||||
@@ -139,14 +139,14 @@ class MetadataSmokeTest {
|
||||
className
|
||||
}
|
||||
assertEquals(".kotlinx/metadata/test/MetadataSmokeTest\$jvmInternalName\$L", l)
|
||||
assertEquals("kotlinx/metadata/test/MetadataSmokeTest\$jvmInternalName\$L", l.jvmInternalName)
|
||||
assertEquals("kotlinx/metadata/test/MetadataSmokeTest\$jvmInternalName\$L", l.toJvmInternalName())
|
||||
|
||||
val coroutineContextKey = ClassNameReader().run {
|
||||
(KotlinClassMetadata.read(CoroutineContext.Key::class.java.readMetadata()) as KotlinClassMetadata.Class).accept(this)
|
||||
className
|
||||
}
|
||||
assertEquals("kotlin/coroutines/CoroutineContext.Key", coroutineContextKey)
|
||||
assertEquals("kotlin/coroutines/CoroutineContext\$Key", coroutineContextKey.jvmInternalName)
|
||||
assertEquals("kotlin/coroutines/CoroutineContext\$Key", coroutineContextKey.toJvmInternalName())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@@ -18,5 +18,16 @@ package kotlinx.metadata
|
||||
*/
|
||||
typealias ClassName = String // Not a value class because of Java usages
|
||||
|
||||
val ClassName.isLocal: Boolean
|
||||
get() = this.startsWith(".")
|
||||
/**
|
||||
* Checks whether a class name [this] represents a local class or an anonymous object.
|
||||
*
|
||||
* A class name represents a local class or an anonymous object if it starts with '.' (dot).
|
||||
*/
|
||||
fun ClassName.isLocalClassName(): Boolean = this.startsWith(".")
|
||||
|
||||
@Deprecated(
|
||||
"Renamed to isLocalClassName() to avoid confusion with String properties",
|
||||
ReplaceWith("isLocalClassName()"),
|
||||
level = DeprecationLevel.WARNING
|
||||
)
|
||||
val ClassName.isLocal: Boolean get() = isLocalClassName()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
|
||||
@@ -8,7 +8,7 @@ package kotlinx.metadata.internal
|
||||
import kotlinx.metadata.ClassName
|
||||
import kotlinx.metadata.KmAnnotation
|
||||
import kotlinx.metadata.KmAnnotationArgument
|
||||
import kotlinx.metadata.isLocal
|
||||
import kotlinx.metadata.isLocalClassName
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||
import org.jetbrains.kotlin.metadata.serialization.StringTable
|
||||
@@ -107,7 +107,7 @@ fun KmAnnotationArgument.writeAnnotationArgument(strings: StringTable): ProtoBuf
|
||||
}
|
||||
|
||||
internal fun StringTable.getClassNameIndex(name: ClassName): Int =
|
||||
if (name.isLocal)
|
||||
if (name.isLocalClassName())
|
||||
getQualifiedClassNameIndex(name.substring(1), true)
|
||||
else
|
||||
getQualifiedClassNameIndex(name, false)
|
||||
|
||||
Reference in New Issue
Block a user