diff --git a/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/KotlinClassMetadata.kt b/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/KotlinClassMetadata.kt index 98a8d9294c2..4601e305711 100644 --- a/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/KotlinClassMetadata.kt +++ b/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/KotlinClassMetadata.kt @@ -21,8 +21,8 @@ import kotlin.LazyThreadSafetyMode.PUBLICATION /** * Represents the parsed metadata of a Kotlin JVM class file. * - * To create an instance of [KotlinClassMetadata], first obtain a [KotlinClassHeader] instance by loading the contents - * of the [Metadata] annotation on a class file, and then call [KotlinClassMetadata.read]. + * To create an instance of [KotlinClassMetadata], first obtain an instance of [Metadata] annotation on a class file, and then call [KotlinClassMetadata.read]. + * [Metadata] annotation can be obtained either via reflection or created from data from a binary class file, using its constructor or helper function. */ sealed class KotlinClassMetadata(val header: Metadata) { /** @@ -46,7 +46,7 @@ sealed class KotlinClassMetadata(val header: Metadata) { * * @param v the visitor that must visit this class */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(v: KmClassVisitor) { val (strings, proto) = classData proto.accept(v, strings) @@ -56,22 +56,20 @@ sealed class KotlinClassMetadata(val header: Metadata) { * A [KmClassVisitor] that generates the metadata of a Kotlin class. */ @Deprecated( - writerApiMessage, - ReplaceWith("KotlinClassMetadata.writeClass(kmClass, metadataVersion, extraInt)"), + "$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeClass(kmClass, metadataVersion, extraInt)", ) class Writer : ClassWriter(JvmStringTable()) { /** * Returns the metadata of the class that was written with this writer. * - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ @JvmOverloads @Deprecated( - writerApiMessage, - ReplaceWith("KotlinClassMetadata.writeClass(kmClass, metadataVersion, extraInt)"), + "$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeClass(kmClass, metadataVersion, extraInt)", ) fun write( metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION, @@ -106,7 +104,7 @@ sealed class KotlinClassMetadata(val header: Metadata) { * * @param v the visitor that must visit this file facade */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(v: KmPackageVisitor) { val (strings, proto) = packageData proto.accept(v, strings) @@ -116,22 +114,20 @@ sealed class KotlinClassMetadata(val header: Metadata) { * A [KmPackageVisitor] that generates the metadata of a Kotlin file facade. */ @Deprecated( - visitorApiMessage, - ReplaceWith("KotlinClassMetadata.writeFileFacade(kmPackage, metadataVersion, extraInt)") + "$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeFileFacade(kmPackage, metadataVersion, extraInt)", ) class Writer : PackageWriter(JvmStringTable()) { /** * Returns the metadata of the file facade that was written with this writer. * - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ @JvmOverloads @Deprecated( - visitorApiMessage, - ReplaceWith("KotlinClassMetadata.writeFileFacade(kmPackage, metadataVersion, extraInt)") + "$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeFileFacade(kmPackage, metadataVersion, extraInt)", ) fun write( metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION, @@ -178,7 +174,7 @@ sealed class KotlinClassMetadata(val header: Metadata) { * * @param v the visitor that must visit this lambda */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(v: KmLambdaVisitor) { if (!isLambda) throw IllegalStateException( "accept(KmLambdaVisitor) is only possible for synthetic classes which are lambdas (isLambda = true)" @@ -194,20 +190,20 @@ sealed class KotlinClassMetadata(val header: Metadata) { * the resulting metadata will represent a _non-lambda_ synthetic class. */ @Deprecated( - "Visitor API is deprecated as excessive and cumbersome. Please use KotlinClassMetadata.writeLambda(kmLambda, metadataVersion, extraInt) " + + WRITER_API_MESSAGE + ": KotlinClassMetadata.writeLambda(kmLambda, metadataVersion, extraInt) " + "or KotlinClassMetadata.writeSyntheticClass(metadataVersion, extraInt) for a non-lambda synthetic class", ) class Writer : LambdaWriter(JvmStringTable()) { /** * Returns the metadata of the synthetic class that was written with this writer. * - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ @Deprecated( - "Visitor API is deprecated as excessive and cumbersome. Please use KotlinClassMetadata.writeLambda(kmLambda, metadataVersion, extraInt) " + + WRITER_API_MESSAGE + ": KotlinClassMetadata.writeLambda(kmLambda, metadataVersion, extraInt) " + "or KotlinClassMetadata.writeSyntheticClass(metadataVersion, extraInt) for a non-lambda synthetic class", ) @JvmOverloads @@ -241,22 +237,20 @@ sealed class KotlinClassMetadata(val header: Metadata) { * A writer that generates the metadata of a multi-file class facade. */ @Deprecated( - writerApiMessage, - ReplaceWith("KotlinClassMetadata.writeMultiFileClassFacade(partClassNames, metadataVersion, extraInt)"), + "$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeMultiFileClassFacade(partClassNames, metadataVersion, extraInt)", ) class Writer { /** * Returns the metadata of the multi-file class facade that was written with this writer. * * @param partClassNames JVM internal names of the part classes which this multi-file class combines - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ @Deprecated( - writerApiMessage, - ReplaceWith("KotlinClassMetadata.writeMultiFileClassFacade(partClassNames, metadataVersion, extraInt)"), + "$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeMultiFileClassFacade(partClassNames, metadataVersion, extraInt)", ) @JvmOverloads fun write( @@ -304,7 +298,7 @@ sealed class KotlinClassMetadata(val header: Metadata) { * * @param v the visitor that must visit this multi-file class part */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(v: KmPackageVisitor) { val (strings, proto) = packageData proto.accept(v, strings) @@ -314,22 +308,20 @@ sealed class KotlinClassMetadata(val header: Metadata) { * A [KmPackageVisitor] that generates the metadata of a multi-file class part. */ @Deprecated( - writerApiMessage, - ReplaceWith("KotlinClassMetadata.writeMultiFileClassPart(kmPackage, facadeClassName, metadataVersion, extraInt)") + "$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeMultiFileClassPart(kmPackage, facadeClassName, metadataVersion, extraInt)" ) class Writer : PackageWriter(JvmStringTable()) { /** * Returns the metadata of the multi-file class part that was written with this writer. * * @param facadeClassName JVM internal name of the corresponding multi-file class facade - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ @Deprecated( - writerApiMessage, - ReplaceWith("KotlinClassMetadata.writeMultiFileClassPart(kmPackage, facadeClassName, metadataVersion, extraInt)") + "$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeMultiFileClassPart(kmPackage, facadeClassName, metadataVersion, extraInt)" ) @JvmOverloads fun write( @@ -357,9 +349,9 @@ sealed class KotlinClassMetadata(val header: Metadata) { /** * Writes contents of [kmClass] as the class metadata. * - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ fun writeClass( @@ -371,9 +363,9 @@ sealed class KotlinClassMetadata(val header: Metadata) { /** * Writes [kmPackage] contents as the file facade metadata. * - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ fun writeFileFacade( @@ -385,9 +377,9 @@ sealed class KotlinClassMetadata(val header: Metadata) { /** * Writes [kmLambda] as the synthetic class metadata. * - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ fun writeLambda( @@ -399,9 +391,9 @@ sealed class KotlinClassMetadata(val header: Metadata) { /** * Writes synthetic class metadata. * - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ fun writeSyntheticClass( @@ -413,9 +405,9 @@ sealed class KotlinClassMetadata(val header: Metadata) { * Writes metadata of the multi-file class facade. * * @param partClassNames JVM internal names of the part classes which this multi-file class combines - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ fun writeMultiFileClassFacade( @@ -427,9 +419,9 @@ sealed class KotlinClassMetadata(val header: Metadata) { * Writes the metadata of the multi-file class part. * * @param facadeClassName JVM internal name of the corresponding multi-file class facade - * @param metadataVersion metadata version to be written to the metadata (see [KotlinClassHeader.metadataVersion]), + * @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]), * [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default. Cannot be less (lexicographically) than `[1, 4]` - * @param extraInt the value of the class-level flags to be written to the metadata (see [KotlinClassHeader.extraInt]), + * @param extraInt the value of the class-level flags to be written to the metadata (see [Metadata.extraInt]), * 0 by default */ fun writeMultiFileClassPart( @@ -531,8 +523,8 @@ sealed class KotlinClassMetadata(val header: Metadata) { } } -internal const val visitorApiMessage = +internal const val VISITOR_API_MESSAGE = "Visitor API is deprecated as excessive and cumbersome. Please use nodes (such as KmClass) and their properties." -internal const val writerApiMessage = - "Visitor API is deprecated as excessive and cumbersome. Please use companion functions on KotlinClassMetadata, such as KotlinClassMetadata.writeClass." \ No newline at end of file +internal const val WRITER_API_MESSAGE = + "Visitor Writer API is deprecated as excessive and cumbersome. Please use member functions of KotlinClassMetadata.Companion" \ No newline at end of file diff --git a/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/KotlinModuleMetadata.kt b/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/KotlinModuleMetadata.kt index 5daa709b145..ed860ebdad2 100644 --- a/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/KotlinModuleMetadata.kt +++ b/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/KotlinModuleMetadata.kt @@ -93,7 +93,7 @@ class KotlinModuleMetadata(@Suppress("CanBeParameter", "MemberVisibilityCanBePri * * @param v the visitor that must visit this module file */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(v: KmModuleVisitor) { for ((fqName, parts) in data.packageFqName2Parts) { val (fileFacades, multiFileClassParts) = parts.parts.partition { parts.getMultifileFacadeName(it) == null } @@ -150,7 +150,7 @@ class KotlinModuleMetadata(@Suppress("CanBeParameter", "MemberVisibilityCanBePri * * When using this class, [visitEnd] must be called exactly once and after calls to all other visit* methods. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) abstract class KmModuleVisitor(private val delegate: KmModuleVisitor? = null) { /** * Visits the table of all single- and multi-file facades declared in some package of this module. @@ -220,17 +220,17 @@ class KmModule : KmModuleVisitor() { */ val optionalAnnotationClasses: MutableList = ArrayList(0) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitPackageParts(fqName: String, fileFacades: List, multiFileClassParts: Map) { packageParts[fqName] = KmPackageParts(fileFacades.toMutableList(), multiFileClassParts.toMutableMap()) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitAnnotation(annotation: KmAnnotation) { annotations.add(annotation) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitOptionalAnnotationClass(): KmClass = KmClass().also(optionalAnnotationClasses::add) @@ -239,7 +239,7 @@ class KmModule : KmModuleVisitor() { * * @param visitor the visitor which will visit data in this module. */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmModuleVisitor) { for ((fqName, parts) in packageParts) { visitor.visitPackageParts(fqName, parts.fileFacades, parts.multiFileClassParts) diff --git a/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/impl/JvmMetadataExtensions.kt b/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/impl/JvmMetadataExtensions.kt index 2d554b6c5de..637a38805b2 100644 --- a/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/impl/JvmMetadataExtensions.kt +++ b/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/impl/JvmMetadataExtensions.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.metadata.deserialization.getExtensionOrNull import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil -@Suppress("DEPRECATION", "DEPRECATION_ERROR") +@Suppress("DEPRECATION") internal class JvmMetadataExtensions : MetadataExtensions { override fun readClassExtensions(v: KmClassVisitor, proto: ProtoBuf.Class, c: ReadContext) { val ext = v.visitExtensions(JvmClassExtensionVisitor.TYPE) as? JvmClassExtensionVisitor ?: return diff --git a/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/jvmExtensionVisitors.kt b/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/jvmExtensionVisitors.kt index 5d306a109c9..42e4e0294bc 100644 --- a/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/jvmExtensionVisitors.kt +++ b/libraries/kotlinx-metadata/jvm/src/kotlinx/metadata/jvm/jvmExtensionVisitors.kt @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil /** * A visitor containing the common code to visit JVM extensions for Kotlin declaration containers, such as classes and package fragments. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) abstract class JvmDeclarationContainerExtensionVisitor @JvmOverloads constructor( protected open val delegate: JvmDeclarationContainerExtensionVisitor? = null ) : KmDeclarationContainerExtensionVisitor { @@ -46,7 +46,7 @@ abstract class JvmDeclarationContainerExtensionVisitor @JvmOverloads constructor /** * A visitor to visit JVM extensions for a class. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) open class JvmClassExtensionVisitor @JvmOverloads constructor( delegate: JvmClassExtensionVisitor? = null ) : KmClassExtensionVisitor, JvmDeclarationContainerExtensionVisitor(delegate) { @@ -92,7 +92,7 @@ open class JvmClassExtensionVisitor @JvmOverloads constructor( /** * A visitor to visit JVM extensions for a package fragment. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) open class JvmPackageExtensionVisitor @JvmOverloads constructor( delegate: JvmPackageExtensionVisitor? = null ) : KmPackageExtensionVisitor, JvmDeclarationContainerExtensionVisitor(delegate) { @@ -123,7 +123,7 @@ open class JvmPackageExtensionVisitor @JvmOverloads constructor( /** * A visitor to visit JVM extensions for a function. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) open class JvmFunctionExtensionVisitor @JvmOverloads constructor( private val delegate: JvmFunctionExtensionVisitor? = null ) : KmFunctionExtensionVisitor { @@ -170,7 +170,7 @@ open class JvmFunctionExtensionVisitor @JvmOverloads constructor( /** * A visitor to visit JVM extensions for a property. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) open class JvmPropertyExtensionVisitor @JvmOverloads constructor( private val delegate: JvmPropertyExtensionVisitor? = null ) : KmPropertyExtensionVisitor { @@ -259,7 +259,7 @@ open class JvmPropertyExtensionVisitor @JvmOverloads constructor( /** * A visitor to visit JVM extensions for a constructor. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) open class JvmConstructorExtensionVisitor @JvmOverloads constructor( private val delegate: JvmConstructorExtensionVisitor? = null ) : KmConstructorExtensionVisitor { @@ -291,7 +291,7 @@ open class JvmConstructorExtensionVisitor @JvmOverloads constructor( /** * A visitor to visit JVM extensions for a type parameter. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) open class JvmTypeParameterExtensionVisitor @JvmOverloads constructor( private val delegate: JvmTypeParameterExtensionVisitor? = null ) : KmTypeParameterExtensionVisitor { @@ -328,7 +328,7 @@ open class JvmTypeParameterExtensionVisitor @JvmOverloads constructor( /** * A visitor to visit JVM extensions for a type. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) open class JvmTypeExtensionVisitor @JvmOverloads constructor( private val delegate: JvmTypeExtensionVisitor? = null ) : KmTypeExtensionVisitor { diff --git a/libraries/kotlinx-metadata/jvm/test/kotlinx/metadata/test/MetadataSmokeTest.kt b/libraries/kotlinx-metadata/jvm/test/kotlinx/metadata/test/MetadataSmokeTest.kt index 7f9b463c617..827a4242622 100644 --- a/libraries/kotlinx-metadata/jvm/test/kotlinx/metadata/test/MetadataSmokeTest.kt +++ b/libraries/kotlinx-metadata/jvm/test/kotlinx/metadata/test/MetadataSmokeTest.kt @@ -191,7 +191,6 @@ class MetadataSmokeTest { } @Test - @Suppress("DEPRECATION_ERROR") fun metadataVersionEarlierThan1_4() { val dummy = (KotlinClassMetadata.read(MetadataSmokeTest::class.java.readMetadata()) as KotlinClassMetadata.Class).toKmClass() val mv = intArrayOf(1, 3) diff --git a/libraries/kotlinx-metadata/src/kotlinx/metadata/extensions.kt b/libraries/kotlinx-metadata/src/kotlinx/metadata/extensions.kt index ec9f1a74604..bc8af0b91fe 100644 --- a/libraries/kotlinx-metadata/src/kotlinx/metadata/extensions.kt +++ b/libraries/kotlinx-metadata/src/kotlinx/metadata/extensions.kt @@ -43,7 +43,7 @@ class KmExtensionType(private val klass: KClass) { /** * A base interface for all extension visitors. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmExtensionVisitor { /** * Type of this extension visitor. @@ -54,65 +54,65 @@ interface KmExtensionVisitor { /** * A visitor to visit platform-specific extensions for a declaration container, such as a class or a package fragment. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmDeclarationContainerExtensionVisitor : KmExtensionVisitor /** * A visitor to visit platform-specific extensions for a class. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmClassExtensionVisitor : KmDeclarationContainerExtensionVisitor /** * A visitor to visit platform-specific extensions for a package fragment. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmPackageExtensionVisitor : KmDeclarationContainerExtensionVisitor /** * A visitor to visit platform-specific extensions for a module fragment. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmModuleFragmentExtensionVisitor : KmExtensionVisitor /** * A visitor to visit platform-specific extensions for a function. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmFunctionExtensionVisitor : KmExtensionVisitor /** * A visitor to visit platform-specific extensions for a property. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmPropertyExtensionVisitor : KmExtensionVisitor /** * A visitor to visit platform-specific extensions for a constructor. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmConstructorExtensionVisitor : KmExtensionVisitor /** * A visitor to visit platform-specific extensions for a type parameter. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmTypeParameterExtensionVisitor : KmExtensionVisitor /** * A visitor to visit platform-specific extensions for a type. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmTypeExtensionVisitor : KmExtensionVisitor /** * A visitor to visit platform-specific extensions for a type alias. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmTypeAliasExtensionVisitor : KmExtensionVisitor /** * A visitor to visit platform-specific extensions for a value parameter. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) interface KmValueParameterExtensionVisitor : KmExtensionVisitor diff --git a/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/extensions/MetadataExtensions.kt b/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/extensions/MetadataExtensions.kt index 2972defe38a..c689a08579f 100644 --- a/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/extensions/MetadataExtensions.kt +++ b/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/extensions/MetadataExtensions.kt @@ -11,8 +11,7 @@ import kotlinx.metadata.impl.WriteContext import org.jetbrains.kotlin.metadata.ProtoBuf import java.util.* -// TODO: this intrerface should be marked with @InternalAPI or something -@Suppress("DEPRECATION", "DEPRECATION_ERROR") +@Suppress("DEPRECATION") interface MetadataExtensions { fun readClassExtensions(v: KmClassVisitor, proto: ProtoBuf.Class, c: ReadContext) diff --git a/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/readers.kt b/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/readers.kt index 949a6335eaa..81bbc4c353d 100644 --- a/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/readers.kt +++ b/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/readers.kt @@ -48,7 +48,6 @@ class ReadContext( } } -@Deprecated(visitorApiMessage) @OptIn(ExperimentalContextReceivers::class) fun ProtoBuf.Class.accept( v: KmClassVisitor, @@ -131,7 +130,6 @@ private fun ProtoBuf.Class.loadInlineClassUnderlyingType(c: ReadContext): ProtoB ?.returnType(c.types) } -@Deprecated(visitorApiMessage) fun ProtoBuf.Package.accept( v: KmPackageVisitor, strings: NameResolver, @@ -153,7 +151,6 @@ fun ProtoBuf.Package.accept( v.visitEnd() } -@Deprecated(visitorApiMessage) fun ProtoBuf.PackageFragment.accept( v: KmModuleFragmentVisitor, strings: NameResolver, @@ -200,7 +197,6 @@ private fun KmDeclarationContainerVisitor.visitDeclarations( } } -@Deprecated(visitorApiMessage) fun ProtoBuf.Function.accept(v: KmLambdaVisitor, strings: NameResolver) { val c = ReadContext(strings, TypeTable(typeTable), VersionRequirementTable.EMPTY) @@ -209,7 +205,6 @@ fun ProtoBuf.Function.accept(v: KmLambdaVisitor, strings: NameResolver) { v.visitEnd() } -@Deprecated(visitorApiMessage) private fun ProtoBuf.Constructor.accept(v: KmConstructorVisitor, c: ReadContext) { for (parameter in valueParameterList) { v.visitValueParameter(parameter.flags, c[parameter.name])?.let { parameter.accept(it, c) } @@ -266,7 +261,6 @@ private fun ProtoBuf.Function.accept(v: KmFunctionVisitor, outer: ReadContext) { } @OptIn(ExperimentalContextReceivers::class) -@Deprecated(visitorApiMessage) fun ProtoBuf.Property.accept(v: KmPropertyVisitor, outer: ReadContext) { val c = outer.withTypeParameters(typeParameterList) diff --git a/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/writers.kt b/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/writers.kt index 09abf447ed7..9a998aa7fbc 100644 --- a/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/writers.kt +++ b/libraries/kotlinx-metadata/src/kotlinx/metadata/impl/writers.kt @@ -189,7 +189,6 @@ private fun writeFunction(c: WriteContext, flags: Flags, name: String, output: ( } } -@Deprecated(visitorApiMessage) fun writeProperty( c: WriteContext, flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags, output: (ProtoBuf.Property.Builder) -> Unit ): KmPropertyVisitor = object : KmPropertyVisitor() { @@ -423,7 +422,6 @@ private fun writeEffectExpression(c: WriteContext, output: (ProtoBuf.Expression. } } -@Deprecated(visitorApiMessage) open class ClassWriter(stringTable: StringTable, contextExtensions: List = emptyList()) : KmClassVisitor() { protected val t = ProtoBuf.Class.newBuilder()!! protected val c: WriteContext = WriteContext(stringTable, contextExtensions) @@ -497,7 +495,6 @@ open class ClassWriter(stringTable: StringTable, contextExtensions: List = emptyList()) : KmPackageVisitor() { protected val t = ProtoBuf.Package.newBuilder()!! protected val c: WriteContext = WriteContext(stringTable, contextExtensions) @@ -523,7 +520,6 @@ open class PackageWriter(stringTable: StringTable, contextExtensions: List = emptyList()) : KmModuleFragmentVisitor() { protected val t = ProtoBuf.PackageFragment.newBuilder()!! @@ -549,7 +545,6 @@ open class ModuleFragmentWriter(stringTable: StringTable, contextExtensions: Lis } } -@Deprecated(visitorApiMessage) open class LambdaWriter(stringTable: StringTable) : KmLambdaVisitor() { protected var t: ProtoBuf.Function.Builder? = null protected val c = WriteContext(stringTable) diff --git a/libraries/kotlinx-metadata/src/kotlinx/metadata/internal/common/KotlinCommonMetadata.kt b/libraries/kotlinx-metadata/src/kotlinx/metadata/internal/common/KotlinCommonMetadata.kt index 6a47136dfbe..8d78b0283d1 100644 --- a/libraries/kotlinx-metadata/src/kotlinx/metadata/internal/common/KotlinCommonMetadata.kt +++ b/libraries/kotlinx-metadata/src/kotlinx/metadata/internal/common/KotlinCommonMetadata.kt @@ -14,7 +14,7 @@ import org.jetbrains.kotlin.metadata.builtins.readBuiltinsPackageFragment import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl import java.io.ByteArrayInputStream -// TODO: decide what to with this piece +// TODO: stabilize class KotlinCommonMetadata private constructor(private val proto: ProtoBuf.PackageFragment) { fun toKmModuleFragment(): KmModuleFragment = KmModuleFragment().apply(this::accept) diff --git a/libraries/kotlinx-metadata/src/kotlinx/metadata/nodes.kt b/libraries/kotlinx-metadata/src/kotlinx/metadata/nodes.kt index d1d0a8b0498..30b385b333c 100644 --- a/libraries/kotlinx-metadata/src/kotlinx/metadata/nodes.kt +++ b/libraries/kotlinx-metadata/src/kotlinx/metadata/nodes.kt @@ -119,75 +119,75 @@ class KmClass : KmClassVisitor(), KmDeclarationContainer { private val extensions: List = MetadataExtensions.INSTANCES.map(MetadataExtensions::createClassExtension) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visit(flags: Flags, name: ClassName) { this.flags = flags this.name = name } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor = KmTypeParameter(flags, name, id, variance).addTo(typeParameters) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitSupertype(flags: Flags): KmTypeVisitor = KmType(flags).addTo(supertypes) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor = KmFunction(flags, name).addTo(functions) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitProperty(flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags): KmPropertyVisitor = KmProperty(flags, name, getterFlags, setterFlags).addTo(properties) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor = KmTypeAlias(flags, name).addTo(typeAliases) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitConstructor(flags: Flags): KmConstructorVisitor = KmConstructor(flags).addTo(constructors) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitCompanionObject(name: String) { this.companionObject = name } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitNestedClass(name: String) { nestedClasses.add(name) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitEnumEntry(name: String) { enumEntries.add(name) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitSealedSubclass(name: ClassName) { sealedSubclasses.add(name) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitInlineClassUnderlyingPropertyName(name: String) { inlineClassUnderlyingPropertyName = name } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitInlineClassUnderlyingType(flags: Flags): KmTypeVisitor = KmType(flags).also { inlineClassUnderlyingType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) @ExperimentalContextReceivers override fun visitContextReceiverType(flags: Flags): KmTypeVisitor = KmType(flags).addTo(contextReceiverTypes) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitVersionRequirement(): KmVersionRequirementVisitor = KmVersionRequirement().addTo(versionRequirements) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExtensions(type: KmExtensionType): KmClassExtensionVisitor = extensions.singleOfType(type) @@ -196,7 +196,7 @@ class KmClass : KmClassVisitor(), KmDeclarationContainer { * * @param visitor the visitor which will visit data in this class */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) @OptIn(ExperimentalContextReceivers::class) fun accept(visitor: KmClassVisitor) { visitor.visit(flags, name) @@ -242,19 +242,19 @@ class KmPackage : KmPackageVisitor(), KmDeclarationContainer { private val extensions: List = MetadataExtensions.INSTANCES.map(MetadataExtensions::createPackageExtension) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor = KmFunction(flags, name).addTo(functions) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitProperty(flags: Flags, name: String, getterFlags: Flags, setterFlags: Flags): KmPropertyVisitor = KmProperty(flags, name, getterFlags, setterFlags).addTo(properties) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor = KmTypeAlias(flags, name).addTo(typeAliases) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExtensions(type: KmExtensionType): KmPackageExtensionVisitor = extensions.singleOfType(type) @@ -263,7 +263,7 @@ class KmPackage : KmPackageVisitor(), KmDeclarationContainer { * * @param visitor the visitor which will visit data in this package fragment */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmPackageVisitor) { functions.forEach { visitor.visitFunction(it.flags, it.name)?.let(it::accept) } properties.forEach { visitor.visitProperty(it.flags, it.name, it.getterFlags, it.setterFlags)?.let(it::accept) } @@ -292,15 +292,15 @@ class KmModuleFragment : KmModuleFragmentVisitor() { private val extensions: List = MetadataExtensions.INSTANCES.map(MetadataExtensions::createModuleFragmentExtensions) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitPackage(): KmPackageVisitor? = KmPackage().also { pkg = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExtensions(type: KmExtensionType): KmModuleFragmentExtensionVisitor? = extensions.singleOfType(type) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitClass(): KmClassVisitor? = KmClass().addTo(classes) @@ -309,7 +309,7 @@ class KmModuleFragment : KmModuleFragmentVisitor() { * * @param visitor the visitor which will visit data in the module fragment. */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmModuleFragmentVisitor) { pkg?.let { visitor.visitPackage()?.let(it::accept) } classes.forEach { visitor.visitClass()?.let(it::accept) } @@ -328,7 +328,7 @@ class KmLambda : KmLambdaVisitor() { */ lateinit var function: KmFunction - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor = KmFunction(flags, name).also { function = it } @@ -337,7 +337,7 @@ class KmLambda : KmLambdaVisitor() { * * @param visitor the visitor which will visit data in this lambda */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmLambdaVisitor) { visitor.visitFunction(function.flags, function.name)?.let(function::accept) visitor.visitEnd() @@ -364,15 +364,15 @@ class KmConstructor(var flags: Flags) : KmConstructorVisitor() { private val extensions: List = MetadataExtensions.INSTANCES.map(MetadataExtensions::createConstructorExtension) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitValueParameter(flags: Flags, name: String): KmValueParameterVisitor = KmValueParameter(flags, name).addTo(valueParameters) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitVersionRequirement(): KmVersionRequirementVisitor = KmVersionRequirement().addTo(versionRequirements) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExtensions(type: KmExtensionType): KmConstructorExtensionVisitor = extensions.singleOfType(type) @@ -381,7 +381,7 @@ class KmConstructor(var flags: Flags) : KmConstructorVisitor() { * * @param visitor the visitor which will visit data in this class */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmConstructorVisitor) { valueParameters.forEach { visitor.visitValueParameter(it.flags, it.name)?.let(it::accept) } versionRequirements.forEach { visitor.visitVersionRequirement()?.let(it::accept) } @@ -441,37 +441,37 @@ class KmFunction( private val extensions: List = MetadataExtensions.INSTANCES.map(MetadataExtensions::createFunctionExtension) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor = KmTypeParameter(flags, name, id, variance).addTo(typeParameters) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitReceiverParameterType(flags: Flags): KmTypeVisitor = KmType(flags).also { receiverParameterType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) @ExperimentalContextReceivers override fun visitContextReceiverType(flags: Flags): KmTypeVisitor = KmType(flags).addTo(contextReceiverTypes) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitValueParameter(flags: Flags, name: String): KmValueParameterVisitor = KmValueParameter(flags, name).addTo(valueParameters) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitReturnType(flags: Flags): KmTypeVisitor = KmType(flags).also { returnType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitVersionRequirement(): KmVersionRequirementVisitor = KmVersionRequirement().addTo(versionRequirements) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) @ExperimentalContracts override fun visitContract(): KmContractVisitor = KmContract().also { contract = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExtensions(type: KmExtensionType): KmFunctionExtensionVisitor = extensions.singleOfType(type) @@ -481,7 +481,7 @@ class KmFunction( * @param visitor the visitor which will visit data in this function */ @OptIn(ExperimentalContextReceivers::class) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmFunctionVisitor) { typeParameters.forEach { visitor.visitTypeParameter(it.flags, it.name, it.id, it.variance)?.let(it::accept) } receiverParameterType?.let { visitor.visitReceiverParameterType(it.flags)?.let(it::accept) } @@ -546,32 +546,32 @@ class KmProperty( private val extensions: List = MetadataExtensions.INSTANCES.map(MetadataExtensions::createPropertyExtension) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor = KmTypeParameter(flags, name, id, variance).addTo(typeParameters) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitReceiverParameterType(flags: Flags): KmTypeVisitor = KmType(flags).also { receiverParameterType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) @ExperimentalContextReceivers override fun visitContextReceiverType(flags: Flags): KmTypeVisitor = KmType(flags).addTo(contextReceiverTypes) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitSetterParameter(flags: Flags, name: String): KmValueParameterVisitor = KmValueParameter(flags, name).also { setterParameter = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitReturnType(flags: Flags): KmTypeVisitor = KmType(flags).also { returnType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitVersionRequirement(): KmVersionRequirementVisitor = KmVersionRequirement().addTo(versionRequirements) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExtensions(type: KmExtensionType): KmPropertyExtensionVisitor = extensions.singleOfType(type) @@ -581,7 +581,7 @@ class KmProperty( * @param visitor the visitor which will visit data in this property */ @OptIn(ExperimentalContextReceivers::class) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmPropertyVisitor) { typeParameters.forEach { visitor.visitTypeParameter(it.flags, it.name, it.id, it.variance)?.let(it::accept) } receiverParameterType?.let { visitor.visitReceiverParameterType(it.flags)?.let(it::accept) } @@ -634,28 +634,28 @@ class KmTypeAlias( private val extensions: List = MetadataExtensions.INSTANCES.mapNotNull(MetadataExtensions::createTypeAliasExtension) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitTypeParameter(flags: Flags, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor = KmTypeParameter(flags, name, id, variance).addTo(typeParameters) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitUnderlyingType(flags: Flags): KmTypeVisitor = KmType(flags).also { underlyingType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExpandedType(flags: Flags): KmTypeVisitor = KmType(flags).also { expandedType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitAnnotation(annotation: KmAnnotation) { annotations.add(annotation) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExtensions(type: KmExtensionType): KmTypeAliasExtensionVisitor? = extensions.singleOfType(type) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitVersionRequirement(): KmVersionRequirementVisitor = KmVersionRequirement().addTo(versionRequirements) @@ -664,7 +664,7 @@ class KmTypeAlias( * * @param visitor the visitor which will visit data in this type alias */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmTypeAliasVisitor) { typeParameters.forEach { visitor.visitTypeParameter(it.flags, it.name, it.id, it.variance)?.let(it::accept) } visitor.visitUnderlyingType(underlyingType.flags)?.let(underlyingType::accept) @@ -701,15 +701,15 @@ class KmValueParameter( private val extensions: List = MetadataExtensions.INSTANCES.mapNotNull(MetadataExtensions::createValueParameterExtension) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitType(flags: Flags): KmTypeVisitor = KmType(flags).also { type = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitVarargElementType(flags: Flags): KmTypeVisitor = KmType(flags).also { varargElementType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExtensions(type: KmExtensionType): KmValueParameterExtensionVisitor? = extensions.singleOfType(type) @@ -718,7 +718,7 @@ class KmValueParameter( * * @param visitor the visitor which will visit data in this value parameter */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmValueParameterVisitor) { visitor.visitType(type.flags)?.let(type::accept) varargElementType?.let { visitor.visitVarargElementType(it.flags)?.let(it::accept) } @@ -751,11 +751,11 @@ class KmTypeParameter( private val extensions: List = MetadataExtensions.INSTANCES.map(MetadataExtensions::createTypeParameterExtension) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitUpperBound(flags: Flags): KmTypeVisitor = KmType(flags).addTo(upperBounds) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExtensions(type: KmExtensionType): KmTypeParameterExtensionVisitor? = extensions.singleOfType(type) @@ -764,7 +764,7 @@ class KmTypeParameter( * * @param visitor the visitor which will visit data in this type parameter */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmTypeParameterVisitor) { upperBounds.forEach { visitor.visitUpperBound(it.flags)?.let(it::accept) } extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) } @@ -822,43 +822,43 @@ class KmType(var flags: Flags) : KmTypeVisitor() { private val extensions: List = MetadataExtensions.INSTANCES.map(MetadataExtensions::createTypeExtension) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitClass(name: ClassName) { classifier = KmClassifier.Class(name) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitTypeAlias(name: ClassName) { classifier = KmClassifier.TypeAlias(name) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitTypeParameter(id: Int) { classifier = KmClassifier.TypeParameter(id) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitArgument(flags: Flags, variance: KmVariance): KmTypeVisitor = KmType(flags).also { arguments.add(KmTypeProjection(variance, it)) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitStarProjection() { arguments.add(KmTypeProjection.STAR) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitAbbreviatedType(flags: Flags): KmTypeVisitor = KmType(flags).also { abbreviatedType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitOuterType(flags: Flags): KmTypeVisitor = KmType(flags).also { outerType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitFlexibleTypeUpperBound(flags: Flags, typeFlexibilityId: String?): KmTypeVisitor = KmType(flags).also { flexibleTypeUpperBound = KmFlexibleTypeUpperBound(it, typeFlexibilityId) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitExtensions(type: KmExtensionType): KmTypeExtension = extensions.singleOfType(type) @@ -867,7 +867,7 @@ class KmType(var flags: Flags) : KmTypeVisitor() { * * @param visitor the visitor which will visit data in this type */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmTypeVisitor) { when (val classifier = classifier) { is KmClassifier.Class -> visitor.visitClass(classifier.name) @@ -924,7 +924,7 @@ class KmVersionRequirement : KmVersionRequirementVisitor() { */ lateinit var version: KmVersion - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visit(kind: KmVersionRequirementVersionKind, level: KmVersionRequirementLevel, errorCode: Int?, message: String?) { this.kind = kind this.level = level @@ -932,7 +932,7 @@ class KmVersionRequirement : KmVersionRequirementVisitor() { this.message = message } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitVersion(major: Int, minor: Int, patch: Int) { this.version = KmVersion(major, minor, patch) } @@ -942,7 +942,7 @@ class KmVersionRequirement : KmVersionRequirementVisitor() { * * @param visitor the visitor which will visit data in this version requirement */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmVersionRequirementVisitor) { visitor.visit(kind, level, errorCode, message) visitor.visitVersion(version.major, version.minor, version.patch) @@ -964,7 +964,7 @@ class KmContract : KmContractVisitor() { */ val effects: MutableList = ArrayList(1) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitEffect(type: KmEffectType, invocationKind: KmEffectInvocationKind?): KmEffectVisitor = KmEffect(type, invocationKind).addTo(effects) @@ -973,7 +973,7 @@ class KmContract : KmContractVisitor() { * * @param visitor the visitor which will visit data in this contract */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmContractVisitor) { effects.forEach { visitor.visitEffect(it.type, it.invocationKind)?.let(it::accept) } visitor.visitEnd() @@ -1007,11 +1007,11 @@ class KmEffect( */ var conclusion: KmEffectExpression? = null - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitConstructorArgument(): KmEffectExpressionVisitor = KmEffectExpression().addTo(constructorArguments) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitConclusionOfConditionalEffect(): KmEffectExpressionVisitor = KmEffectExpression().also { conclusion = it } @@ -1020,7 +1020,7 @@ class KmEffect( * * @param visitor the visitor which will visit data in this effect */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmEffectVisitor) { constructorArguments.forEach { visitor.visitConstructorArgument()?.let(it::accept) } conclusion?.let { visitor.visitConclusionOfConditionalEffect()?.let(it::accept) } @@ -1070,26 +1070,26 @@ class KmEffectExpression : KmEffectExpressionVisitor() { */ val orArguments: MutableList = ArrayList(0) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visit(flags: Flags, parameterIndex: Int?) { this.flags = flags this.parameterIndex = parameterIndex } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitConstantValue(value: Any?) { constantValue = KmConstantValue(value) } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitIsInstanceType(flags: Flags): KmTypeVisitor = KmType(flags).also { isInstanceType = it } - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitAndArgument(): KmEffectExpressionVisitor = KmEffectExpression().addTo(andArguments) - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) override fun visitOrArgument(): KmEffectExpressionVisitor = KmEffectExpression().addTo(orArguments) @@ -1098,7 +1098,7 @@ class KmEffectExpression : KmEffectExpressionVisitor() { * * @param visitor the visitor which will visit data in this effect expression */ - @Deprecated(visitorApiMessage) + @Deprecated(VISITOR_API_MESSAGE) fun accept(visitor: KmEffectExpressionVisitor) { visitor.visit(flags, parameterIndex) constantValue?.let { visitor.visitConstantValue(it.value) } diff --git a/libraries/kotlinx-metadata/src/kotlinx/metadata/util.kt b/libraries/kotlinx-metadata/src/kotlinx/metadata/util.kt deleted file mode 100644 index 82bc32682ea..00000000000 --- a/libraries/kotlinx-metadata/src/kotlinx/metadata/util.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2010-2019 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("unused") - -package kotlinx.metadata - -/** - * Assigns the contents of [collection] into this list. After this function completes, the list and [collection] - * will have the same size and will consist of the same elements in the same order. - * - * Useful for rewriting contents of any repeated Km* element represented by a [MutableList], e.g.: - * - * val klass: KmClass - * klass.functions.assignFrom(...) - * - */ -internal fun MutableList.assignFrom(collection: Collection) { - clear() - addAll(collection) -} diff --git a/libraries/kotlinx-metadata/src/kotlinx/metadata/visitors.kt b/libraries/kotlinx-metadata/src/kotlinx/metadata/visitors.kt index e8d2983cf1b..72cb38ea847 100644 --- a/libraries/kotlinx-metadata/src/kotlinx/metadata/visitors.kt +++ b/libraries/kotlinx-metadata/src/kotlinx/metadata/visitors.kt @@ -7,13 +7,13 @@ package kotlinx.metadata import kotlin.contracts.ExperimentalContracts -internal const val visitorApiMessage = +internal const val VISITOR_API_MESSAGE = "Visitor API is deprecated as excessive and cumbersome. Please use nodes (such as KmClass) and their properties." /** * A visitor containing the common code to visit Kotlin declaration containers, such as classes and package fragments. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmDeclarationContainerVisitor @JvmOverloads constructor(protected open val delegate: KmDeclarationContainerVisitor? = null) { /** @@ -61,7 +61,7 @@ abstract class KmDeclarationContainerVisitor @JvmOverloads constructor(protected * When using this class, [visit] must be called first, followed by zero or more [visitTypeParameter] calls, followed by zero or more calls * to other visit* methods, followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmClassVisitor @JvmOverloads constructor(delegate: KmClassVisitor? = null) : KmDeclarationContainerVisitor(delegate) { override val delegate: KmClassVisitor? @@ -194,7 +194,7 @@ abstract class KmClassVisitor @JvmOverloads constructor(delegate: KmClassVisitor * * When using this class, [visitEnd] must be called exactly once and after calls to all other visit* methods. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmPackageVisitor @JvmOverloads constructor(delegate: KmPackageVisitor? = null) : KmDeclarationContainerVisitor(delegate) { override val delegate: KmPackageVisitor? @@ -222,7 +222,7 @@ abstract class KmPackageVisitor @JvmOverloads constructor(delegate: KmPackageVis * * When using this class, [visitEnd] must be called exactly once and after calls to all other visit* methods. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmModuleFragmentVisitor @JvmOverloads constructor(private val delegate: KmModuleFragmentVisitor? = null) { @@ -259,7 +259,7 @@ abstract class KmModuleFragmentVisitor @JvmOverloads constructor(private val del * * When using this class, [visitFunction] must be called first, followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmLambdaVisitor @JvmOverloads constructor(private val delegate: KmLambdaVisitor? = null) { /** @@ -284,7 +284,7 @@ abstract class KmLambdaVisitor @JvmOverloads constructor(private val delegate: K * * When using this class, [visitEnd] must be called exactly once and after calls to all other visit* methods. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmConstructorVisitor @JvmOverloads constructor(private val delegate: KmConstructorVisitor? = null) { /** @@ -324,7 +324,7 @@ abstract class KmConstructorVisitor @JvmOverloads constructor(private val delega * When using this class, zero or more calls to [visitTypeParameter] must be done first, followed by zero or more calls * to other visit* methods, followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmFunctionVisitor @JvmOverloads constructor(private val delegate: KmFunctionVisitor? = null) { /** @@ -408,7 +408,7 @@ abstract class KmFunctionVisitor @JvmOverloads constructor(private val delegate: * When using this class, zero or more calls to [visitTypeParameter] must be done first, followed by zero or more calls * to other visit* methods, followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmPropertyVisitor @JvmOverloads constructor(private val delegate: KmPropertyVisitor? = null) { /** @@ -485,7 +485,7 @@ abstract class KmPropertyVisitor @JvmOverloads constructor(private val delegate: * When using this class, zero or more calls to [visitTypeParameter] must be done first, followed by zero or more calls * to other visit* methods, followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmTypeAliasVisitor @JvmOverloads constructor(private val delegate: KmTypeAliasVisitor? = null) { /** @@ -554,7 +554,7 @@ abstract class KmTypeAliasVisitor @JvmOverloads constructor(private val delegate * When using this class, either [visitType] or [visitVarargElementType] must be called first (depending on whether the value parameter * is `vararg` or not), followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmValueParameterVisitor @JvmOverloads constructor(private val delegate: KmValueParameterVisitor? = null) { /** @@ -594,7 +594,7 @@ abstract class KmValueParameterVisitor @JvmOverloads constructor(private val del * * When using this class, zero or more [visitUpperBound] calls must be done first, followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmTypeParameterVisitor @JvmOverloads constructor(private val delegate: KmTypeParameterVisitor? = null) { /** @@ -632,7 +632,7 @@ abstract class KmTypeParameterVisitor @JvmOverloads constructor(private val dele * * When using this class, [visitEnd] must be called exactly once and after calls to all other visit* methods. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") abstract class KmTypeVisitor @JvmOverloads constructor(private val delegate: KmTypeVisitor? = null) { /** @@ -745,7 +745,7 @@ abstract class KmTypeVisitor @JvmOverloads constructor(private val delegate: KmT * * When using this class, [visit] must be called first, followed by [visitVersion], followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) abstract class KmVersionRequirementVisitor @JvmOverloads constructor(@Suppress("DEPRECATION") private val delegate: KmVersionRequirementVisitor? = null) { /** * Visits the description of this version requirement. @@ -787,7 +787,7 @@ abstract class KmVersionRequirementVisitor @JvmOverloads constructor(@Suppress(" * * When using this class, zero or more calls to [visitEffect] must be done first, followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") @ExperimentalContracts abstract class KmContractVisitor @JvmOverloads constructor(private val delegate: KmContractVisitor? = null) { @@ -818,7 +818,7 @@ abstract class KmContractVisitor @JvmOverloads constructor(private val delegate: * When using this class, zero or more calls to [visitConstructorArgument] or [visitConclusionOfConditionalEffect] must be done first, * followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") @ExperimentalContracts abstract class KmEffectVisitor @JvmOverloads constructor(private val delegate: KmEffectVisitor? = null) { @@ -852,7 +852,7 @@ abstract class KmEffectVisitor @JvmOverloads constructor(private val delegate: K * * When using this class, [visit] must be called first, followed by zero or more calls to other visit* methods, followed by [visitEnd]. */ -@Deprecated(visitorApiMessage) +@Deprecated(VISITOR_API_MESSAGE) @Suppress("DEPRECATION") @ExperimentalContracts abstract class KmEffectExpressionVisitor @JvmOverloads constructor(private val delegate: KmEffectExpressionVisitor? = null) { diff --git a/libraries/tools/kotlinp/test/org/jetbrains/kotlin/kotlinp/test/KotlinpTestUtils.kt b/libraries/tools/kotlinp/test/org/jetbrains/kotlin/kotlinp/test/KotlinpTestUtils.kt index f11bc1151d6..07d292c3b18 100644 --- a/libraries/tools/kotlinp/test/org/jetbrains/kotlin/kotlinp/test/KotlinpTestUtils.kt +++ b/libraries/tools/kotlinp/test/org/jetbrains/kotlin/kotlinp/test/KotlinpTestUtils.kt @@ -129,7 +129,7 @@ private fun transformClassFileWithNodes(classFile: KotlinClassMetadata): KotlinC else -> classFile } -@Suppress("DEPRECATION") +@Suppress("DEPRECATION") // We're testing that reading/writing with KmNodes is identical to direct private fun transformModuleFileWithReadWriteVisitors(moduleFile: KotlinModuleMetadata): KotlinModuleMetadata = KotlinModuleMetadata.Writer().apply(moduleFile::accept).write()