Add module name JVM extensions to class/package in kotlinx-metadata-jvm
#KT-31308 Fixed
This commit is contained in:
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.load.java;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.builtins.CompanionObjectMapping;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -43,7 +44,7 @@ public final class JvmAbi {
|
||||
public static final String INSTANCE_FIELD = "INSTANCE";
|
||||
public static final String HIDDEN_INSTANCE_FIELD = "$$" + INSTANCE_FIELD;
|
||||
|
||||
public static final String DEFAULT_MODULE_NAME = "main";
|
||||
public static final String DEFAULT_MODULE_NAME = JvmProtoBufUtil.DEFAULT_MODULE_NAME;
|
||||
public static final ClassId REFLECTION_FACTORY_IMPL = ClassId.topLevel(new FqName("kotlin.reflect.jvm.internal.ReflectionFactoryImpl"));
|
||||
|
||||
public static final String LOCAL_VARIABLE_NAME_PREFIX_INLINE_ARGUMENT = "$i$a$";
|
||||
|
||||
+2
@@ -20,6 +20,8 @@ object JvmProtoBufUtil {
|
||||
|
||||
const val PLATFORM_TYPE_ID = "kotlin.jvm.PlatformType"
|
||||
|
||||
const val DEFAULT_MODULE_NAME = "main"
|
||||
|
||||
@JvmStatic
|
||||
fun readClassDataFrom(data: Array<String>, strings: Array<String>): Pair<JvmNameResolver, ProtoBuf.Class> =
|
||||
readClassDataFrom(BitEncoding.decodeBytes(data), strings)
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# kotlinx-metadata-jvm
|
||||
|
||||
## 0.0.6
|
||||
|
||||
- [`KT-31308`](https://youtrack.jetbrains.com/issue/KT-31308) Add module name extensions to kotlinx-metadata-jvm
|
||||
|
||||
## 0.0.5
|
||||
|
||||
- [`KT-25371`](https://youtrack.jetbrains.com/issue/KT-25371) Support unsigned integers in kotlinx-metadata-jvm
|
||||
|
||||
@@ -29,6 +29,8 @@ internal class JvmMetadataExtensions : MetadataExtensions {
|
||||
)?.let { property.accept(it, c) }
|
||||
}
|
||||
|
||||
ext.visitModuleName(proto.getExtensionOrNull(JvmProtoBuf.classModuleName)?.let(c::get) ?: JvmProtoBufUtil.DEFAULT_MODULE_NAME)
|
||||
|
||||
ext.visitEnd()
|
||||
}
|
||||
|
||||
@@ -41,6 +43,8 @@ internal class JvmMetadataExtensions : MetadataExtensions {
|
||||
)?.let { property.accept(it, c) }
|
||||
}
|
||||
|
||||
ext.visitModuleName(proto.getExtensionOrNull(JvmProtoBuf.packageModuleName)?.let(c::get) ?: JvmProtoBufUtil.DEFAULT_MODULE_NAME)
|
||||
|
||||
ext.visitEnd()
|
||||
}
|
||||
|
||||
@@ -111,6 +115,12 @@ internal class JvmMetadataExtensions : MetadataExtensions {
|
||||
): KmPropertyVisitor = writeProperty(c, flags, name, getterFlags, setterFlags) {
|
||||
proto.addExtension(JvmProtoBuf.classLocalVariable, it.build())
|
||||
}
|
||||
|
||||
override fun visitModuleName(name: String) {
|
||||
if (name != JvmProtoBufUtil.DEFAULT_MODULE_NAME) {
|
||||
proto.setExtension(JvmProtoBuf.classModuleName, c[name])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +134,12 @@ internal class JvmMetadataExtensions : MetadataExtensions {
|
||||
): KmPropertyVisitor = writeProperty(c, flags, name, getterFlags, setterFlags) {
|
||||
proto.addExtension(JvmProtoBuf.packageLocalVariable, it.build())
|
||||
}
|
||||
|
||||
override fun visitModuleName(name: String) {
|
||||
if (name != JvmProtoBufUtil.DEFAULT_MODULE_NAME) {
|
||||
proto.setExtension(JvmProtoBuf.packageModuleName, c[name])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,13 @@ abstract class JvmDeclarationContainerExtensionVisitor @JvmOverloads constructor
|
||||
*/
|
||||
open fun visitLocalDelegatedProperty(flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags): KmPropertyVisitor? =
|
||||
delegate?.visitLocalDelegatedProperty(flags, name, getterFlags, setterFlags)
|
||||
|
||||
/**
|
||||
* Visits the name of the module where this container is declared.
|
||||
*/
|
||||
open fun visitModuleName(name: String) {
|
||||
delegate?.visitModuleName(name)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -514,7 +514,11 @@ private fun StringBuilder.appendFlags(flags: Flags, map: Map<Flag, String>) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendLocalDelegatedProperties(localDelegatedProperties: List<StringBuilder>) {
|
||||
private fun StringBuilder.appendDeclarationContainerExtensions(
|
||||
settings: KotlinpSettings,
|
||||
localDelegatedProperties: List<StringBuilder>,
|
||||
moduleName: String?
|
||||
) {
|
||||
for ((i, sb) in localDelegatedProperties.withIndex()) {
|
||||
appendln()
|
||||
appendln(" // local delegated property #$i")
|
||||
@@ -527,6 +531,11 @@ private fun StringBuilder.appendLocalDelegatedProperties(localDelegatedPropertie
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.isVerbose && moduleName != null) {
|
||||
appendln()
|
||||
appendln(" // module name: $moduleName")
|
||||
}
|
||||
}
|
||||
|
||||
interface AbstractPrinter<in T : KotlinClassMetadata> {
|
||||
@@ -615,6 +624,7 @@ class ClassPrinter(private val settings: KotlinpSettings) : KmClassVisitor(), Ab
|
||||
if (type != JvmClassExtensionVisitor.TYPE) return null
|
||||
return object : JvmClassExtensionVisitor() {
|
||||
private val localDelegatedProperties = mutableListOf<StringBuilder>()
|
||||
private var moduleName: String? = null
|
||||
|
||||
override fun visitAnonymousObjectOriginName(internalName: String) {
|
||||
anonymousObjectOriginName = internalName
|
||||
@@ -626,8 +636,12 @@ class ClassPrinter(private val settings: KotlinpSettings) : KmClassVisitor(), Ab
|
||||
settings, StringBuilder().also { localDelegatedProperties.add(it) }, flags, name, getterFlags, setterFlags
|
||||
)
|
||||
|
||||
override fun visitModuleName(name: String) {
|
||||
moduleName = name
|
||||
}
|
||||
|
||||
override fun visitEnd() {
|
||||
sb.appendLocalDelegatedProperties(localDelegatedProperties)
|
||||
sb.appendDeclarationContainerExtensions(settings, localDelegatedProperties, moduleName)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -660,6 +674,7 @@ abstract class PackagePrinter(private val settings: KotlinpSettings) : KmPackage
|
||||
if (type != JvmPackageExtensionVisitor.TYPE) return null
|
||||
return object : JvmPackageExtensionVisitor() {
|
||||
private val localDelegatedProperties = mutableListOf<StringBuilder>()
|
||||
private var moduleName: String? = null
|
||||
|
||||
override fun visitLocalDelegatedProperty(
|
||||
flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags
|
||||
@@ -668,7 +683,7 @@ abstract class PackagePrinter(private val settings: KotlinpSettings) : KmPackage
|
||||
)
|
||||
|
||||
override fun visitEnd() {
|
||||
sb.appendLocalDelegatedProperties(localDelegatedProperties)
|
||||
sb.appendDeclarationContainerExtensions(settings, localDelegatedProperties, moduleName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +125,8 @@ public final annotation class A : kotlin/Annotation {
|
||||
// getter: za()[Z
|
||||
public final val za: kotlin/BooleanArray
|
||||
public final get
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// B.class
|
||||
// ------------------------------------------
|
||||
@@ -136,6 +138,8 @@ public final annotation class B : kotlin/Annotation {
|
||||
// getter: value()Ljava/lang/String;
|
||||
public final val value: kotlin/String
|
||||
public final get
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// C.class
|
||||
// ------------------------------------------
|
||||
@@ -149,6 +153,8 @@ public final class C : kotlin/Any {
|
||||
|
||||
// signature: returnTypeAnnotation()V
|
||||
public final fun returnTypeAnnotation(): @A(z = true, c = 'x', b = 1.toByte(), s = 42.toShort(), i = 42424242, f = -2.72f, j = 239239239239239L, d = 3.14, ui = 1u, ub = 255.toUByte(), us = 3.toUShort(), ul = 4uL, ui_max = 4294967295u, ub_max = 255.toUByte(), us_max = 65535.toUShort(), ul_max = 18446744073709551615uL, za = [true], ca = ['\''], ba = [1.toByte()], sa = [42.toShort()], ia = [42424242], fa = [-2.72f], ja = [239239239239239L], da = [3.14], str = "aba\ncaba'\"\t\u0001\u0002ꙮ", enum = kotlin/annotation/AnnotationTarget.CLASS, klass = C::class, anno = B(value = "aba\ncaba'\"\t\u0001\u0002ꙮ")) kotlin/Unit
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// JvmNamed.class
|
||||
// ------------------------------------------
|
||||
@@ -160,6 +166,8 @@ public final annotation class JvmNamed : kotlin/Annotation {
|
||||
// getter: uglyJvmName()Ljava/lang/String;
|
||||
public final val value: kotlin/String
|
||||
public final get
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
// ------------------------------------------
|
||||
|
||||
@@ -4,6 +4,8 @@ public final class A : kotlin/Any {
|
||||
|
||||
// signature: <init>()V
|
||||
public /* primary */ constructor()
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// A$L.class
|
||||
// ------------------------------------------
|
||||
@@ -16,6 +18,8 @@ local final class .A$L<T#0 /* T */> : kotlin/Any {
|
||||
public final fun x(l: .A$L<.A$L<T#0>.I>): kotlin/Unit
|
||||
|
||||
// nested class: I
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// A$L$I.class
|
||||
// ------------------------------------------
|
||||
@@ -23,6 +27,8 @@ local final inner class .A$L.I : kotlin/Any {
|
||||
|
||||
// signature: <init>(LA$L;)V
|
||||
public /* primary */ constructor()
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
// ------------------------------------------
|
||||
|
||||
@@ -19,6 +19,8 @@ public final class Class : kotlin/Any {
|
||||
// local delegated property #2
|
||||
// local final /* delegated */ val local6: kotlin/Int
|
||||
// local final get
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// Class$f$1.class
|
||||
// ------------------------------------------
|
||||
@@ -41,6 +43,8 @@ public final class Delegate<T#0 /* T */> : kotlin/Any {
|
||||
// getter: getValue()Ljava/lang/Object;
|
||||
public final val value: T#0?
|
||||
public final get
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// LocalDelegatedPropertiesKt.class
|
||||
// ------------------------------------------
|
||||
|
||||
@@ -7,16 +7,22 @@ public abstract interface A : kotlin/Any {
|
||||
// nested class: B
|
||||
|
||||
// nested class: D
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// A$B.class
|
||||
// ------------------------------------------
|
||||
public abstract interface A.B : kotlin/Any {
|
||||
|
||||
// nested class: C
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// A$B$C.class
|
||||
// ------------------------------------------
|
||||
public abstract interface A.B.C : kotlin/Any {
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// A$D.class
|
||||
// ------------------------------------------
|
||||
@@ -28,6 +34,8 @@ public final companion object A.D : kotlin/Any {
|
||||
// nested class: E
|
||||
|
||||
// nested class: F
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// A$D$E.class
|
||||
// ------------------------------------------
|
||||
@@ -39,6 +47,8 @@ public final enum class A.D.E : kotlin/Enum<A.D.E> {
|
||||
E1,
|
||||
|
||||
E2,
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// A$D$F.class
|
||||
// ------------------------------------------
|
||||
@@ -50,6 +60,8 @@ public sealed class A.D.F : kotlin/Any {
|
||||
// nested class: G
|
||||
|
||||
// sealed subclass: A.D.F.G
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// A$D$F$G.class
|
||||
// ------------------------------------------
|
||||
@@ -57,6 +69,8 @@ public final class A.D.F.G : A.D.F {
|
||||
|
||||
// signature: <init>()V
|
||||
public /* primary */ constructor()
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
// ------------------------------------------
|
||||
|
||||
@@ -10,6 +10,8 @@ public final class PlatformType : kotlin/Any {
|
||||
|
||||
// signature: nullability()Ljava/io/File;
|
||||
public final fun nullability(): java/io/File!
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
// ------------------------------------------
|
||||
|
||||
@@ -34,6 +34,8 @@ public final class C : kotlin/Any {
|
||||
// getter: getDelegated(Ljava/lang/Number;)Ljava/util/List;
|
||||
public final /* delegated */ val <T#0 /* T */ : kotlin/Number> T#0.delegated: kotlin/collections/List<kotlin/Nothing>
|
||||
public final /* non-default */ get
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
// ------------------------------------------
|
||||
|
||||
@@ -26,6 +26,8 @@ public final class SimpleClass<in T#0 /* A */> : kotlin/Any {
|
||||
public final var x: kotlin/Long
|
||||
public final /* non-default */ external get
|
||||
public final /* non-default */ set(<set-?>: kotlin/Long)
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
// ------------------------------------------
|
||||
|
||||
@@ -9,6 +9,8 @@ public final class A<T#0 /* T */> : kotlin/Any {
|
||||
public final fun <T#1 /* T */> a(t: T#1): kotlin/Unit
|
||||
|
||||
// nested class: B
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// A$B.class
|
||||
// ------------------------------------------
|
||||
@@ -24,6 +26,8 @@ public final inner class A.B<T#1 /* U */, T#2 /* V */ : T#1> : kotlin/Any {
|
||||
public final fun bb(t: T#0): kotlin/Unit
|
||||
|
||||
// nested class: C
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// A$B$C.class
|
||||
// ------------------------------------------
|
||||
@@ -40,6 +44,8 @@ public final inner class A.B.C<T#3 /* T */, T#4 /* U */> : kotlin/Any {
|
||||
|
||||
// signature: z(LA$B$C;)V
|
||||
public final fun z(c: A<kotlin/Int>.B<kotlin/Any, kotlin/Byte>.C<kotlin/Unit, kotlin/Long>): kotlin/Unit
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
// ------------------------------------------
|
||||
|
||||
@@ -5,6 +5,8 @@ public final class test/Klass : kotlin/Any {
|
||||
|
||||
// signature: <init>()V
|
||||
public /* primary */ constructor()
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// test/Konstructor.class
|
||||
// ------------------------------------------
|
||||
@@ -13,6 +15,8 @@ public final class test/Konstructor : kotlin/Any {
|
||||
// requires language version 42.0.0 (level=WARNING, errorCode=42, message="Konstructor must not be used!")
|
||||
// signature: <init>()V
|
||||
public /* primary */ constructor()
|
||||
|
||||
// module name: test-module
|
||||
}
|
||||
// test/VersionRequirementKt.class
|
||||
// ------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user