Remove all deprecated API from kotlin-metadata(-jvm).

This includes APIs such as:

- Visitors API
- Obsolete KotlinClassMetadata reading and writing API
- Extension and extension visitors API
- Flags and `class Flag` (a reduced version of it was moved to test sources)
- Various utility methods

Extensions mechanism got reworked with the removal of public visitors; it is
completely internal now with special accessors in kotlinx.metadata.internal
package.

Since `var KmClass.flags` is internal now (instead of being deprecated), special
utility functions with the name `_flagAccess` were added to internal package
for testing purposes.

^KT-63156 Fixed
This commit is contained in:
Leonid Startsev
2024-03-06 20:00:39 +01:00
committed by Space Team
parent e002f07ff5
commit 50331fb149
34 changed files with 563 additions and 4684 deletions
File diff suppressed because it is too large Load Diff
@@ -3,7 +3,6 @@
* 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("DEPRECATION_ERROR") // flags will become internal eventually
@file:JvmName("JvmAttributes")
package kotlin.metadata.jvm
@@ -11,6 +10,7 @@ package kotlin.metadata.jvm
import kotlin.metadata.*
import kotlin.metadata.internal.*
import org.jetbrains.kotlin.metadata.deserialization.Flags
import kotlin.metadata.jvm.internal.jvm
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmFlags as JF
/**
@@ -55,3 +55,16 @@ public var KmClass.isCompiledInCompatibilityMode: Boolean by BooleanFlagDelegate
private fun booleanFlag(f: Flags.BooleanFlagField): FlagImpl =
FlagImpl(f.offset, f.bitWidth, 1)
private var KmProperty.jvmFlags: Int
get() = jvm.jvmFlags
set(value) {
jvm.jvmFlags = value
}
private var KmClass.jvmFlags: Int
get() = jvm.jvmFlags
set(value) {
jvm.jvmFlags = value
}
@@ -1,379 +0,0 @@
/*
* 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.
*/
@file:Suppress("DEPRECATION_ERROR") // delegate implementation
package kotlin.metadata.jvm
import kotlin.metadata.*
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(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public abstract class JvmDeclarationContainerExtensionVisitor @JvmOverloads constructor(
protected open val delegate: JvmDeclarationContainerExtensionVisitor? = null
) : KmDeclarationContainerExtensionVisitor {
/**
* Visits the metadata of a local delegated property used somewhere inside this container (but not in a nested declaration container).
* Note that for classes produced by the Kotlin compiler, such properties will have default accessors.
*
* The order of visited local delegated properties is important. The Kotlin compiler generates the corresponding property's index
* at the call site, so that reflection would be able to load the metadata of the property with that index at runtime.
* If an incorrect index is used, either the `KProperty<*>` object passed to delegate methods will point to the wrong property
* at runtime, or an exception will be thrown.
*
* @param flags property flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag and [Flag.Property] flags
* @param name the name of the property
* @param getterFlags property accessor flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag
* and [Flag.PropertyAccessor] flags
* @param setterFlags property accessor flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag
* and [Flag.PropertyAccessor] flags
*/
public open fun visitLocalDelegatedProperty(flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor? =
delegate?.visitLocalDelegatedProperty(flags, name, getterFlags, setterFlags)
/**
* Visits the name of the module where this container is declared.
*/
public open fun visitModuleName(name: String) {
delegate?.visitModuleName(name)
}
}
/**
* A visitor to visit JVM extensions for a class.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public open class JvmClassExtensionVisitor @JvmOverloads constructor(
delegate: JvmClassExtensionVisitor? = null
) : KmClassExtensionVisitor, JvmDeclarationContainerExtensionVisitor(delegate) {
override val delegate: JvmClassExtensionVisitor?
get() = super.delegate as JvmClassExtensionVisitor?
final override val type: KmExtensionType
get() = TYPE
/**
* Visits the JVM internal name of the original class this anonymous object is copied from. This method is called for
* anonymous objects copied from bodies of inline functions to the use site by the Kotlin compiler.
*/
public open fun visitAnonymousObjectOriginName(internalName: String) {
delegate?.visitAnonymousObjectOriginName(internalName)
}
/**
* Visits the JVM-specific flags of the class, consisting of [JvmFlag.Class] flags.
*/
public open fun visitJvmFlags(flags: Int) {
delegate?.visitJvmFlags(flags)
}
/**
* Visits the end of JVM extensions for the class.
*/
public open fun visitEnd() {
delegate?.visitEnd()
}
public companion object {
/**
* The type of this extension visitor.
*
* @see KmExtensionType
*/
@JvmField
public val TYPE: KmExtensionType = KmExtensionType(JvmClassExtensionVisitor::class)
}
}
/**
* A visitor to visit JVM extensions for a package fragment.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public open class JvmPackageExtensionVisitor @JvmOverloads constructor(
delegate: JvmPackageExtensionVisitor? = null
) : KmPackageExtensionVisitor, JvmDeclarationContainerExtensionVisitor(delegate) {
override val delegate: JvmPackageExtensionVisitor?
get() = super.delegate as JvmPackageExtensionVisitor?
final override val type: KmExtensionType
get() = TYPE
/**
* Visits the end of JVM extensions for the package fragment.
*/
public open fun visitEnd() {
delegate?.visitEnd()
}
public companion object {
/**
* The type of this extension visitor.
*
* @see KmExtensionType
*/
@JvmField
public val TYPE: KmExtensionType = KmExtensionType(JvmPackageExtensionVisitor::class)
}
}
/**
* A visitor to visit JVM extensions for a function.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public open class JvmFunctionExtensionVisitor @JvmOverloads constructor(
private val delegate: JvmFunctionExtensionVisitor? = null
) : KmFunctionExtensionVisitor {
final override val type: KmExtensionType
get() = TYPE
/**
* Visits the JVM signature of the function, or null if the JVM signature of this function is unknown.
*
* Example: `JvmMethodSignature("equals", "(Ljava/lang/Object;)Z")`
*
* @param signature the signature of the function
*/
public open fun visit(signature: JvmMethodSignature?) {
delegate?.visit(signature)
}
/**
* Visits the JVM internal name of the original class the lambda class for this function is copied from.
* This information is present for lambdas copied from bodies of inline functions to the use site by the Kotlin compiler.
*/
public open fun visitLambdaClassOriginName(internalName: String) {
delegate?.visitLambdaClassOriginName(internalName)
}
/**
* Visits the end of JVM extensions for the function.
*/
public open fun visitEnd() {
delegate?.visitEnd()
}
public companion object {
/**
* The type of this extension visitor.
*
* @see KmExtensionType
*/
@JvmField
public val TYPE: KmExtensionType = KmExtensionType(JvmFunctionExtensionVisitor::class)
}
}
/**
* A visitor to visit JVM extensions for a property.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public open class JvmPropertyExtensionVisitor @JvmOverloads constructor(
private val delegate: JvmPropertyExtensionVisitor? = null
) : KmPropertyExtensionVisitor {
final override val type: KmExtensionType
get() = TYPE
/**
* Visits JVM signatures of field and accessors generated for the property.
*
* @param jvmFlags JVM-specific flags of the property, consisting of [JvmFlag.Property] flags
* @param fieldSignature the signature of the backing field of the property, or `null` if this property has no backing field.
* Example: `JvmFieldSignature("X", "Ljava/lang/Object;")`
* @param getterSignature the signature of the property getter, or `null` if this property has no getter or its signature is unknown.
* Example: `JvmMethodSignature("getX", "()Ljava/lang/Object;")`
* @param setterSignature the signature of the property setter, or `null` if this property has no setter or its signature is unknown.
* Example: `JvmMethodSignature("setX", "(Ljava/lang/Object;)V")`
*/
public open fun visit(
jvmFlags: Int,
fieldSignature: JvmFieldSignature?,
getterSignature: JvmMethodSignature?,
setterSignature: JvmMethodSignature?
) {
delegate?.visit(jvmFlags, fieldSignature, getterSignature, setterSignature)
@Suppress("DEPRECATION_ERROR")
visit(fieldSignature, getterSignature, setterSignature)
}
@Deprecated(
"Use visit(Flags, JvmFieldSignature?, JvmMethodSignature?, JvmMethodSignature?) instead.",
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("visit(flagsOf(), fieldSignature, getterSignature, setterSignature)", "kotlinx.metadata.flagsOf")
)
public open fun visit(
fieldSignature: JvmFieldSignature?,
getterSignature: JvmMethodSignature?,
setterSignature: JvmMethodSignature?
) {
@Suppress("DEPRECATION_ERROR")
delegate?.visit(fieldSignature, getterSignature, setterSignature)
}
/**
* Visits the JVM signature of a synthetic method which is generated to store annotations on a property in the bytecode.
*
* Example: `JvmMethodSignature("getX$annotations", "()V")`
*
* @param signature the signature of the synthetic method
*/
public open fun visitSyntheticMethodForAnnotations(signature: JvmMethodSignature?) {
delegate?.visitSyntheticMethodForAnnotations(signature)
}
/**
* Visits the JVM signature of a synthetic method which is generated when a delegated property's delegate object is
* optimized out, e.g. because it is constant; in that case, a copy of that object can be obtained on demand by calling
* this method. It takes the property's receivers as arguments.
*
* Example: `JvmMethodSignature("getX$delegate", "(LMyClass;)LMyDelegate;")`
*
* @param signature the signature of the synthetic method
*/
public open fun visitSyntheticMethodForDelegate(signature: JvmMethodSignature?) {
delegate?.visitSyntheticMethodForDelegate(signature)
}
/**
* Visits the end of JVM extensions for the property.
*/
public open fun visitEnd() {
delegate?.visitEnd()
}
public companion object {
/**
* The type of this extension visitor.
*
* @see KmExtensionType
*/
@JvmField
public val TYPE: KmExtensionType = KmExtensionType(JvmPropertyExtensionVisitor::class)
}
}
/**
* A visitor to visit JVM extensions for a constructor.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public open class JvmConstructorExtensionVisitor @JvmOverloads constructor(
private val delegate: JvmConstructorExtensionVisitor? = null
) : KmConstructorExtensionVisitor {
final override val type: KmExtensionType
get() = TYPE
/**
* Visits the JVM signature of the constructor, or null if the JVM signature of this constructor is unknown.
*
* Example: `JvmMethodSignature("<init>", "(Ljava/lang/Object;)V")`
*
* @param signature the signature of the constructor
*/
public open fun visit(signature: JvmMethodSignature?) {
delegate?.visit(signature)
}
public companion object {
/**
* The type of this extension visitor.
*
* @see KmExtensionType
*/
@JvmField
public val TYPE: KmExtensionType = KmExtensionType(JvmConstructorExtensionVisitor::class)
}
}
/**
* A visitor to visit JVM extensions for a type parameter.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public open class JvmTypeParameterExtensionVisitor @JvmOverloads constructor(
private val delegate: JvmTypeParameterExtensionVisitor? = null
) : KmTypeParameterExtensionVisitor {
final override val type: KmExtensionType
get() = TYPE
/**
* Visits an annotation on the type parameter.
*
* @param annotation the annotation on the type parameter
*/
public open fun visitAnnotation(annotation: KmAnnotation) {
delegate?.visitAnnotation(annotation)
}
/**
* Visits the end of JVM extensions for the type parameter.
*/
public open fun visitEnd() {
delegate?.visitEnd()
}
public companion object {
/**
* The type of this extension visitor.
*
* @see KmExtensionType
*/
@JvmField
public val TYPE: KmExtensionType = KmExtensionType(JvmTypeParameterExtensionVisitor::class)
}
}
/**
* A visitor to visit JVM extensions for a type.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public open class JvmTypeExtensionVisitor @JvmOverloads constructor(
private val delegate: JvmTypeExtensionVisitor? = null
) : KmTypeExtensionVisitor {
final override val type: KmExtensionType
get() = TYPE
/**
* Visits the JVM-specific flags of a type.
*
* @param isRaw whether the type is seen as a raw type in Java
*/
public open fun visit(isRaw: Boolean) {
delegate?.visit(isRaw)
}
/**
* Visits an annotation on the type.
*
* @param annotation the annotation on the type
*/
public open fun visitAnnotation(annotation: KmAnnotation) {
delegate?.visitAnnotation(annotation)
}
/**
* Visits the end of JVM extensions for the type parameter.
*/
public open fun visitEnd() {
delegate?.visitEnd()
}
public companion object {
/**
* The type of this extension visitor.
*
* @see KmExtensionType
*/
@JvmField
public val TYPE: KmExtensionType = KmExtensionType(JvmTypeExtensionVisitor::class)
/**
* The type flexibility id, signifying that the visited type is a JVM platform type.
*
* @see KmTypeVisitor.visitFlexibleTypeUpperBound
*/
public const val PLATFORM_TYPE_ID: String = JvmProtoBufUtil.PLATFORM_TYPE_ID // TODO: move out of deprecated visitor
}
}
@@ -42,19 +42,6 @@ public var KmClass.anonymousObjectOriginName: String?
jvm.anonymousObjectOriginName = value
}
/**
* JVM-specific flags of the class, consisting of [JvmFlag.Class] flags.
*/
@Deprecated(
"Flag API is deprecated. Please use corresponding member extensions on KmClass, such as KmClass.hasMethodBodiesInInterface",
level = DeprecationLevel.ERROR
)
public var KmClass.jvmFlags: Int
get() = jvm.jvmFlags
set(value) {
jvm.jvmFlags = value
}
/**
* Metadata of local delegated properties used somewhere inside this package fragment (but not in any class).
* Note that for classes produced by the Kotlin compiler, such properties will have default accessors.
@@ -97,19 +84,6 @@ public var KmFunction.lambdaClassOriginName: String?
jvm.lambdaClassOriginName = value
}
/**
* JVM-specific flags of the property, consisting of [JvmFlag.Property] flags.
*/
@Deprecated(
"Flag API is deprecated. Please use corresponding member extensions on KmProperty, such as KmProperty.isMovedFromInterfaceCompanion",
level = DeprecationLevel.ERROR
)
public var KmProperty.jvmFlags: Int
get() = jvm.jvmFlags
set(value) {
jvm.jvmFlags = value
}
/**
* JVM signature of the backing field of the property, or `null` if this property has no backing field.
*
@@ -1,70 +0,0 @@
/*
* 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.
*/
@file:Suppress("DEPRECATION_ERROR")
package kotlin.metadata.jvm
import kotlin.metadata.Flag
import org.jetbrains.kotlin.metadata.deserialization.Flags as F
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmFlags as JF
private const val prefix = "Flag API is deprecated. Please use"
/**
* JVM-specific flags in addition to common flags declared in [Flag].
*
* @see Flag
* @see Flags
*/
@Deprecated("$prefix corresponding extensions on Km nodes, such as KmClass.hasMethodBodiesInInterface", level = DeprecationLevel.ERROR)
public object JvmFlag {
/**
* JVM-specific property flags in addition to common property flags declared in [Flag.Property].
*/
@Deprecated("$prefix corresponding extension on KmProperty: KmProperty.isMovedFromInterfaceCompanion", level = DeprecationLevel.ERROR)
public object Property {
/**
* Applied to a property declared in an interface's companion object, signifies that its backing field is declared as a static
* field in the interface. In Kotlin code, this usually happens if the property is annotated with [JvmField].
*
* Has no effect if the property is not declared in a companion object of some interface.
*/
@JvmField
@Deprecated("$prefix KmProperty.isMovedFromInterfaceCompanion", level = DeprecationLevel.ERROR)
public val IS_MOVED_FROM_INTERFACE_COMPANION: Flag = booleanFlag(JF.IS_MOVED_FROM_INTERFACE_COMPANION)
}
/**
* JVM-specific class flags in addition to common class flags declared in [Flag.Class].
*/
@Deprecated("$prefix corresponding extensions on KmClass", level = DeprecationLevel.ERROR)
public object Class {
/**
* Applied to an interface compiled with -Xjvm-default=all or all-compatibility.
*
* Without this flag or a `@JvmDefault` annotation on individual interface methods
* the Kotlin compiler moves all interface method bodies into a nested `DefaultImpls`
* class.
*/
@JvmField
@Deprecated("$prefix KmClass.hasMethodBodiesInInterface", level = DeprecationLevel.ERROR)
public val HAS_METHOD_BODIES_IN_INTERFACE: Flag = booleanFlag(JF.IS_COMPILED_IN_JVM_DEFAULT_MODE)
/**
* Applied to an interface compiled with -Xjvm-default=all-compatibility.
*
* In compatibility mode we generate method bodies directly in the interface,
* but we also generate bridges in a nested `DefaultImpls` class for use by
* clients compiled without all-compatibility.
*/
@JvmField
@Deprecated("$prefix KmClass.isCompiledInCompatibilityMode", level = DeprecationLevel.ERROR)
public val IS_COMPILED_IN_COMPATIBILITY_MODE: Flag = booleanFlag(JF.IS_COMPILED_IN_COMPATIBILITY_MODE)
}
internal fun booleanFlag(f: F.BooleanFlagField): Flag =
Flag(f.offset, f.bitWidth, 1)
}
@@ -26,18 +26,6 @@ public sealed class JvmMemberSignature {
* In case of a field [name] and [descriptor] are concatenated with `:` separator, e.g. `value:Ljava/lang/String;`
*/
abstract override fun toString(): String
// Two following declarations are deprecated since 0.6.1, should be error in 0.7.0+
@Deprecated("Deprecated for removal. Use descriptor instead", ReplaceWith("descriptor"), level = DeprecationLevel.ERROR)
public val desc: String get() = descriptor
@Deprecated(
"asString() is deprecated as redundant. Use toString() instead",
ReplaceWith("toString()"),
level = DeprecationLevel.ERROR
)
public fun asString(): String = toString()
}
/**
@@ -18,14 +18,6 @@ public fun ClassName.toJvmInternalName(): String =
if (this.isLocalClassName()) substring(1)
else replace('.', '$')
// Deprecated since 0.6.1, should be error in 0.7.0+
@Deprecated(
"Renamed to toJvmInternalName() to avoid confusion with String properties",
ReplaceWith("toJvmInternalName()"),
level = DeprecationLevel.ERROR
)
public val ClassName.jvmInternalName: String get() = toJvmInternalName()
/**
* Helper function to instantiate [Metadata].
* Contrary to a direct constructor call, this one accepts nullable parameters to substitute nulls with default values.
@@ -146,40 +146,4 @@ public final class KotlinClassHeader implements Metadata {
}
// TODO: equals, hashCode, etc as in Java Annotation contract?
/**
* Use {@link KotlinClassMetadata#CLASS_KIND} instead
*/
@Deprecated
public static final int CLASS_KIND = 1;
/**
* Use {@link KotlinClassMetadata#FILE_FACADE_KIND} instead
*/
@Deprecated
public static final int FILE_FACADE_KIND = 2;
/**
* Use {@link KotlinClassMetadata#SYNTHETIC_CLASS_KIND} instead
*/
@Deprecated
public static final int SYNTHETIC_CLASS_KIND = 3;
/**
* Use {@link KotlinClassMetadata#MULTI_FILE_CLASS_FACADE_KIND} instead
*/
@Deprecated
public static final int MULTI_FILE_CLASS_FACADE_KIND = 4;
/**
* Use {@link KotlinClassMetadata#MULTI_FILE_CLASS_PART_KIND} instead
*/
@Deprecated
public static final int MULTI_FILE_CLASS_PART_KIND = 5;
/**
* Use {@link kotlinx.metadata.jvm.JvmMetadataVersion#LATEST_STABLE_SUPPORTED} instead
*/
@Deprecated
public static final int[] COMPATIBLE_METADATA_VERSION = Arrays.copyOf(JvmMetadataVersion.INSTANCE.toArray(), 3);
}
@@ -2,19 +2,12 @@
* 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.
*/
@file:Suppress(
"DEPRECATION_ERROR", // Deprecated .accept implementation
"DEPRECATION", // COMPATIBLE_METADATA_VERSION as default param
"UNUSED_PARAMETER" // For deprecated Writer.write
)
package kotlin.metadata.jvm
import kotlin.metadata.*
import kotlin.metadata.internal.*
import kotlin.metadata.jvm.internal.*
import kotlin.metadata.jvm.internal.JvmReadUtils.readMetadataImpl
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion as CompilerMetadataVersion
import org.jetbrains.kotlin.metadata.jvm.serialization.JvmStringTable
import java.util.*
@@ -114,53 +107,6 @@ public sealed class KotlinClassMetadata {
Metadata(CLASS_KIND, version.toIntArray(), d1, d2, extraInt = flags)
}
}
/**
* Returns a new [KmClass] instance created from this class metadata.
*/
@Deprecated(
"To avoid excessive copying, use .kmClass property instead. Note that it returns a view and not a copy.",
ReplaceWith("kmClass"),
DeprecationLevel.ERROR
)
public fun toKmClass(): KmClass = KmClass().also { newKm -> kmClass.accept(newKm) } // defensive copy
/**
* Makes the given visitor visit the metadata of this class.
*
* @param v the visitor that must visit this class
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(v: KmClassVisitor): Unit = kmClass.accept(v)
/**
* A [KmClassVisitor] that generates the metadata of a Kotlin class.
*/
@Deprecated(
"$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeClass(kmClass, metadataVersion, extraInt)",
level = DeprecationLevel.ERROR
)
public 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 [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 [Metadata.extraInt]),
* 0 by default
*/
@JvmOverloads
@Deprecated(
"$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeClass(kmClass, metadataVersion, extraInt)",
level = DeprecationLevel.ERROR
)
public fun write(
metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0
): Class {
error("This method is no longer implemented. Migrate to KotlinClassMetadata.writeClass.")
}
}
}
/**
@@ -206,53 +152,6 @@ public sealed class KotlinClassMetadata {
Metadata(FILE_FACADE_KIND, version.toIntArray(), d1, d2, extraInt = flags)
}
}
/**
* Creates a new [KmPackage] instance from this file facade metadata.
*/
@Deprecated(
"To avoid excessive copying, use .kmPackage property instead. Note that it returns a view and not a copy.",
ReplaceWith("kmPackage"),
DeprecationLevel.ERROR
)
public fun toKmPackage(): KmPackage = KmPackage().also { newPkg -> kmPackage.accept(newPkg) }
/**
* Makes the given visitor visit metadata of this file facade.
*
* @param v the visitor that must visit this file facade
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(v: KmPackageVisitor): Unit = kmPackage.accept(v)
/**
* A [KmPackageVisitor] that generates the metadata of a Kotlin file facade.
*/
@Deprecated(
"$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeFileFacade(kmPackage, metadataVersion, extraInt)",
level = DeprecationLevel.ERROR
)
public 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 [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 [Metadata.extraInt]),
* 0 by default
*/
@JvmOverloads
@Deprecated(
"$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeFileFacade(kmPackage, metadataVersion, extraInt)",
level = DeprecationLevel.ERROR
)
public fun write(
metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0
): FileFacade {
error("This method is no longer implemented. Migrate to KotlinClassMetadata.writeFileFacade.")
}
}
}
/**
@@ -305,67 +204,6 @@ public sealed class KotlinClassMetadata {
*/
public val isLambda: Boolean
get() = kmLambda != null
/**
* Creates a new [KmLambda] instance from this synthetic class metadata.
* Returns `null` if this synthetic class does not represent a lambda.
*/
@Deprecated(
"To avoid excessive copying, use .kmLambda property instead. Note that it returns a view and not a copy.",
ReplaceWith("kmLambda"),
DeprecationLevel.ERROR
)
public fun toKmLambda(): KmLambda? = if (isLambda) KmLambda().apply(this::accept) else null
/**
* Makes the given visitor visit metadata of this file facade if this synthetic class represents a Kotlin lambda
* (`isLambda` == true).
*
* Throws [IllegalArgumentException] if this synthetic class does not represent a Kotlin lambda.
*
* @param v the visitor that must visit this lambda
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(v: KmLambdaVisitor) {
if (!isLambda) throw IllegalArgumentException(
"accept(KmLambdaVisitor) is only possible for synthetic classes which are lambdas (isLambda = true)"
)
kmLambda!!.accept(v)
}
/**
* A [KmLambdaVisitor] that generates the metadata of a synthetic class. To generate metadata of a Kotlin lambda,
* call [Writer.visitFunction] and [Writer.visitEnd] on a newly created instance of this writer. If these methods are not called,
* the resulting metadata will represent a _non-lambda_ synthetic class.
*/
@Deprecated(
WRITER_API_MESSAGE + ": KotlinClassMetadata.writeLambda(kmLambda, metadataVersion, extraInt) " +
"or KotlinClassMetadata.writeSyntheticClass(metadataVersion, extraInt) for a non-lambda synthetic class",
level = DeprecationLevel.ERROR
)
public 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 [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 [Metadata.extraInt]),
* 0 by default
*/
@Deprecated(
WRITER_API_MESSAGE + ": KotlinClassMetadata.writeLambda(kmLambda, metadataVersion, extraInt) " +
"or KotlinClassMetadata.writeSyntheticClass(metadataVersion, extraInt) for a non-lambda synthetic class",
level = DeprecationLevel.ERROR
)
@JvmOverloads
public fun write(
metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0
): SyntheticClass {
error("This method is no longer implemented. Migrate to KotlinClassMetadata.writeLambda or KotlinClassMetadata.writeSyntheticClass.")
}
}
}
/**
@@ -430,37 +268,6 @@ public sealed class KotlinClassMetadata {
partClassNames.toTypedArray<String>(), extraInt = flags
)
}
/**
* A writer that generates the metadata of a multi-file class facade.
*/
@Deprecated(
"$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeMultiFileClassFacade(partClassNames, metadataVersion, extraInt)",
level = DeprecationLevel.ERROR
)
public 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 [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 [Metadata.extraInt]),
* 0 by default
*/
@Deprecated(
"$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeMultiFileClassFacade(partClassNames, metadataVersion, extraInt)",
level = DeprecationLevel.ERROR
)
@JvmOverloads
public fun write(
partClassNames: List<String>,
metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0
): MultiFileClassFacade {
error("This method is no longer implemented. Migrate to KotlinClassMetadata.writeMultiFileClassFacade.")
}
}
}
/**
@@ -516,57 +323,6 @@ public sealed class KotlinClassMetadata {
)
}
}
/**
* Creates a new [KmPackage] instance from this multi-file class part metadata.
*/
@Deprecated(
"To avoid excessive copying, use .kmPackage property instead. Note that it returns a view and not a copy.",
ReplaceWith("kmPackage"),
DeprecationLevel.ERROR
)
public fun toKmPackage(): KmPackage = KmPackage().also { newKmp -> kmPackage.accept(newKmp) }
/**
* Makes the given visitor visit metadata of this multi-file class part.
*
* @param v the visitor that must visit this multi-file class part
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(v: KmPackageVisitor) {
kmPackage.accept(v)
}
/**
* A [KmPackageVisitor] that generates the metadata of a multi-file class part.
*/
@Deprecated(
"$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeMultiFileClassPart(kmPackage, facadeClassName, metadataVersion, extraInt)",
level = DeprecationLevel.ERROR
)
public 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 [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 [Metadata.extraInt]),
* 0 by default
*/
@Deprecated(
"$WRITER_API_MESSAGE, such as KotlinClassMetadata.writeMultiFileClassPart(kmPackage, facadeClassName, metadataVersion, extraInt)",
level = DeprecationLevel.ERROR
)
@JvmOverloads
public fun write(
facadeClassName: String,
metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0
): MultiFileClassPart {
error("This method is no longer implemented. Migrate to KotlinClassMetadata.writeMultifileClassPart.")
}
}
}
/**
@@ -597,13 +353,6 @@ public sealed class KotlinClassMetadata {
flags
)
}
@PublishedApi
@Deprecated("This declaration is intended for binary compatibility only", level = DeprecationLevel.HIDDEN)
internal companion object {
@JvmField // For binary compatibility with previous `data object Unknown`
public val INSTANCE: Unknown = Unknown(Metadata(kind = 99, metadataVersion = JvmMetadataVersion.LATEST_STABLE_SUPPORTED.toIntArray()), true)
}
}
/**
@@ -627,152 +376,6 @@ public sealed class KotlinClassMetadata {
return readStrict(metadata).apply(transformer).write()
}
/**
* Writes contents of [kmClass] as the class metadata.
*
* @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 [Metadata.extraInt]),
* 0 by default
*
* @throws IllegalArgumentException if [kmClass] is not correct and cannot be written or if [metadataVersion] is not supported for writing.
*/
@JvmStatic
@JvmOverloads
@Deprecated("Use a KotlinClassMetadata.Class instance and its write() member function", level = DeprecationLevel.ERROR)
public fun writeClass(
kmClass: KmClass,
metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0,
): Metadata = Class(kmClass, JvmMetadataVersion(metadataVersion), extraInt).write()
/**
* Writes [kmPackage] contents as the file facade metadata.
*
* @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 [Metadata.extraInt]),
* 0 by default
*
* @throws IllegalArgumentException if [kmPackage] is not correct and cannot be written or if [metadataVersion] is not supported for writing.
*/
@JvmStatic
@JvmOverloads
@Deprecated("Use a KotlinClassMetadata.FileFacade instance and its write() member function", level = DeprecationLevel.ERROR)
public fun writeFileFacade(
kmPackage: KmPackage,
metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0,
): Metadata = FileFacade(kmPackage, JvmMetadataVersion(metadataVersion), extraInt).write()
/**
* Writes [kmLambda] as the synthetic class metadata.
*
* @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 [Metadata.extraInt]),
* 0 by default
*
* @throws IllegalArgumentException if [kmLambda] is not correct and cannot be written or if [metadataVersion] is not supported for writing.
*/
@JvmStatic
@JvmOverloads
@Deprecated("Use a KotlinClassMetadata.SyntheticClass instance and its write() member function", level = DeprecationLevel.ERROR)
public fun writeLambda(
kmLambda: KmLambda,
metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0,
): Metadata = SyntheticClass(kmLambda, JvmMetadataVersion(metadataVersion), extraInt).write()
/**
* Writes synthetic class metadata.
*
* @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 [Metadata.extraInt]),
* 0 by default
*
* @throws IllegalArgumentException if [metadataVersion] is not supported for writing.
*/
@JvmStatic
@JvmOverloads
@Deprecated("Use a KotlinClassMetadata.SyntheticClass instance and its write() member function", level = DeprecationLevel.ERROR)
public fun writeSyntheticClass(
metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0,
): Metadata = SyntheticClass(null, JvmMetadataVersion(metadataVersion), extraInt).write()
/**
* 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 [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 [Metadata.extraInt]),
* 0 by default
*
* @throws IllegalArgumentException if [metadataVersion] is not supported for writing.
*/
@JvmStatic
@JvmOverloads
@Deprecated(
"Use a KotlinClassMetadata.MultiFileClassFacade instance and its write() member function",
level = DeprecationLevel.ERROR
)
public fun writeMultiFileClassFacade(
partClassNames: List<String>, metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0,
): Metadata = MultiFileClassFacade(partClassNames, JvmMetadataVersion(metadataVersion), extraInt).write()
/**
* 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 [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 [Metadata.extraInt]),
* 0 by default
*
* @throws IllegalArgumentException if [kmPackage] is not correct and cannot be written or if [metadataVersion] is not supported for writing.
*/
@JvmStatic
@JvmOverloads
@Deprecated(
"Use a KotlinClassMetadata.MultiFileClassPart instance and its write() member function",
level = DeprecationLevel.ERROR
)
public fun writeMultiFileClassPart(
kmPackage: KmPackage,
facadeClassName: String,
metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION,
extraInt: Int = 0,
): Metadata = MultiFileClassPart(kmPackage, facadeClassName, JvmMetadataVersion(metadataVersion), extraInt).write()
/**
* Reads and parses the given annotation data of a Kotlin JVM class file and returns the correct type of [KotlinClassMetadata] encoded by
* this annotation, if metadata version is supported.
*
* [annotationData] may be obtained reflectively, constructed manually or with helper [kotlinx.metadata.jvm.Metadata] function,
* or equivalent [KotlinClassHeader] can be used.
*
* Metadata version is supported if it is greater or equal than 1.1, and less or equal than [COMPATIBLE_METADATA_VERSION] + 1 minor version.
* Note that metadata version is 1.1 for Kotlin < 1.4, and is equal to the language version starting from Kotlin 1.4.
* For example, if the latest Kotlin version is 1.7.0, the latest kotlinx-metadata-jvm can read binaries produced by Kotlin
* compilers from 1.0 to 1.8.* inclusively.
*
* @throws IllegalArgumentException if the metadata version is unsupported
*
* @see COMPATIBLE_METADATA_VERSION
*/
@JvmStatic
@Deprecated(
"read() throws an error if metadata version is too high. Use either readStrict() if you want to retain this behavior, or readLenient() if you want to try to read newer metadata.",
ReplaceWith("KotlinClassMetadata.readStrict(annotationData)"),
DeprecationLevel.ERROR
)
public fun read(annotationData: Metadata): KotlinClassMetadata = readMetadataImpl(annotationData, lenient = false)
/**
* Reads and parses the given annotation data of a Kotlin JVM class file and returns the correct type of [KotlinClassMetadata] encoded by
* this annotation, if the metadata version is supported.
@@ -867,28 +470,5 @@ public sealed class KotlinClassMetadata {
* @see JvmMultifileClass
*/
public const val MULTI_FILE_CLASS_PART_KIND: Int = 5
/**
* The latest stable metadata version supported by this version of the library.
* The library can read in strict mode Kotlin metadata produced by Kotlin compilers from 1.0 up to and including this version + 1 minor.
*
* In other words, a metadata version is supported if it is greater or equal than 1.1, and less or equal than [COMPATIBLE_METADATA_VERSION] + 1 minor version.
* Note that a metadata version is 1.1 for Kotlin < 1.4, and is equal to the language version starting from Kotlin 1.4.
*
* For example, if the latest supported stable Kotlin version is 1.7.0, kotlinx-metadata-jvm can read binaries produced by Kotlin compilers from 1.0
* to 1.8.* inclusively. In this case, this property will have the value `[1, 7, 0]`.
*
* @see Metadata.metadataVersion
*/
@JvmField
@Deprecated("Use JvmMetadataVersion.LATEST_STABLE_SUPPORTED instead", ReplaceWith("JvmMetadataVersion.LATEST_STABLE_SUPPORTED"), DeprecationLevel.ERROR)
public val COMPATIBLE_METADATA_VERSION: IntArray = CompilerMetadataVersion.INSTANCE.toArray().copyOf()
}
}
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 WRITER_API_MESSAGE =
"Visitor Writer API is deprecated as excessive and cumbersome. Please use member functions of KotlinClassMetadata.Companion"
@@ -3,20 +3,12 @@
* 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(
"DEPRECATION", // COMPATIBLE_METADATA_VERSION
"DEPRECATION_ERROR", // KmModule.annotations
"UNUSED_PARAMETER" // For deprecated Writer.write
)
package kotlin.metadata.jvm
import kotlin.metadata.*
import kotlin.metadata.jvm.KotlinClassMetadata.Companion.COMPATIBLE_METADATA_VERSION
import kotlin.metadata.jvm.internal.JvmReadUtils.readModuleMetadataImpl
import kotlin.metadata.jvm.internal.JvmReadUtils.throwIfNotCompatible
import kotlin.metadata.jvm.internal.wrapIntoMetadataExceptionWhenNeeded
import kotlin.metadata.jvm.internal.wrapWriteIntoIAE
import org.jetbrains.kotlin.metadata.jvm.JvmModuleProtoBuf
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping
import org.jetbrains.kotlin.metadata.jvm.deserialization.PackageParts
@@ -46,16 +38,6 @@ public class KotlinModuleMetadata public constructor(
*/
public var version: JvmMetadataVersion,
) {
/**
* Visits metadata of this module with a new [KmModule] instance and returns that instance.
*/
@Deprecated(
"To avoid excessive copying, use .kmModule property instead. Note that it returns a view and not a copy.",
ReplaceWith("kmModule"),
DeprecationLevel.ERROR
)
public fun toKmModule(): KmModule = KmModule().apply { kmModule.accept(this) }
/**
* Encodes and writes this metadata of the Kotlin module file.
*
@@ -99,38 +81,6 @@ public class KotlinModuleMetadata public constructor(
return b.build().serializeToByteArray(CompilerMetadataVersion(version.toIntArray(), false), 0)
}
/**
* A [KmModuleVisitor] that generates the metadata of a Kotlin JVM module file.
*/
@Deprecated(
"Writer API is deprecated as excessive and cumbersome. Please use KotlinModuleMetadata.write(kmModule, metadataVersion)",
level = DeprecationLevel.ERROR
)
public class Writer {
/**
* Returns the metadata of the module file that was written with this writer.
*
* @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]),
* [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default
*/
@Deprecated(
"Writer API is deprecated as excessive and cumbersome. Please use KotlinModuleMetadata.write(kmModule, metadataVersion)",
level = DeprecationLevel.ERROR
)
public fun write(metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION): ByteArray {
error("This method is no longer implemented. Migrate to KotlinModuleMetadata.write.")
}
}
/**
* Makes the given visitor visit the metadata of this module file.
*
* @param v the visitor that must visit this module file
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(v: KmModuleVisitor): Unit = kmModule.accept(v)
/**
* Collection of methods for reading and writing [KotlinModuleMetadata].
*/
@@ -158,95 +108,19 @@ public class KotlinModuleMetadata public constructor(
KotlinModuleMetadata(module, JvmMetadataVersion(result.version.toArray()))
}
}
/**
* Writes the metadata of the Kotlin module file.
*
* @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]),
* [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default
*
* @throws IllegalArgumentException if [kmModule] is not correct and cannot be written or if [metadataVersion] is not supported for writing.
*/
@UnstableMetadataApi
@Deprecated("Use a KotlinModuleMetadata instance and its write() member function", level = DeprecationLevel.ERROR)
@JvmStatic
@JvmOverloads
public fun write(kmModule: KmModule, metadataVersion: JvmMetadataVersion = JvmMetadataVersion.LATEST_STABLE_SUPPORTED): ByteArray = wrapWriteIntoIAE {
return KotlinModuleMetadata(kmModule, metadataVersion).write()
}
}
}
/**
* A visitor to visit Kotlin JVM module files.
*
* When using this class, [visitEnd] must be called exactly once and after calls to all other visit* methods.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
@UnstableMetadataApi
public 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.
*
* Packages are separated by '/' in the names of file facades.
*
* @param fqName the fully qualified name of the package, separated by '.'
* @param fileFacades the list of single-file facades in this package
* @param multiFileClassParts the map of multi-file classes where keys are names of multi-file class parts,
* and values are names of the corresponding multi-file facades
*/
public open fun visitPackageParts(fqName: String, fileFacades: List<String>, multiFileClassParts: Map<String, String>) {
delegate?.visitPackageParts(fqName, fileFacades, multiFileClassParts)
}
/**
* Visits the annotation on the module.
*
* @param annotation annotation on the module
*/
public open fun visitAnnotation(annotation: KmAnnotation) {
delegate?.visitAnnotation(annotation)
}
/**
* Visits an `@OptionalExpectation`-annotated annotation class declared in this module.
* Such classes are not materialized to bytecode on JVM, but the Kotlin compiler stores their metadata in the module file on JVM,
* and loads it during compilation of dependent modules, in order to avoid reporting "unresolved reference" errors on usages.
*
* Multiplatform projects are an experimental feature of Kotlin, and their behavior and/or binary format
* may change in a subsequent release.
*/
public open fun visitOptionalAnnotationClass(): KmClassVisitor? =
delegate?.visitOptionalAnnotationClass()
/**
* Visits the end of the module.
*/
public open fun visitEnd() {
delegate?.visitEnd()
}
// TODO: JvmPackageName
}
/**
* Represents a Kotlin JVM module file (`.kotlin_module` extension).
*/
@UnstableMetadataApi
public class KmModule : KmModuleVisitor() {
public class KmModule {
/**
* Table of all single- and multi-file facades declared in some package of this module, where keys are '.'-separated package names.
*/
public val packageParts: MutableMap<String, KmPackageParts> = LinkedHashMap()
/**
* Annotations on the module.
*
* Currently, Kotlin does not provide functionality to specify annotations on modules.
*/
@Deprecated("This list is always empty and will be removed", level = DeprecationLevel.ERROR)
public val annotations: MutableList<KmAnnotation> = ArrayList(0)
/**
* `@OptionalExpectation`-annotated annotation classes declared in this module.
* Such classes are not materialized to bytecode on JVM, but the Kotlin compiler stores their metadata in the module file on JVM,
@@ -256,34 +130,6 @@ public class KmModule : KmModuleVisitor() {
* may change in a subsequent release.
*/
public val optionalAnnotationClasses: MutableList<KmClass> = ArrayList(0)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitPackageParts(fqName: String, fileFacades: List<String>, multiFileClassParts: Map<String, String>) {
packageParts[fqName] = KmPackageParts(fileFacades.toMutableList(), multiFileClassParts.toMutableMap())
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitAnnotation(annotation: KmAnnotation) {
annotations.add(annotation)
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitOptionalAnnotationClass(): KmClass =
KmClass().also(optionalAnnotationClasses::add)
/**
* Populates the given visitor with data in this module.
*
* @param visitor the visitor which will visit data in this module.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmModuleVisitor) {
for ((fqName, parts) in packageParts) {
visitor.visitPackageParts(fqName, parts.fileFacades, parts.multiFileClassParts)
}
annotations.forEach(visitor::visitAnnotation)
optionalAnnotationClasses.forEach { visitor.visitOptionalAnnotationClass()?.let(it::accept) }
}
}
/**
@@ -2,8 +2,6 @@
* 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.
*/
@file:Suppress("DEPRECATION","DEPRECATION_ERROR") // inheritance of deprecated visitors will be removed with visitors
package kotlin.metadata.jvm.internal
import kotlin.metadata.*
@@ -11,104 +9,68 @@ import kotlin.metadata.internal.extensions.*
import kotlin.metadata.jvm.*
internal val KmClass.jvm: JvmClassExtension
get() = visitExtensions(JvmClassExtensionVisitor.TYPE) as JvmClassExtension
get() = getExtension(JvmClassExtension.TYPE) as JvmClassExtension
internal val KmPackage.jvm: JvmPackageExtension
get() = visitExtensions(JvmPackageExtensionVisitor.TYPE) as JvmPackageExtension
get() = getExtension(JvmPackageExtension.TYPE) as JvmPackageExtension
internal val KmFunction.jvm: JvmFunctionExtension
get() = visitExtensions(JvmFunctionExtensionVisitor.TYPE) as JvmFunctionExtension
get() = getExtension(JvmFunctionExtension.TYPE) as JvmFunctionExtension
internal val KmProperty.jvm: JvmPropertyExtension
get() = visitExtensions(JvmPropertyExtensionVisitor.TYPE) as JvmPropertyExtension
get() = getExtension(JvmPropertyExtension.TYPE) as JvmPropertyExtension
internal val KmConstructor.jvm: JvmConstructorExtension
get() = visitExtensions(JvmConstructorExtensionVisitor.TYPE) as JvmConstructorExtension
get() = getExtension(JvmConstructorExtension.TYPE) as JvmConstructorExtension
internal val KmTypeParameter.jvm: JvmTypeParameterExtension
get() = visitExtensions(JvmTypeParameterExtensionVisitor.TYPE) as JvmTypeParameterExtension
get() = getExtension(JvmTypeParameterExtension.TYPE) as JvmTypeParameterExtension
internal val KmType.jvm: JvmTypeExtension
get() = visitExtensions(JvmTypeExtensionVisitor.TYPE) as JvmTypeExtension
get() = getExtension(JvmTypeExtension.TYPE) as JvmTypeExtension
internal class JvmClassExtension : JvmClassExtensionVisitor(), KmClassExtension {
internal class JvmClassExtension : KmClassExtension {
val localDelegatedProperties: MutableList<KmProperty> = ArrayList(0)
var moduleName: String? = null
var anonymousObjectOriginName: String? = null
var jvmFlags: Int = 0
override fun visitLocalDelegatedProperty(flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor =
KmProperty(flags, name, getterFlags, setterFlags).also { localDelegatedProperties.add(it) }
override val type: KmExtensionType
get() = TYPE
override fun visitModuleName(name: String) {
this.moduleName = name
}
override fun visitAnonymousObjectOriginName(internalName: String) {
this.anonymousObjectOriginName = internalName
}
override fun visitJvmFlags(flags: Int) {
this.jvmFlags = flags
}
override fun accept(visitor: KmClassExtensionVisitor) {
require(visitor is JvmClassExtensionVisitor)
localDelegatedProperties.forEach {
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") // getter.flags
visitor.visitLocalDelegatedProperty(it.flags, it.name, it.getter.flags, it.setterFlags)?.let(it::accept)
}
moduleName?.let(visitor::visitModuleName)
anonymousObjectOriginName?.let(visitor::visitAnonymousObjectOriginName)
jvmFlags.takeIf { it != 0 }?.let(visitor::visitJvmFlags)
visitor.visitEnd()
companion object {
val TYPE: KmExtensionType = KmExtensionType(JvmClassExtension::class)
}
}
internal class JvmPackageExtension : JvmPackageExtensionVisitor(), KmPackageExtension {
internal class JvmPackageExtension : KmPackageExtension {
val localDelegatedProperties: MutableList<KmProperty> = ArrayList(0)
var moduleName: String? = null
override fun visitLocalDelegatedProperty(flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor =
KmProperty(flags, name, getterFlags, setterFlags).also { localDelegatedProperties.add(it) }
override val type: KmExtensionType
get() = TYPE
override fun visitModuleName(name: String) {
this.moduleName = name
}
override fun accept(visitor: KmPackageExtensionVisitor) {
require(visitor is JvmPackageExtensionVisitor)
localDelegatedProperties.forEach {
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") // getter.flags
visitor.visitLocalDelegatedProperty(it.flags, it.name, it.getter.flags, it.setterFlags)?.let(it::accept)
}
moduleName?.let(visitor::visitModuleName)
visitor.visitEnd()
companion object {
@JvmField
val TYPE: KmExtensionType = KmExtensionType(JvmPackageExtension::class)
}
}
internal class JvmFunctionExtension : JvmFunctionExtensionVisitor(), KmFunctionExtension {
internal class JvmFunctionExtension : KmFunctionExtension {
var signature: JvmMethodSignature? = null
var lambdaClassOriginName: String? = null
override fun visit(signature: JvmMethodSignature?) {
this.signature = signature
}
override val type: KmExtensionType
get() = TYPE
override fun visitLambdaClassOriginName(internalName: String) {
this.lambdaClassOriginName = internalName
}
override fun accept(visitor: KmFunctionExtensionVisitor) {
require(visitor is JvmFunctionExtensionVisitor)
visitor.visit(signature)
lambdaClassOriginName?.let(visitor::visitLambdaClassOriginName)
visitor.visitEnd()
companion object {
@JvmField
val TYPE: KmExtensionType = KmExtensionType(JvmFunctionExtension::class)
}
}
internal class JvmPropertyExtension : JvmPropertyExtensionVisitor(), KmPropertyExtension {
internal class JvmPropertyExtension : KmPropertyExtension {
var jvmFlags: Int = 0
var fieldSignature: JvmFieldSignature? = null
var getterSignature: JvmMethodSignature? = null
@@ -116,78 +78,55 @@ internal class JvmPropertyExtension : JvmPropertyExtensionVisitor(), KmPropertyE
var syntheticMethodForAnnotations: JvmMethodSignature? = null
var syntheticMethodForDelegate: JvmMethodSignature? = null
override fun visit(
jvmFlags: Int,
fieldSignature: JvmFieldSignature?,
getterSignature: JvmMethodSignature?,
setterSignature: JvmMethodSignature?
) {
this.jvmFlags = jvmFlags
this.fieldSignature = fieldSignature
this.getterSignature = getterSignature
this.setterSignature = setterSignature
}
override val type: KmExtensionType
get() = TYPE
override fun visitSyntheticMethodForAnnotations(signature: JvmMethodSignature?) {
this.syntheticMethodForAnnotations = signature
}
override fun visitSyntheticMethodForDelegate(signature: JvmMethodSignature?) {
this.syntheticMethodForDelegate = signature
}
override fun accept(visitor: KmPropertyExtensionVisitor) {
require(visitor is JvmPropertyExtensionVisitor)
visitor.visit(jvmFlags, fieldSignature, getterSignature, setterSignature)
visitor.visitSyntheticMethodForAnnotations(syntheticMethodForAnnotations)
visitor.visitSyntheticMethodForDelegate(syntheticMethodForDelegate)
visitor.visitEnd()
companion object {
@JvmField
val TYPE: KmExtensionType = KmExtensionType(JvmPropertyExtension::class)
}
}
internal class JvmConstructorExtension : JvmConstructorExtensionVisitor(), KmConstructorExtension {
internal class JvmConstructorExtension : KmConstructorExtension {
var signature: JvmMethodSignature? = null
override fun visit(signature: JvmMethodSignature?) {
this.signature = signature
}
override val type: KmExtensionType
get() = TYPE
override fun accept(visitor: KmConstructorExtensionVisitor) {
require(visitor is JvmConstructorExtensionVisitor)
visitor.visit(signature)
companion object {
@JvmField
val TYPE: KmExtensionType = KmExtensionType(JvmConstructorExtension::class)
}
}
internal class JvmTypeParameterExtension : JvmTypeParameterExtensionVisitor(), KmTypeParameterExtension {
internal class JvmTypeParameterExtension : KmTypeParameterExtension {
val annotations: MutableList<KmAnnotation> = mutableListOf()
override fun visitAnnotation(annotation: KmAnnotation) {
annotations.add(annotation)
}
override val type: KmExtensionType
get() = TYPE
override fun accept(visitor: KmTypeParameterExtensionVisitor) {
require(visitor is JvmTypeParameterExtensionVisitor)
annotations.forEach(visitor::visitAnnotation)
visitor.visitEnd()
companion object {
@JvmField
val TYPE: KmExtensionType = KmExtensionType(JvmTypeParameterExtension::class)
}
}
internal class JvmTypeExtension : JvmTypeExtensionVisitor(), KmTypeExtension {
internal class JvmTypeExtension : KmTypeExtension {
var isRaw: Boolean = false
val annotations: MutableList<KmAnnotation> = mutableListOf()
override fun visit(isRaw: Boolean) {
this.isRaw = isRaw
}
override val type: KmExtensionType
get() = TYPE
override fun visitAnnotation(annotation: KmAnnotation) {
annotations.add(annotation)
}
companion object {
@JvmField
val TYPE: KmExtensionType = KmExtensionType(JvmTypeExtension::class)
override fun accept(visitor: KmTypeExtensionVisitor) {
require(visitor is JvmTypeExtensionVisitor)
visitor.visit(isRaw)
annotations.forEach(visitor::visitAnnotation)
visitor.visitEnd()
/**
* The type flexibility id, signifying that the visited type is a JVM platform type.
*
* @see KmTypeVisitor.visitFlexibleTypeUpperBound
*/
const val PLATFORM_TYPE_ID: String = JvmProtoBufUtil.PLATFORM_TYPE_ID // TODO: move out of deprecated visitor
}
}
@@ -223,13 +223,9 @@ internal class JvmMetadataExtensions : MetadataExtensions {
override fun createPackageExtension(): KmPackageExtension = JvmPackageExtension()
@Suppress("DEPRECATION_ERROR")
override fun createModuleFragmentExtensions(): KmModuleFragmentExtension =
object : KmModuleFragmentExtension {
override val type: KmExtensionType = KmExtensionType(KmModuleFragmentExtension::class)
override fun accept(visitor: KmModuleFragmentExtensionVisitor) {
}
}
override fun createFunctionExtension(): KmFunctionExtension = JvmFunctionExtension()
@@ -5,7 +5,6 @@
package kotlin.metadata.jvm.internal
import kotlin.metadata.KmAnnotation
import kotlin.metadata.KmClass
import kotlin.metadata.KmLambda
import kotlin.metadata.KmPackage
@@ -69,11 +68,6 @@ internal object JvmReadUtils {
)
}
for (annotation in data.moduleData.annotations) {
@Suppress("DEPRECATION_ERROR")
v.annotations.add(KmAnnotation(annotation, emptyMap()))
}
for (classProto in data.moduleData.optionalAnnotations) {
v.optionalAnnotationClasses.add(classProto.toKmClass(data.moduleData.nameResolver, false))
}
@@ -0,0 +1,77 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.metadata.test
import kotlin.metadata.internal.FlagImpl
import org.jetbrains.kotlin.metadata.ProtoBuf.Visibility as ProtoVisibility
import org.jetbrains.kotlin.metadata.deserialization.Flags as F
fun Flag(field: F.FlagField<*>, value: Int) = FlagImpl(field.offset, field.bitWidth, value)
fun Flag(field: F.BooleanFlagField) = Flag(field, 1)
// Reduced copy of old Flag.kt for testing purposes.
class Flag private constructor() {
companion object Common {
/**
* A visibility flag, signifying that the corresponding declaration is `internal`.
*/
val IS_INTERNAL = Flag(F.VISIBILITY, ProtoVisibility.INTERNAL_VALUE)
/**
* A visibility flag, signifying that the corresponding declaration is `private`.
*/
@JvmField
val IS_PRIVATE = Flag(F.VISIBILITY, ProtoVisibility.PRIVATE_VALUE)
/**
* A visibility flag, signifying that the corresponding declaration is `public`.
*/
@JvmField
val IS_PUBLIC = Flag(F.VISIBILITY, ProtoVisibility.PUBLIC_VALUE)
}
object Class {
/**
* Signifies that the corresponding class is `data`.
*/
@JvmField
val IS_DATA = Flag(F.IS_DATA)
}
object Constructor {
/**
* Signifies that the corresponding constructor has non-stable parameter names, i.e. cannot be called with named arguments.
*/
@JvmField
val HAS_NON_STABLE_PARAMETER_NAMES = Flag(F.IS_CONSTRUCTOR_WITH_NON_STABLE_PARAMETER_NAMES)
}
object Function {
/**
* Signifies that the corresponding function is `operator`.
*/
@JvmField
val IS_OPERATOR = Flag(F.IS_OPERATOR)
/**
* Signifies that the corresponding function has non-stable parameter names, i.e. cannot be called with named arguments.
*/
@JvmField
val HAS_NON_STABLE_PARAMETER_NAMES = Flag(F.IS_FUNCTION_WITH_NON_STABLE_PARAMETER_NAMES)
}
object Type {
/**
* Signifies that the corresponding type is marked as nullable, i.e. has a question mark at the end of its notation.
*/
@JvmField
val IS_NULLABLE = FlagImpl(0, 1, 1)
}
}
@@ -7,10 +7,11 @@ package kotlin.metadata.test
import kotlin.metadata.*
import org.junit.Test
import kotlin.metadata.internal.FlagImpl
import kotlin.metadata.internal._flagAccess
import kotlin.reflect.KMutableProperty0
import kotlin.test.*
@Suppress("DEPRECATION", "DEPRECATION_ERROR") // flags will become internal eventually
class FlagDelegatesTest {
private class Private
@@ -26,29 +27,29 @@ class FlagDelegatesTest {
assertEquals(Visibility.PRIVATE, p1.visibility)
assertEquals(Visibility.PUBLIC, p2.visibility)
assertTrue(Flag.IS_PRIVATE(p1.flags))
assertTrue(Flag.IS_PUBLIC(p2.flags))
assertTrue(Flag.IS_PRIVATE(_flagAccess(p1)))
assertTrue(Flag.IS_PUBLIC(_flagAccess(p2)))
p1.visibility = Visibility.PUBLIC
p2.visibility = Visibility.INTERNAL
assertFalse(Flag.IS_PRIVATE(p1.flags))
assertFalse(Flag.IS_PUBLIC(p2.flags))
assertFalse(Flag.IS_PRIVATE(_flagAccess(p1)))
assertFalse(Flag.IS_PUBLIC(_flagAccess(p2)))
assertTrue(Flag.IS_PUBLIC(p1.flags))
assertTrue(Flag.IS_INTERNAL(p2.flags))
assertTrue(Flag.IS_PUBLIC(_flagAccess(p1)))
assertTrue(Flag.IS_INTERNAL(_flagAccess(p2)))
val f = assertNotNull(p2.functions.find { it.name == "f" })
assertEquals(Visibility.PUBLIC, f.visibility)
f.visibility = Visibility.PRIVATE
assertFalse(Flag.IS_PUBLIC(f.flags))
assertTrue(Flag.IS_PRIVATE(f.flags))
assertFalse(Flag.IS_PUBLIC(_flagAccess(f)))
assertTrue(Flag.IS_PRIVATE(_flagAccess(f)))
}
@Test
fun testBooleanFlags() {
val klass = Public::class.java.readMetadataAsKmClass()
fun doTest(prop: KMutableProperty0<Boolean>, flags: () -> Int, rawFlag: Flag) {
fun doTest(prop: KMutableProperty0<Boolean>, flags: () -> Int, rawFlag: FlagImpl) {
assertFalse(prop.get())
assertFalse(rawFlag(flags()))
@@ -59,14 +60,14 @@ class FlagDelegatesTest {
}
doTest(klass::isData, klass::flags, Flag.Class.IS_DATA)
doTest(klass::isData, { _flagAccess(klass) }, Flag.Class.IS_DATA)
val f = klass.functions.single { it.name == "f" }
doTest(f::isOperator, f::flags, Flag.Function.IS_OPERATOR)
doTest(f::isOperator, { _flagAccess(f) }, Flag.Function.IS_OPERATOR)
val rt = f.returnType
doTest(rt::isNullable, rt::flags, Flag.Type.IS_NULLABLE)
doTest(rt::isNullable, { _flagAccess(rt) }, Flag.Type.IS_NULLABLE)
}
@Suppress("UNUSED_PARAMETER")
@Suppress("UNUSED_PARAMETER", "unused")
class PropertiesContainer {
val defaultVal: String = ""
@@ -121,7 +122,7 @@ class FlagDelegatesTest {
setterParamCheck: (KmValueParameter?) -> Unit = { assertNull(it, "Should not be a setter parameter for $name") },
) {
with(propMap.getValue(name)) {
assertEquals(listOf(isVarProp, true, isVarProp), listOf(isVar, hasGetter, hasSetter), "for $name")
assertEquals(listOf(isVarProp, isVarProp), listOf(isVar, setter != null), "for $name")
assertEquals(visibility, getter.visibility, "for $name")
assertEquals(getterNotDefault, getter.isNotDefault, "for $name")
@@ -12,6 +12,7 @@ import org.jetbrains.org.objectweb.asm.Opcodes
import org.junit.Test
import java.net.URLClassLoader
import kotlin.coroutines.CoroutineContext
import kotlin.metadata.internal._flagAccess
import kotlin.reflect.full.primaryConstructor
import kotlin.test.*
@@ -146,7 +147,6 @@ class MetadataSmokeTest {
}
@Test
@Suppress("DEPRECATION_ERROR") // flags will become internal eventually
fun unstableParameterNames() {
@Suppress("unused", "UNUSED_PARAMETER")
class Test(a: String, b: Int, c: Boolean) {
@@ -155,8 +155,8 @@ class MetadataSmokeTest {
val classWithStableParameterNames = Test::class.java.readMetadataAsClass()
classWithStableParameterNames.kmClass.constructors.forEach { assertFalse(Flag.Constructor.HAS_NON_STABLE_PARAMETER_NAMES(it.flags)) }
classWithStableParameterNames.kmClass.functions.forEach { assertFalse(Flag.Function.HAS_NON_STABLE_PARAMETER_NAMES(it.flags)) }
classWithStableParameterNames.kmClass.constructors.forEach { assertFalse(Flag.Constructor.HAS_NON_STABLE_PARAMETER_NAMES(_flagAccess(it))) }
classWithStableParameterNames.kmClass.functions.forEach { assertFalse(Flag.Function.HAS_NON_STABLE_PARAMETER_NAMES(_flagAccess(it))) }
classWithStableParameterNames.kmClass.constructors.forEach { assertFalse(it.hasNonStableParameterNames) }
classWithStableParameterNames.kmClass.functions.forEach { assertFalse(it.hasNonStableParameterNames) }
@@ -168,8 +168,8 @@ class MetadataSmokeTest {
val classWithUnstableParameterNames = newMetadata.readAsKmClass()
classWithUnstableParameterNames.constructors.forEach { assertTrue(Flag.Constructor.HAS_NON_STABLE_PARAMETER_NAMES(it.flags)) }
classWithUnstableParameterNames.functions.forEach { assertTrue(Flag.Function.HAS_NON_STABLE_PARAMETER_NAMES(it.flags)) }
classWithUnstableParameterNames.constructors.forEach { assertTrue(Flag.Constructor.HAS_NON_STABLE_PARAMETER_NAMES(_flagAccess(it))) }
classWithUnstableParameterNames.functions.forEach { assertTrue(Flag.Function.HAS_NON_STABLE_PARAMETER_NAMES(_flagAccess(it))) }
classWithUnstableParameterNames.constructors.forEach { assertTrue(it.hasNonStableParameterNames) }
classWithUnstableParameterNames.functions.forEach { assertTrue(it.hasNonStableParameterNames) }
@@ -2,45 +2,42 @@
* Copyright 2010-2024 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("DEPRECATION_ERROR") // Extension visitors
package kotlinx.metadata.klib.impl
import kotlinx.metadata.klib.*
import kotlin.metadata.*
import kotlin.metadata.internal.common.KmModuleFragment
import kotlin.metadata.internal.common.KmModuleFragmentExtensionVisitor
import kotlin.metadata.internal.extensions.*
internal val KmFunction.klibExtensions: KlibFunctionExtension
get() = visitExtensions(KlibFunctionExtensionVisitor.TYPE) as KlibFunctionExtension
get() = getExtension(KlibFunctionExtensionVisitor.TYPE) as KlibFunctionExtension
internal val KmClass.klibExtensions: KlibClassExtension
get() = visitExtensions(KlibClassExtensionVisitor.TYPE) as KlibClassExtension
get() = getExtension(KlibClassExtensionVisitor.TYPE) as KlibClassExtension
internal val KmType.klibExtensions: KlibTypeExtension
get() = visitExtensions(KlibTypeExtensionVisitor.TYPE) as KlibTypeExtension
get() = getExtension(KlibTypeExtensionVisitor.TYPE) as KlibTypeExtension
internal val KmProperty.klibExtensions: KlibPropertyExtension
get() = visitExtensions(KlibPropertyExtensionVisitor.TYPE) as KlibPropertyExtension
get() = getExtension(KlibPropertyExtensionVisitor.TYPE) as KlibPropertyExtension
internal val KmConstructor.klibExtensions: KlibConstructorExtension
get() = visitExtensions(KlibConstructorExtensionVisitor.TYPE) as KlibConstructorExtension
get() = getExtension(KlibConstructorExtensionVisitor.TYPE) as KlibConstructorExtension
internal val KmTypeParameter.klibExtensions: KlibTypeParameterExtension
get() = visitExtensions(KlibTypeParameterExtensionVisitor.TYPE) as KlibTypeParameterExtension
get() = getExtension(KlibTypeParameterExtensionVisitor.TYPE) as KlibTypeParameterExtension
internal val KmPackage.klibExtensions: KlibPackageExtension
get() = visitExtensions(KlibPackageExtensionVisitor.TYPE) as KlibPackageExtension
get() = getExtension(KlibPackageExtensionVisitor.TYPE) as KlibPackageExtension
internal val KmModuleFragment.klibExtensions: KlibModuleFragmentExtension
get() = visitExtensions(KlibModuleFragmentExtensionVisitor.TYPE) as KlibModuleFragmentExtension
get() = getExtension(KlibModuleFragmentExtensionVisitor.TYPE) as KlibModuleFragmentExtension
internal val KmTypeAlias.klibExtensions: KlibTypeAliasExtension
get() = visitExtensions(KlibTypeAliasExtensionVisitor.TYPE) as KlibTypeAliasExtension
get() = getExtension(KlibTypeAliasExtensionVisitor.TYPE) as KlibTypeAliasExtension
internal val KmValueParameter.klibExtensions: KlibValueParameterExtension
get() = visitExtensions(KlibValueParameterExtensionVisitor.TYPE) as KlibValueParameterExtension
get() = getExtension(KlibValueParameterExtensionVisitor.TYPE) as KlibValueParameterExtension
internal class KlibFunctionExtension : KlibFunctionExtensionVisitor(), KmFunctionExtension {
@@ -60,7 +57,7 @@ internal class KlibFunctionExtension : KlibFunctionExtensionVisitor(), KmFunctio
this.file = file
}
override fun accept(visitor: KmFunctionExtensionVisitor) {
fun accept(visitor: KmFunctionExtension) {
require(visitor is KlibFunctionExtensionVisitor)
annotations.forEach(visitor::visitAnnotation)
uniqId?.let(visitor::visitUniqId)
@@ -91,7 +88,7 @@ internal class KlibClassExtension : KlibClassExtensionVisitor(), KmClassExtensio
enumEntries += entry
}
override fun accept(visitor: KmClassExtensionVisitor) {
fun accept(visitor: KmClassExtension) {
require(visitor is KlibClassExtensionVisitor)
annotations.forEach(visitor::visitAnnotation)
enumEntries.forEach(visitor::visitEnumEntry)
@@ -108,7 +105,7 @@ internal class KlibTypeExtension : KlibTypeExtensionVisitor(), KmTypeExtension {
annotations += annotation
}
override fun accept(visitor: KmTypeExtensionVisitor) {
fun accept(visitor: KmTypeExtension) {
require(visitor is KlibTypeExtensionVisitor)
annotations.forEach(visitor::visitAnnotation)
}
@@ -147,7 +144,7 @@ internal class KlibPropertyExtension : KlibPropertyExtensionVisitor(), KmPropert
this.compileTimeValue = value
}
override fun accept(visitor: KmPropertyExtensionVisitor) {
fun accept(visitor: KmPropertyExtension) {
require(visitor is KlibPropertyExtensionVisitor)
annotations.forEach(visitor::visitAnnotation)
getterAnnotations.forEach(visitor::visitGetterAnnotation)
@@ -171,7 +168,7 @@ internal class KlibConstructorExtension : KlibConstructorExtensionVisitor(), KmC
this.uniqId = uniqId
}
override fun accept(visitor: KmConstructorExtensionVisitor) {
fun accept(visitor: KmConstructorExtension) {
require(visitor is KlibConstructorExtensionVisitor)
annotations.forEach(visitor::visitAnnotation)
uniqId?.let(visitor::visitUniqId)
@@ -191,7 +188,7 @@ internal class KlibTypeParameterExtension : KlibTypeParameterExtensionVisitor(),
this.uniqId = uniqId
}
override fun accept(visitor: KmTypeParameterExtensionVisitor) {
fun accept(visitor: KmTypeParameterExtension) {
require(visitor is KlibTypeParameterExtensionVisitor)
annotations.forEach(visitor::visitAnnotation)
uniqId?.let(visitor::visitUniqId)
@@ -206,7 +203,7 @@ internal class KlibPackageExtension : KlibPackageExtensionVisitor(), KmPackageEx
fqName = name
}
override fun accept(visitor: KmPackageExtensionVisitor) {
fun accept(visitor: KmPackageExtension) {
require(visitor is KlibPackageExtensionVisitor)
fqName?.let(visitor::visitFqName)
}
@@ -230,7 +227,7 @@ internal class KlibModuleFragmentExtension : KlibModuleFragmentExtensionVisitor(
this.className += className
}
override fun accept(visitor: KmModuleFragmentExtensionVisitor) {
fun accept(visitor: KmModuleFragmentExtension) {
require(visitor is KlibModuleFragmentExtensionVisitor)
moduleFragmentFiles.forEach(visitor::visitFile)
fqName?.let(visitor::visitFqName)
@@ -245,7 +242,7 @@ internal class KlibTypeAliasExtension : KlibTypeAliasExtensionVisitor(), KmTypeA
this.uniqId = uniqId
}
override fun accept(visitor: KmTypeAliasExtensionVisitor) {
fun accept(visitor: KmTypeAliasExtension) {
require(visitor is KlibTypeAliasExtensionVisitor)
uniqId?.let(visitor::visitUniqId)
}
@@ -258,7 +255,7 @@ internal class KlibValueParameterExtension : KlibValueParameterExtensionVisitor(
annotations += annotation
}
override fun accept(visitor: KmValueParameterExtensionVisitor) {
fun accept(visitor: KmValueParameterExtension) {
require(visitor is KlibValueParameterExtensionVisitor)
annotations.forEach(visitor::visitAnnotation)
}
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.serialization.StringTableImpl
@Suppress("DEPRECATION_ERROR")
internal class KlibMetadataExtensions : MetadataExtensions {
private fun ReadContext.getSourceFile(index: Int) =
@@ -28,7 +27,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
strings.getStringIndex(file.name)
override fun readClassExtensions(kmClass: KmClass, proto: ProtoBuf.Class, c: ReadContext) {
val extension = kmClass.visitExtensions(KlibClassExtensionVisitor.TYPE) as? KlibClassExtensionVisitor ?: return
val extension = kmClass.getExtension(KlibClassExtensionVisitor.TYPE) as? KlibClassExtensionVisitor ?: return
proto.getExtension(KlibMetadataProtoBuf.classAnnotation).forEach { annotation ->
extension.visitAnnotation(annotation.readAnnotation(c.strings))
@@ -49,7 +48,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
}
override fun readPackageExtensions(kmPackage: KmPackage, proto: ProtoBuf.Package, c: ReadContext) {
val extension = kmPackage.visitExtensions(KlibPackageExtensionVisitor.TYPE) as? KlibPackageExtensionVisitor ?: return
val extension = kmPackage.getExtension(KlibPackageExtensionVisitor.TYPE) as? KlibPackageExtensionVisitor ?: return
proto.getExtensionOrNull(KlibMetadataProtoBuf.packageFqName)?.let {
val fqName = (c.strings as NameResolverImpl).getPackageFqName(it)
@@ -58,7 +57,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
}
override fun readModuleFragmentExtensions(kmModuleFragment: KmModuleFragment, proto: ProtoBuf.PackageFragment, c: ReadContext) {
val extension = kmModuleFragment.visitExtensions(KlibModuleFragmentExtensionVisitor.TYPE) as? KlibModuleFragmentExtensionVisitor ?: return
val extension = kmModuleFragment.getExtension(KlibModuleFragmentExtensionVisitor.TYPE) as? KlibModuleFragmentExtensionVisitor ?: return
proto.getExtension(KlibMetadataProtoBuf.packageFragmentFiles)
.map { c.getSourceFile(it) }
@@ -70,7 +69,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
}
override fun readFunctionExtensions(kmFunction: KmFunction, proto: ProtoBuf.Function, c: ReadContext) {
val extension = kmFunction.visitExtensions(KlibFunctionExtensionVisitor.TYPE) as? KlibFunctionExtensionVisitor ?: return
val extension = kmFunction.getExtension(KlibFunctionExtensionVisitor.TYPE) as? KlibFunctionExtensionVisitor ?: return
proto.getExtension(KlibMetadataProtoBuf.functionAnnotation).forEach { annotation ->
extension.visitAnnotation(annotation.readAnnotation(c.strings))
@@ -85,7 +84,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
}
override fun readPropertyExtensions(kmProperty: KmProperty, proto: ProtoBuf.Property, c: ReadContext) {
val extension = kmProperty.visitExtensions(KlibPropertyExtensionVisitor.TYPE) as? KlibPropertyExtensionVisitor ?: return
val extension = kmProperty.getExtension(KlibPropertyExtensionVisitor.TYPE) as? KlibPropertyExtensionVisitor ?: return
proto.getExtension(KlibMetadataProtoBuf.propertyAnnotation).forEach { annotation ->
extension.visitAnnotation(annotation.readAnnotation(c.strings))
@@ -106,7 +105,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
}
override fun readConstructorExtensions(kmConstructor: KmConstructor, proto: ProtoBuf.Constructor, c: ReadContext) {
val extension = kmConstructor.visitExtensions(KlibConstructorExtensionVisitor.TYPE) as? KlibConstructorExtensionVisitor ?: return
val extension = kmConstructor.getExtension(KlibConstructorExtensionVisitor.TYPE) as? KlibConstructorExtensionVisitor ?: return
proto.getExtension(KlibMetadataProtoBuf.constructorAnnotation).forEach { annotation ->
extension.visitAnnotation(annotation.readAnnotation(c.strings))
@@ -117,7 +116,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
}
override fun readTypeParameterExtensions(kmTypeParameter: KmTypeParameter, proto: ProtoBuf.TypeParameter, c: ReadContext) {
val extension = kmTypeParameter.visitExtensions(KlibTypeParameterExtensionVisitor.TYPE) as? KlibTypeParameterExtensionVisitor ?: return
val extension = kmTypeParameter.getExtension(KlibTypeParameterExtensionVisitor.TYPE) as? KlibTypeParameterExtensionVisitor ?: return
proto.getExtension(KlibMetadataProtoBuf.typeParameterAnnotation).forEach { annotation ->
extension.visitAnnotation(annotation.readAnnotation(c.strings))
@@ -128,7 +127,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
}
override fun readTypeExtensions(kmType: KmType, proto: ProtoBuf.Type, c: ReadContext) {
val extension = kmType.visitExtensions(KlibTypeExtensionVisitor.TYPE) as? KlibTypeExtensionVisitor ?: return
val extension = kmType.getExtension(KlibTypeExtensionVisitor.TYPE) as? KlibTypeExtensionVisitor ?: return
proto.getExtension(KlibMetadataProtoBuf.typeAnnotation).forEach { annotation ->
extension.visitAnnotation(annotation.readAnnotation(c.strings))
@@ -136,7 +135,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
}
override fun readTypeAliasExtensions(kmTypeAlias: KmTypeAlias, proto: ProtoBuf.TypeAlias, c: ReadContext) {
val extension = kmTypeAlias.visitExtensions(KlibTypeAliasExtensionVisitor.TYPE) as? KlibTypeAliasExtensionVisitor ?: return
val extension = kmTypeAlias.getExtension(KlibTypeAliasExtensionVisitor.TYPE) as? KlibTypeAliasExtensionVisitor ?: return
proto.getExtension(KlibMetadataProtoBuf.typeAliasUniqId).let { descriptorUniqId ->
extension.visitUniqId(descriptorUniqId.readUniqId())
@@ -144,7 +143,7 @@ internal class KlibMetadataExtensions : MetadataExtensions {
}
override fun readValueParameterExtensions(kmValueParameter: KmValueParameter, proto: ProtoBuf.ValueParameter, c: ReadContext) {
val extension = kmValueParameter.visitExtensions(KlibValueParameterExtensionVisitor.TYPE) as? KlibValueParameterExtensionVisitor ?: return
val extension = kmValueParameter.getExtension(KlibValueParameterExtensionVisitor.TYPE) as? KlibValueParameterExtensionVisitor ?: return
proto.getExtension(KlibMetadataProtoBuf.parameterAnnotation).forEach { annotation ->
extension.visitAnnotation(annotation.readAnnotation(c.strings))
@@ -2,14 +2,12 @@
* Copyright 2010-2024 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("DEPRECATION_ERROR") // Extension visitors
package kotlinx.metadata.klib
import kotlin.metadata.*
import kotlin.metadata.internal.common.KmModuleFragmentExtensionVisitor
import kotlin.metadata.internal.extensions.*
abstract class KlibFunctionExtensionVisitor : KmFunctionExtensionVisitor {
abstract class KlibFunctionExtensionVisitor : KmFunctionExtension {
abstract fun visitAnnotation(annotation: KmAnnotation)
@@ -25,7 +23,7 @@ abstract class KlibFunctionExtensionVisitor : KmFunctionExtensionVisitor {
}
}
abstract class KlibClassExtensionVisitor : KmClassExtensionVisitor {
abstract class KlibClassExtensionVisitor : KmClassExtension {
abstract fun visitAnnotation(annotation: KmAnnotation)
@@ -43,7 +41,7 @@ abstract class KlibClassExtensionVisitor : KmClassExtensionVisitor {
}
}
abstract class KlibTypeExtensionVisitor : KmTypeExtensionVisitor {
abstract class KlibTypeExtensionVisitor : KmTypeExtension {
abstract fun visitAnnotation(annotation: KmAnnotation)
@@ -55,7 +53,7 @@ abstract class KlibTypeExtensionVisitor : KmTypeExtensionVisitor {
}
}
abstract class KlibPropertyExtensionVisitor : KmPropertyExtensionVisitor {
abstract class KlibPropertyExtensionVisitor : KmPropertyExtension {
abstract fun visitAnnotation(annotation: KmAnnotation)
@@ -77,7 +75,7 @@ abstract class KlibPropertyExtensionVisitor : KmPropertyExtensionVisitor {
}
}
abstract class KlibConstructorExtensionVisitor : KmConstructorExtensionVisitor {
abstract class KlibConstructorExtensionVisitor : KmConstructorExtension {
abstract fun visitAnnotation(annotation: KmAnnotation)
@@ -91,7 +89,7 @@ abstract class KlibConstructorExtensionVisitor : KmConstructorExtensionVisitor {
}
}
abstract class KlibTypeParameterExtensionVisitor : KmTypeParameterExtensionVisitor {
abstract class KlibTypeParameterExtensionVisitor : KmTypeParameterExtension {
abstract fun visitAnnotation(annotation: KmAnnotation)
@@ -105,7 +103,7 @@ abstract class KlibTypeParameterExtensionVisitor : KmTypeParameterExtensionVisit
}
}
abstract class KlibPackageExtensionVisitor : KmPackageExtensionVisitor {
abstract class KlibPackageExtensionVisitor : KmPackageExtension {
abstract fun visitFqName(name: String)
@@ -117,7 +115,7 @@ abstract class KlibPackageExtensionVisitor : KmPackageExtensionVisitor {
}
}
abstract class KlibModuleFragmentExtensionVisitor : KmModuleFragmentExtensionVisitor {
abstract class KlibModuleFragmentExtensionVisitor : KmModuleFragmentExtension {
abstract fun visitFile(file: KlibSourceFile)
@@ -133,7 +131,7 @@ abstract class KlibModuleFragmentExtensionVisitor : KmModuleFragmentExtensionVis
}
}
abstract class KlibTypeAliasExtensionVisitor : KmTypeAliasExtensionVisitor {
abstract class KlibTypeAliasExtensionVisitor : KmTypeAliasExtension {
abstract fun visitUniqId(uniqId: UniqId)
@@ -145,7 +143,7 @@ abstract class KlibTypeAliasExtensionVisitor : KmTypeAliasExtensionVisitor {
}
}
abstract class KlibValueParameterExtensionVisitor : KmValueParameterExtensionVisitor {
abstract class KlibValueParameterExtensionVisitor : KmValueParameterExtension {
abstract fun visitAnnotation(annotation: KmAnnotation)
@@ -159,23 +159,7 @@ public sealed class KmAnnotationArgument {
*
* @property className FQ name of the referenced class.
*/
@Suppress("DEPRECATION_ERROR")
public data class KClassValue @Deprecated(
"Use single-argument constructor instead or ArrayKClassValue",
level = DeprecationLevel.ERROR
) constructor(
val className: ClassName,
@Deprecated(
"Use ArrayKClassValue instead",
level = DeprecationLevel.ERROR
) val arrayDimensionCount: Int
) : KmAnnotationArgument() {
public constructor(className: ClassName) : this(className, 0)
init {
require(arrayDimensionCount == 0) { "KClassValue must not have array dimensions. For Array<X>::class, use ArrayKClassValue." }
}
public data class KClassValue(val className: ClassName) : KmAnnotationArgument() {
override fun toString(): String = "KClassValue($className)"
}
@@ -3,7 +3,6 @@
* 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("DEPRECATION_ERROR") // flags will become internal eventually
@file:JvmName("Attributes")
package kotlin.metadata
@@ -295,18 +294,6 @@ public var KmProperty.kind: MemberKind by memberKindDelegate(KmProperty::flags)
*/
public var KmProperty.isVar: Boolean by propertyBooleanFlag(FlagImpl(ProtoFlags.IS_VAR))
/**
* Indicates that the corresponding property has a getter.
*/
@Deprecated("Kotlin properties always have getters", ReplaceWith("true"), DeprecationLevel.ERROR)
public var KmProperty.hasGetter: Boolean by propertyBooleanFlag(FlagImpl(ProtoFlags.HAS_GETTER))
/**
* Indicates that the corresponding property has a setter.
*/
@Deprecated("Check .setter for nullability instead", ReplaceWith("this.setter != null"), DeprecationLevel.ERROR)
public var KmProperty.hasSetter: Boolean by propertyBooleanFlag(FlagImpl(ProtoFlags.HAS_SETTER))
/**
* Indicates that the corresponding property is `const`.
*/
@@ -24,10 +24,3 @@ public typealias ClassName = String // Not a value class because of Java usages
* A class name represents a local class or an anonymous object if it starts with '.' (dot).
*/
public fun ClassName.isLocalClassName(): Boolean = this.startsWith(".")
@Deprecated(
"Renamed to isLocalClassName() to avoid confusion with String properties",
ReplaceWith("isLocalClassName()"),
level = DeprecationLevel.ERROR
)
public val ClassName.isLocal: Boolean get() = isLocalClassName()
@@ -0,0 +1,158 @@
/*
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.metadata
import kotlin.contracts.ExperimentalContracts
/**
* Represents a contract of a Kotlin function.
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*/
@ExperimentalContracts
public class KmContract {
/**
* Effects of this contract.
*/
public val effects: MutableList<KmEffect> = ArrayList(1)
}
/**
* Represents an effect (a part of the contract of a Kotlin function).
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*
* @property type type of the effect
* @property invocationKind optional number of invocations of the lambda parameter of this function,
* specified further in the effect expression
*/
@ExperimentalContracts
public class KmEffect(
public var type: KmEffectType,
public var invocationKind: KmEffectInvocationKind?,
) {
/**
* Arguments of the effect constructor, i.e. the constant value for the [KmEffectType.RETURNS_CONSTANT] effect,
* or the parameter reference for the [KmEffectType.CALLS] effect.
*/
public val constructorArguments: MutableList<KmEffectExpression> = ArrayList(1)
/**
* Conclusion of the effect. If this value is set, the effect represents an implication with this value as the right-hand side.
*/
public var conclusion: KmEffectExpression? = null
}
/**
* Represents an effect expression, the contents of an effect (a part of the contract of a Kotlin function).
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*
* Various effect expression attributes can be read and manipulated via extension properties,
* such as [KmEffectExpression.isNegated].
*/
@ExperimentalContracts
public class KmEffectExpression {
internal var flags: Int = 0
/**
* Optional 1-based index of the value parameter of the function, for effects which assert something about
* the function parameters. Index 0 means the extension receiver parameter.
*/
public var parameterIndex: Int? = null
/**
* Constant value used in the effect expression.
*/
public var constantValue: KmConstantValue? = null
/**
* Type used as the target of an `is`-expression in the effect expression.
*/
public var isInstanceType: KmType? = null
/**
* Arguments of an `&&`-expression. If this list is non-empty, the resulting effect expression is a conjunction of this expression
* and elements of the list.
*/
public val andArguments: MutableList<KmEffectExpression> = ArrayList(0)
/**
* Arguments of an `||`-expression. If this list is non-empty, the resulting effect expression is a disjunction of this expression
* and elements of the list.
*/
public val orArguments: MutableList<KmEffectExpression> = ArrayList(0)
}
/**
* Represents a constant value used in an effect expression.
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*
* @property value the constant value. May be `true`, `false` or `null`
*/
@ExperimentalContracts
public data class KmConstantValue(val value: Any?)
/**
* Type of an effect (a part of the contract of a Kotlin function).
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*/
@ExperimentalContracts
public enum class KmEffectType {
/**
* Represents `returns(value)` contract effect:
* a situation when a function returns normally with the specified return value.
* Return value is stored in the [KmEffect.constructorArguments].
*/
RETURNS_CONSTANT,
/**
* Represents `callsInPlace` contract effect:
* A situation when the referenced lambda is invoked in place (optionally) specified number of times.
*
* Referenced lambda is stored in the [KmEffect.constructorArguments].
* Number of invocations, if specified, is stored in [KmEffect.invocationKind].
*/
CALLS,
/**
* Represents `returnsNotNull` contract effect:
* a situation when a function returns normally with any value that is not null.
*/
RETURNS_NOT_NULL,
}
/**
* Number of invocations of a lambda parameter specified by an effect (a part of the contract of a Kotlin function).
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*/
@ExperimentalContracts
public enum class KmEffectInvocationKind {
/**
* A function parameter will be invoked one time or not invoked at all.
*/
AT_MOST_ONCE,
/**
* A function parameter will be invoked exactly one time.
*/
EXACTLY_ONCE,
/**
* A function parameter will be invoked one or more times.
*/
AT_LEAST_ONCE,
}
@@ -1,113 +0,0 @@
/*
* Copyright 2010-2018 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("DEPRECATION_ERROR")
package kotlin.metadata
import kotlin.reflect.KClass
/**
* A type of the extension visitor expected by the code that uses the visitor API.
*
* Each declaration which can have platform-specific extensions in the metadata has a method `visitExtensions` in its visitor, e.g.:
*
* open fun visitExtensions(type: KmExtensionType): KmFunctionExtensionVisitor?
*
* The client code is supposed to return the extension visitor corresponding to the given type, or to return `null` if the type is
* of no interest to that code. Each platform-specific extension visitor has a [KmExtensionType] instance declared in the `TYPE` property
* its companion object. For example, to load JVM extensions on a function, one could do:
* ```
* override fun visitExtensions(type: KmExtensionType): KmFunctionExtensionVisitor? {
* if (type != JvmFunctionExtensionVisitor.TYPE) return null
*
* return object : JvmFunctionExtensionVisitor() {
* ...
* }
* }
* ```
* In case an extension visitor of an unrelated type is returned, the code using the visitor API must ignore that visitor.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public class KmExtensionType(private val klass: KClass<out KmExtensionVisitor>) {
override fun equals(other: Any?): Boolean =
other is KmExtensionType && klass == other.klass
override fun hashCode(): Int =
klass.hashCode()
override fun toString(): String =
klass.java.name
}
/**
* A base interface for all extension visitors.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmExtensionVisitor {
/**
* Type of this extension visitor.
*/
public val type: KmExtensionType
}
/**
* A visitor to visit platform-specific extensions for a declaration container, such as a class or a package fragment.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmDeclarationContainerExtensionVisitor : KmExtensionVisitor
/**
* A visitor to visit platform-specific extensions for a class.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmClassExtensionVisitor : KmDeclarationContainerExtensionVisitor
/**
* A visitor to visit platform-specific extensions for a package fragment.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmPackageExtensionVisitor : KmDeclarationContainerExtensionVisitor
/**
* A visitor to visit platform-specific extensions for a function.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmFunctionExtensionVisitor : KmExtensionVisitor
/**
* A visitor to visit platform-specific extensions for a property.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmPropertyExtensionVisitor : KmExtensionVisitor
/**
* A visitor to visit platform-specific extensions for a constructor.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmConstructorExtensionVisitor : KmExtensionVisitor
/**
* A visitor to visit platform-specific extensions for a type parameter.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmTypeParameterExtensionVisitor : KmExtensionVisitor
/**
* A visitor to visit platform-specific extensions for a type.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmTypeExtensionVisitor : KmExtensionVisitor
/**
* A visitor to visit platform-specific extensions for a type alias.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmTypeAliasExtensionVisitor : KmExtensionVisitor
/**
* A visitor to visit platform-specific extensions for a value parameter.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmValueParameterExtensionVisitor : KmExtensionVisitor
@@ -1,611 +0,0 @@
/*
* 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.
*/
package kotlin.metadata
import kotlin.metadata.internal.IgnoreInApiDump
import org.jetbrains.kotlin.metadata.ProtoBuf.*
import org.jetbrains.kotlin.metadata.ProtoBuf.Class.Kind as ClassKind
import org.jetbrains.kotlin.metadata.deserialization.Flags as F
import org.jetbrains.kotlin.metadata.ProtoBuf.Modality as ProtoModality
import org.jetbrains.kotlin.metadata.ProtoBuf.Visibility as ProtoVisibility
import org.jetbrains.kotlin.metadata.ProtoBuf.MemberKind as ProtoMemberKind
private const val prefix = "Flag API is deprecated. Please use"
/**
* Represents a boolean flag that is either present or not in a Kotlin declaration. A "flag" is a boolean trait that is either present
* or not in a declaration. To check whether the flag is present in the bitmask, call [Flag.invoke] on the flag, passing the bitmask
* as the argument:
*
* override fun visitFunction(flags: Flags, name: String): KmFunctionVisitor? {
* if (Flag.Function.IS_INLINE(flags)) {
* ...
* }
* }
*
* To construct a bitmask out of several flags, call [flagsOf] on the needed flags:
*
* v.visitFunction(flagsOf(Flag.Function.IS_DECLARATION, Flag.Function.IS_INLINE), "foo")
*
* Flags common to multiple kinds of Kotlin declarations ("common flags") are declared in [Flag.Common].
* Flags applicable to specific kinds of declarations ("declaration-specific flags") are declared in nested objects of the [Flag] object.
*
* Some flags are mutually exclusive, i.e. there are "flag groups" such that no more than one flag from each group can be present
* in the same bitmask. Among common flags, there are the following flag groups:
* * visibility flags: [IS_INTERNAL], [IS_PRIVATE], [IS_PROTECTED], [IS_PUBLIC], [IS_PRIVATE_TO_THIS], [IS_LOCAL]
* * modality flags: [IS_FINAL], [IS_OPEN], [IS_ABSTRACT], [IS_SEALED]
*
* Some declaration-specific flags form other flag groups, see the documentation of the corresponding containers for more information.
*
* @see Flags
* @see flagsOf
*/
@Deprecated("$prefix corresponding extensions on Km nodes, such as KmClass.visibility", level = DeprecationLevel.ERROR)
@Suppress("DEPRECATION_ERROR")
public class Flag public constructor(internal val offset: Int, internal val bitWidth: Int, internal val value: Int) {
// Implementation copies FlagImpl to avoid reusing of deprecated declarations.
@IgnoreInApiDump
internal constructor(field: F.FlagField<*>, value: Int) : this(field.offset, field.bitWidth, value)
@IgnoreInApiDump
internal constructor(field: F.BooleanFlagField) : this(field, 1)
internal operator fun plus(flags: Int): Int =
(flags and (((1 shl bitWidth) - 1) shl offset).inv()) + (value shl offset)
/**
* Checks whether the flag is present in the given bitmask.
*/
public operator fun invoke(flags: Int): Boolean = (flags ushr offset) and ((1 shl bitWidth) - 1) == value
/** @suppress deprecated */
@Deprecated("$prefix corresponding extensions on Km nodes, such as KmClass.visibility", level = DeprecationLevel.ERROR)
public companion object Common {
/**
* Signifies that the corresponding declaration has at least one annotation.
*
* This flag is useful for reading Kotlin metadata on JVM efficiently. On JVM, most of the annotations are written not to the Kotlin
* metadata, but directly on the corresponding declarations in the class file. This flag can be used as an optimization to avoid
* reading annotations from the class file (which can be slow) in case when a declaration has no annotations.
*/
@JvmField
@Deprecated("$prefix corresponding extension on a node, e.g. KmClass.hasAnnotations", level = DeprecationLevel.ERROR)
public val HAS_ANNOTATIONS: Flag = Flag(F.HAS_ANNOTATIONS)
/**
* A visibility flag, signifying that the corresponding declaration is `internal`.
*/
@JvmField
@Deprecated("$prefix visibility extension on a node, e.g. KmClass.visibility", level = DeprecationLevel.ERROR)
public val IS_INTERNAL: Flag = Flag(F.VISIBILITY, ProtoVisibility.INTERNAL_VALUE)
/**
* A visibility flag, signifying that the corresponding declaration is `private`.
*/
@JvmField
@Deprecated("$prefix visibility extension on a node, e.g. KmClass.visibility", level = DeprecationLevel.ERROR)
public val IS_PRIVATE: Flag = Flag(F.VISIBILITY, ProtoVisibility.PRIVATE_VALUE)
/**
* A visibility flag, signifying that the corresponding declaration is `protected`.
*/
@JvmField
@Deprecated("$prefix visibility extension on a node, e.g. KmClass.visibility", level = DeprecationLevel.ERROR)
public val IS_PROTECTED: Flag = Flag(F.VISIBILITY, ProtoVisibility.PROTECTED_VALUE)
/**
* A visibility flag, signifying that the corresponding declaration is `public`.
*/
@JvmField
@Deprecated("$prefix visibility extension on a node, e.g. KmClass.visibility", level = DeprecationLevel.ERROR)
public val IS_PUBLIC: Flag = Flag(F.VISIBILITY, ProtoVisibility.PUBLIC_VALUE)
/**
* A visibility flag, signifying that the corresponding declaration is "private-to-this", which is a non-denotable visibility of
* private members in Kotlin which are callable only on the same instance of the declaring class.
*/
@JvmField
@Deprecated("$prefix visibility extension on a node, e.g. KmClass.visibility", level = DeprecationLevel.ERROR)
public val IS_PRIVATE_TO_THIS: Flag = Flag(F.VISIBILITY, ProtoVisibility.PRIVATE_TO_THIS_VALUE)
/**
* A visibility flag, signifying that the corresponding declaration is local, i.e. declared inside a code block
* and not visible from the outside.
*/
@JvmField
@Deprecated("$prefix visibility extension on a node, e.g. KmClass.visibility", level = DeprecationLevel.ERROR)
public val IS_LOCAL: Flag = Flag(F.VISIBILITY, ProtoVisibility.LOCAL_VALUE)
/**
* A modality flag, signifying that the corresponding declaration is `final`.
*/
@JvmField
@Deprecated("$prefix modality extension on a node, e.g. KmClass.modality or KmFunction.modality", level = DeprecationLevel.ERROR)
public val IS_FINAL: Flag = Flag(F.MODALITY, ProtoModality.FINAL_VALUE)
/**
* A modality flag, signifying that the corresponding declaration is `open`.
*/
@JvmField
@Deprecated("$prefix modality extension on a node, e.g. KmClass.modality or KmFunction.modality", level = DeprecationLevel.ERROR)
public val IS_OPEN: Flag = Flag(F.MODALITY, ProtoModality.OPEN_VALUE)
/**
* A modality flag, signifying that the corresponding declaration is `abstract`.
*/
@JvmField
@Deprecated("$prefix modality extension on a node, e.g. KmClass.modality or KmFunction.modality", level = DeprecationLevel.ERROR)
public val IS_ABSTRACT: Flag = Flag(F.MODALITY, ProtoModality.ABSTRACT_VALUE)
/**
* A modality flag, signifying that the corresponding declaration is `sealed`.
*/
@JvmField
@Deprecated("$prefix modality extension on a node, e.g. KmClass.modality", level = DeprecationLevel.ERROR)
public val IS_SEALED: Flag = Flag(F.MODALITY, ProtoModality.SEALED_VALUE)
}
/**
* A container of flags applicable to Kotlin classes, including interfaces, objects, enum classes and annotation classes.
*
* In addition to the common flag groups, the following flag groups exist for class flags:
* * class kind flags: [IS_CLASS], [IS_INTERFACE], [IS_ENUM_CLASS], [IS_ENUM_ENTRY], [IS_ANNOTATION_CLASS], [IS_OBJECT],
* [IS_COMPANION_OBJECT]
*/
@Deprecated("$prefix corresponding extension on a KmClass", level = DeprecationLevel.ERROR)
public object Class {
/**
* A class kind flag, signifying that the corresponding class is a usual `class`.
*/
@JvmField
@Deprecated("$prefix KmClass.kind", level = DeprecationLevel.ERROR)
public val IS_CLASS: Flag = Flag(F.CLASS_KIND, ClassKind.CLASS_VALUE)
/**
* A class kind flag, signifying that the corresponding class is an `interface`.
*/
@JvmField
@Deprecated("$prefix KmClass.kind", level = DeprecationLevel.ERROR)
public val IS_INTERFACE: Flag = Flag(F.CLASS_KIND, ClassKind.INTERFACE_VALUE)
/**
* A class kind flag, signifying that the corresponding class is an `enum class`.
*/
@JvmField
@Deprecated("$prefix KmClass.kind", level = DeprecationLevel.ERROR)
public val IS_ENUM_CLASS: Flag = Flag(F.CLASS_KIND, ClassKind.ENUM_CLASS_VALUE)
/**
* A class kind flag, signifying that the corresponding class is an enum entry.
*/
@JvmField
@Deprecated("$prefix KmClass.kind", level = DeprecationLevel.ERROR)
public val IS_ENUM_ENTRY: Flag = Flag(F.CLASS_KIND, ClassKind.ENUM_ENTRY_VALUE)
/**
* A class kind flag, signifying that the corresponding class is an `annotation class`.
*/
@JvmField
@Deprecated("$prefix KmClass.kind", level = DeprecationLevel.ERROR)
public val IS_ANNOTATION_CLASS: Flag = Flag(F.CLASS_KIND, ClassKind.ANNOTATION_CLASS_VALUE)
/**
* A class kind flag, signifying that the corresponding class is a non-companion `object`.
*/
@JvmField
@Deprecated("$prefix KmClass.kind", level = DeprecationLevel.ERROR)
public val IS_OBJECT: Flag = Flag(F.CLASS_KIND, ClassKind.OBJECT_VALUE)
/**
* A class kind flag, signifying that the corresponding class is a `companion object`.
*/
@JvmField
@Deprecated("$prefix KmClass.kind", level = DeprecationLevel.ERROR)
public val IS_COMPANION_OBJECT: Flag = Flag(F.CLASS_KIND, ClassKind.COMPANION_OBJECT_VALUE)
/**
* Signifies that the corresponding class is `inner`.
*/
@JvmField
@Deprecated("$prefix KmClass.isInner", level = DeprecationLevel.ERROR)
public val IS_INNER: Flag = Flag(F.IS_INNER)
/**
* Signifies that the corresponding class is `data`.
*/
@JvmField
@Deprecated("$prefix KmClass.isData", level = DeprecationLevel.ERROR)
public val IS_DATA: Flag = Flag(F.IS_DATA)
/**
* Signifies that the corresponding class is `external`.
*/
@JvmField
@Deprecated("$prefix KmClass.isExternal", level = DeprecationLevel.ERROR)
public val IS_EXTERNAL: Flag = Flag(F.IS_EXTERNAL_CLASS)
/**
* Signifies that the corresponding class is `expect`.
*/
@JvmField
@Deprecated("$prefix KmClass.isExpect", level = DeprecationLevel.ERROR)
public val IS_EXPECT: Flag = Flag(F.IS_EXPECT_CLASS)
@JvmField
@Deprecated(
"Use IS_VALUE instead, which returns true if the class is either a pre-1.5 inline class, or a 1.5+ value class.",
level = DeprecationLevel.ERROR
)
@Suppress("unused")
public val IS_INLINE: Flag = Flag(F.IS_VALUE_CLASS)
/**
* Signifies that the corresponding class is either a pre-Kotlin-1.5 `inline` class, or a 1.5+ `value` class.
*/
@JvmField
@Deprecated("$prefix KmClass.isValue", level = DeprecationLevel.ERROR)
public val IS_VALUE: Flag = Flag(F.IS_VALUE_CLASS)
/**
* Signifies that the corresponding class is a functional interface, i.e. marked with the keyword `fun`.
*/
@JvmField
@Deprecated("$prefix KmClass.isFun", level = DeprecationLevel.ERROR)
public val IS_FUN: Flag = Flag(F.IS_FUN_INTERFACE)
/**
* Signifies that the corresponding enum class has ".entries" property in bytecode.
* Always `false` for not enum classes.
*/
@JvmField
@Deprecated("$prefix KmClass.hasEnumEntries", level = DeprecationLevel.ERROR)
public val HAS_ENUM_ENTRIES: Flag = Flag(F.HAS_ENUM_ENTRIES)
}
/**
* A container of flags applicable to Kotlin constructors.
*/
public object Constructor {
@JvmField
@Deprecated("Use IS_SECONDARY which holds inverted value instead.", level = DeprecationLevel.ERROR)
@Suppress("unused")
public val IS_PRIMARY: Flag = Flag(F.IS_SECONDARY, 0)
/**
* Signifies that the corresponding constructor is secondary, i.e. declared not in the class header, but in the class body.
*/
@JvmField
@Deprecated("$prefix KmConstructor.isSecondary", level = DeprecationLevel.ERROR)
public val IS_SECONDARY: Flag = Flag(F.IS_SECONDARY)
/**
* Signifies that the corresponding constructor has non-stable parameter names, i.e. cannot be called with named arguments.
*/
@JvmField
@Deprecated("$prefix KmConstructor.hasNonStableParameterNames", level = DeprecationLevel.ERROR)
public val HAS_NON_STABLE_PARAMETER_NAMES: Flag = Flag(F.IS_CONSTRUCTOR_WITH_NON_STABLE_PARAMETER_NAMES)
}
/**
* A container of flags applicable to Kotlin functions.
*
* In addition to the common flag groups, the following flag groups exist for function flags:
* * member kind flags: [IS_DECLARATION], [IS_FAKE_OVERRIDE], [IS_DELEGATION], [IS_SYNTHESIZED]
*/
public object Function {
/**
* A member kind flag, signifying that the corresponding function is explicitly declared in the containing class.
*/
@JvmField
@Deprecated("$prefix KmFunction.kind", level = DeprecationLevel.ERROR)
public val IS_DECLARATION: Flag = Flag(F.MEMBER_KIND, ProtoMemberKind.DECLARATION_VALUE)
/**
* A member kind flag, signifying that the corresponding function exists in the containing class because a function with a suitable
* signature exists in a supertype. This flag is not written by the Kotlin compiler and its effects are unspecified.
*/
@JvmField
@Deprecated("$prefix KmFunction.kind", level = DeprecationLevel.ERROR)
public val IS_FAKE_OVERRIDE: Flag = Flag(F.MEMBER_KIND, ProtoMemberKind.FAKE_OVERRIDE_VALUE)
/**
* A member kind flag, signifying that the corresponding function exists in the containing class because it has been produced
* by interface delegation (delegation "by").
*/
@JvmField
@Deprecated("$prefix KmFunction.kind", level = DeprecationLevel.ERROR)
public val IS_DELEGATION: Flag = Flag(F.MEMBER_KIND, ProtoMemberKind.DELEGATION_VALUE)
/**
* A member kind flag, signifying that the corresponding function exists in the containing class because it has been synthesized
* by the compiler and has no declaration in the source code.
*/
@JvmField
@Deprecated("$prefix KmFunction.kind", level = DeprecationLevel.ERROR)
public val IS_SYNTHESIZED: Flag = Flag(F.MEMBER_KIND, ProtoMemberKind.SYNTHESIZED_VALUE)
/**
* Signifies that the corresponding function is `operator`.
*/
@JvmField
@Deprecated("$prefix KmFunction.isOperator", level = DeprecationLevel.ERROR)
public val IS_OPERATOR: Flag = Flag(F.IS_OPERATOR)
/**
* Signifies that the corresponding function is `infix`.
*/
@JvmField
@Deprecated("$prefix KmFunction.isInfix", level = DeprecationLevel.ERROR)
public val IS_INFIX: Flag = Flag(F.IS_INFIX)
/**
* Signifies that the corresponding function is `inline`.
*/
@JvmField
@Deprecated("$prefix KmFunction.isInline", level = DeprecationLevel.ERROR)
public val IS_INLINE: Flag = Flag(F.IS_INLINE)
/**
* Signifies that the corresponding function is `tailrec`.
*/
@JvmField
@Deprecated("$prefix KmFunction.isTailrec", level = DeprecationLevel.ERROR)
public val IS_TAILREC: Flag = Flag(F.IS_TAILREC)
/**
* Signifies that the corresponding function is `external`.
*/
@JvmField
@Deprecated("$prefix KmFunction.isExternalFunction", level = DeprecationLevel.ERROR)
public val IS_EXTERNAL: Flag = Flag(F.IS_EXTERNAL_FUNCTION)
/**
* Signifies that the corresponding function is `suspend`.
*/
@JvmField
@Deprecated("$prefix KmFunction.isSuspend", level = DeprecationLevel.ERROR)
public val IS_SUSPEND: Flag = Flag(F.IS_SUSPEND)
/**
* Signifies that the corresponding function is `expect`.
*/
@JvmField
@Deprecated("$prefix KmFunction.isExpectFunction", level = DeprecationLevel.ERROR)
public val IS_EXPECT: Flag = Flag(F.IS_EXPECT_FUNCTION)
/**
* Signifies that the corresponding function has non-stable parameter names, i.e. cannot be called with named arguments.
*/
@JvmField
@Deprecated("$prefix KmFunction.isFunctionWithNonStableParameterNames", level = DeprecationLevel.ERROR)
public val HAS_NON_STABLE_PARAMETER_NAMES: Flag = Flag(F.IS_FUNCTION_WITH_NON_STABLE_PARAMETER_NAMES)
}
/**
* A container of flags applicable to Kotlin properties.
*
* In addition to the common flag groups, the following flag groups exist for property flags:
* * member kind flags: [IS_DECLARATION], [IS_FAKE_OVERRIDE], [IS_DELEGATION], [IS_SYNTHESIZED]
*/
public object Property {
/**
* A member kind flag, signifying that the corresponding property is explicitly declared in the containing class.
*/
@JvmField
@Deprecated("$prefix KmProperty.kind", level = DeprecationLevel.ERROR)
public val IS_DECLARATION: Flag = Flag(F.MEMBER_KIND, ProtoMemberKind.DECLARATION_VALUE)
/**
* A member kind flag, signifying that the corresponding property exists in the containing class because a property with a suitable
* signature exists in a supertype. This flag is not written by the Kotlin compiler and its effects are unspecified.
*/
@JvmField
@Deprecated("$prefix KmProperty.kind", level = DeprecationLevel.ERROR)
public val IS_FAKE_OVERRIDE: Flag = Flag(F.MEMBER_KIND, ProtoMemberKind.FAKE_OVERRIDE_VALUE)
/**
* A member kind flag, signifying that the corresponding property exists in the containing class because it has been produced
* by interface delegation (delegation "by").
*/
@JvmField
@Deprecated("$prefix KmProperty.kind", level = DeprecationLevel.ERROR)
public val IS_DELEGATION: Flag = Flag(F.MEMBER_KIND, ProtoMemberKind.DELEGATION_VALUE)
/**
* A member kind flag, signifying that the corresponding property exists in the containing class because it has been synthesized
* by the compiler and has no declaration in the source code.
*/
@JvmField
@Deprecated("$prefix KmProperty.kind", level = DeprecationLevel.ERROR)
public val IS_SYNTHESIZED: Flag = Flag(F.MEMBER_KIND, ProtoMemberKind.SYNTHESIZED_VALUE)
/**
* Signifies that the corresponding property is `var`.
*/
@JvmField
@Deprecated("$prefix KmProperty.isVar", level = DeprecationLevel.ERROR)
public val IS_VAR: Flag = Flag(F.IS_VAR)
/**
* Signifies that the corresponding property has a getter.
*/
@JvmField
@Deprecated("$prefix KmProperty.hasGetter", level = DeprecationLevel.ERROR)
public val HAS_GETTER: Flag = Flag(F.HAS_GETTER)
/**
* Signifies that the corresponding property has a setter.
*/
@JvmField
@Deprecated("$prefix KmProperty.hasSetter", level = DeprecationLevel.ERROR)
public val HAS_SETTER: Flag = Flag(F.HAS_SETTER)
/**
* Signifies that the corresponding property is `const`.
*/
@JvmField
@Deprecated("$prefix KmProperty.isConst", level = DeprecationLevel.ERROR)
public val IS_CONST: Flag = Flag(F.IS_CONST)
/**
* Signifies that the corresponding property is `lateinit`.
*/
@JvmField
@Deprecated("$prefix KmProperty.isLateinit", level = DeprecationLevel.ERROR)
public val IS_LATEINIT: Flag = Flag(F.IS_LATEINIT)
/**
* Signifies that the corresponding property has a constant value. On JVM, this flag allows an optimization similarly to
* [F.HAS_ANNOTATIONS]: constant values of properties are written to the bytecode directly, and this flag can be used to avoid
* reading the value from the bytecode in case there isn't one.
*/
@JvmField
@Deprecated("$prefix KmProperty.hasConstant", level = DeprecationLevel.ERROR)
public val HAS_CONSTANT: Flag = Flag(F.HAS_CONSTANT)
/**
* Signifies that the corresponding property is `external`.
*/
@JvmField
@Deprecated("$prefix KmProperty.isExternal", level = DeprecationLevel.ERROR)
public val IS_EXTERNAL: Flag = Flag(F.IS_EXTERNAL_PROPERTY)
/**
* Signifies that the corresponding property is a delegated property.
*/
@JvmField
@Deprecated("$prefix KmProperty.isDelegated", level = DeprecationLevel.ERROR)
public val IS_DELEGATED: Flag = Flag(F.IS_DELEGATED)
/**
* Signifies that the corresponding property is `expect`.
*/
@JvmField
@Deprecated("$prefix KmProperty.isExpect", level = DeprecationLevel.ERROR)
public val IS_EXPECT: Flag = Flag(F.IS_EXPECT_PROPERTY)
}
/**
* A container of flags applicable to Kotlin property getters and setters.
*/
public object PropertyAccessor {
/**
* Signifies that the corresponding property accessor is not default, i.e. it has a body and/or annotations in the source code.
*/
@JvmField
@Deprecated("$prefix KmPropertyAccessorAttributes.isNotDefault", level = DeprecationLevel.ERROR)
public val IS_NOT_DEFAULT: Flag = Flag(F.IS_NOT_DEFAULT)
/**
* Signifies that the corresponding property accessor is `external`.
*/
@JvmField
@Deprecated("$prefix KmPropertyAccessorAttributes.isExternal", level = DeprecationLevel.ERROR)
public val IS_EXTERNAL: Flag = Flag(F.IS_EXTERNAL_ACCESSOR)
/**
* Signifies that the corresponding property accessor is `inline`.
*/
@JvmField
@Deprecated("$prefix KmPropertyAccessorAttributes.isInline", level = DeprecationLevel.ERROR)
public val IS_INLINE: Flag = Flag(F.IS_INLINE_ACCESSOR)
}
/**
* A container of flags applicable to Kotlin types.
*/
public object Type {
/**
* Signifies that the corresponding type is marked as nullable, i.e. has a question mark at the end of its notation.
*/
@JvmField
@Deprecated("$prefix KmType.isNullable", level = DeprecationLevel.ERROR)
public val IS_NULLABLE: Flag = Flag(0, 1, 1)
/**
* Signifies that the corresponding type is `suspend`.
*/
@JvmField
@Deprecated("$prefix KmType.isSuspend", level = DeprecationLevel.ERROR)
public val IS_SUSPEND: Flag = Flag(F.SUSPEND_TYPE.offset + 1, F.SUSPEND_TYPE.bitWidth, 1)
/**
* Signifies that the corresponding type is
* [definitely non-null](https://kotlinlang.org/docs/whatsnew17.html#stable-definitely-non-nullable-types).
*/
@JvmField
@Deprecated("$prefix KmType.isDefinitelyNonNull", level = DeprecationLevel.ERROR)
public val IS_DEFINITELY_NON_NULL: Flag = Flag(F.DEFINITELY_NOT_NULL_TYPE.offset + 1, F.DEFINITELY_NOT_NULL_TYPE.bitWidth, 1)
}
/**
* A container of flags applicable to Kotlin type parameters.
*/
public object TypeParameter {
/**
* Signifies that the corresponding type parameter is `reified`.
*/
@JvmField
@Deprecated("$prefix KmTypeParameter.isReified", level = DeprecationLevel.ERROR)
public val IS_REIFIED: Flag = Flag(0, 1, 1)
}
/**
* A container of flags applicable to Kotlin value parameters.
*/
public object ValueParameter {
/**
* Signifies that the corresponding value parameter declares a default value. Note that the default value itself can be a complex
* expression and is not available via metadata. Also note that in case of an override of a parameter with default value, the
* parameter in the derived method does _not_ declare the default value ([DECLARES_DEFAULT_VALUE] == false), but the parameter is
* still optional at the call site because the default value from the base method is used.
*/
@JvmField
@Deprecated("$prefix KmValueParameter.declaresDefaultValue", level = DeprecationLevel.ERROR)
public val DECLARES_DEFAULT_VALUE: Flag = Flag(F.DECLARES_DEFAULT_VALUE)
/**
* Signifies that the corresponding value parameter is `crossinline`.
*/
@JvmField
@Deprecated("$prefix KmValueParameter.isCrossinline", level = DeprecationLevel.ERROR)
public val IS_CROSSINLINE: Flag = Flag(F.IS_CROSSINLINE)
/**
* Signifies that the corresponding value parameter is `noinline`.
*/
@JvmField
@Deprecated("$prefix KmValueParameter.isNoinline", level = DeprecationLevel.ERROR)
public val IS_NOINLINE: Flag = Flag(F.IS_NOINLINE)
}
/**
* A container of flags applicable to Kotlin effect expressions.
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*/
public object EffectExpression {
/**
* Signifies that the corresponding effect expression should be negated to compute the proposition or the conclusion of an effect.
*/
@JvmField
@Deprecated("$prefix KmEffectExpression.isNegated", level = DeprecationLevel.ERROR)
public val IS_NEGATED: Flag = Flag(F.IS_NEGATED)
/**
* Signifies that the corresponding effect expression checks whether a value of some variable is `null`.
*/
@JvmField
@Deprecated("$prefix KmEffectExpression.isNullCheckPredicate", level = DeprecationLevel.ERROR)
public val IS_NULL_CHECK_PREDICATE: Flag = Flag(F.IS_NULL_CHECK_PREDICATE)
}
}
@@ -1,37 +0,0 @@
/*
* 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.
*/
@file:JvmName("FlagsKt")
package kotlin.metadata
import kotlin.metadata.internal.FlagImpl
/**
* Declaration flags are represented as bitmasks of this type.
*
* @see Flag
*/
@Deprecated(
"Flags API is deprecated and this typealias will be removed. Use Int directly and then migrate to corresponding Km nodes extensions, e.g. KmClass.visibility",
ReplaceWith("Int"),
DeprecationLevel.ERROR
)
public typealias Flags = Int
/**
* Combines several flags into an integer bitmask.
*
* Note that in case several mutually exclusive flags are passed (for example, several visibility flags), the resulting bitmask will
* hold the value of the latest flag. For example, `flagsOf(Flag.IS_PRIVATE, Flag.IS_PUBLIC, Flag.IS_INTERNAL)` is the same as
* `flagsOf(Flag.IS_INTERNAL)`.
*/
@Suppress("DEPRECATION_ERROR")
@Deprecated(
"Flags API is deprecated and this function will be removed. Create Km nodes directly and then use corresponding Km nodes extensions, e.g. KmClass.visibility",
level = DeprecationLevel.ERROR
)
public fun flagsOf(vararg flags: Flag): Int =
flags.fold(0) { acc, flag -> flag + acc }
@@ -40,13 +40,8 @@ public interface KmDeclarationContainer {
* Precise kind of the class can be obtained via [KmClass.kind].
* Various class attributes can be read and manipulated via extension properties, such as [KmClass.visibility] or [KmClass.isData].
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmClass : KmClassVisitor(), KmDeclarationContainer {
/**
* Class flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag and [Flag.Class] flags.
*/
@Deprecated("$flagAccessPrefix KmClass, such as KmClass.visibility", level = DeprecationLevel.ERROR)
public var flags: Int = 0
public class KmClass : KmDeclarationContainer {
internal var flags: Int = 0
/**
* Name of the class.
@@ -126,105 +121,6 @@ public class KmClass : KmClassVisitor(), KmDeclarationContainer {
internal val extensions: List<KmClassExtension> =
MetadataExtensions.INSTANCES.map(MetadataExtensions::createClassExtension)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visit(flags: Int, name: ClassName) {
this.flags = flags
this.name = name
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor =
KmTypeParameter(flags, name, id, variance).addTo(typeParameters)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitSupertype(flags: Int): KmTypeVisitor =
KmType(flags).addTo(supertypes)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor =
KmFunction(flags, name).addTo(functions)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitProperty(flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor =
KmProperty(flags, name, getterFlags, setterFlags).addTo(properties)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitTypeAlias(flags: Int, name: String): KmTypeAliasVisitor =
KmTypeAlias(flags, name).addTo(typeAliases)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitConstructor(flags: Int): KmConstructorVisitor =
KmConstructor(flags).addTo(constructors)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitCompanionObject(name: String) {
this.companionObject = name
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitNestedClass(name: String) {
nestedClasses.add(name)
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitEnumEntry(name: String) {
enumEntries.add(name)
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitSealedSubclass(name: ClassName) {
sealedSubclasses.add(name)
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitInlineClassUnderlyingPropertyName(name: String) {
inlineClassUnderlyingPropertyName = name
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitInlineClassUnderlyingType(flags: Int): KmTypeVisitor =
KmType(flags).also { inlineClassUnderlyingType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
@ExperimentalContextReceivers
override fun visitContextReceiverType(flags: Int): KmTypeVisitor =
KmType(flags).addTo(contextReceiverTypes)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitVersionRequirement(): KmVersionRequirementVisitor =
KmVersionRequirement().addTo(versionRequirements)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExtensions(type: KmExtensionType): KmClassExtensionVisitor =
extensions.singleOfType(type)
/**
* Populates the given visitor with data in this class.
*
* @param visitor the visitor which will visit data in this class
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
@OptIn(ExperimentalContextReceivers::class)
public fun accept(visitor: KmClassVisitor) {
visitor.visit(flags, name)
typeParameters.forEach { visitor.visitTypeParameter(it.flags, it.name, it.id, it.variance)?.let(it::accept) }
supertypes.forEach { visitor.visitSupertype(it.flags)?.let(it::accept) }
functions.forEach { visitor.visitFunction(it.flags, it.name)?.let(it::accept) }
properties.forEach { visitor.visitProperty(it.flags, it.name, it.getter.flags, it.setterFlags)?.let(it::accept) }
typeAliases.forEach { visitor.visitTypeAlias(it.flags, it.name)?.let(it::accept) }
constructors.forEach { visitor.visitConstructor(it.flags)?.let(it::accept) }
companionObject?.let(visitor::visitCompanionObject)
nestedClasses.forEach(visitor::visitNestedClass)
enumEntries.forEach(visitor::visitEnumEntry)
sealedSubclasses.forEach(visitor::visitSealedSubclass)
inlineClassUnderlyingPropertyName?.let(visitor::visitInlineClassUnderlyingPropertyName)
inlineClassUnderlyingType?.let { visitor.visitInlineClassUnderlyingType(it.flags)?.let(it::accept) }
contextReceiverTypes.forEach { visitor.visitContextReceiverType(it.flags)?.let(it::accept) }
versionRequirements.forEach { visitor.visitVersionRequirement()?.let(it::accept) }
extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
@@ -232,8 +128,7 @@ public class KmClass : KmClassVisitor(), KmDeclarationContainer {
* Package fragments are produced from single file facades and multi-file class parts.
* Note that a package fragment does not contain any classes, as classes are not a part of file facades and have their own metadata.
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmPackage : KmPackageVisitor(), KmDeclarationContainer {
public class KmPackage : KmDeclarationContainer {
/**
* Functions in the package fragment.
*/
@@ -251,62 +146,16 @@ public class KmPackage : KmPackageVisitor(), KmDeclarationContainer {
internal val extensions: List<KmPackageExtension> =
MetadataExtensions.INSTANCES.map(MetadataExtensions::createPackageExtension)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor =
KmFunction(flags, name).addTo(functions)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitProperty(flags: Int, name: String, getterFlags: Int, setterFlags: Int): KmPropertyVisitor =
KmProperty(flags, name, getterFlags, setterFlags).addTo(properties)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitTypeAlias(flags: Int, name: String): KmTypeAliasVisitor =
KmTypeAlias(flags, name).addTo(typeAliases)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExtensions(type: KmExtensionType): KmPackageExtensionVisitor =
extensions.singleOfType(type)
/**
* Populates the given visitor with data in this package fragment.
*
* @param visitor the visitor which will visit data in this package fragment
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmPackageVisitor) {
functions.forEach { visitor.visitFunction(it.flags, it.name)?.let(it::accept) }
properties.forEach { visitor.visitProperty(it.flags, it.name, it.getter.flags, it.setterFlags)?.let(it::accept) }
typeAliases.forEach { visitor.visitTypeAlias(it.flags, it.name)?.let(it::accept) }
extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
* Represents a synthetic class generated for a Kotlin lambda.
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmLambda : KmLambdaVisitor() {
public class KmLambda {
/**
* Signature of the synthetic anonymous function, representing the lambda.
*/
public lateinit var function: KmFunction
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitFunction(flags: Int, name: String): KmFunctionVisitor =
KmFunction(flags, name).also { function = it }
/**
* Populates the given visitor with data in this lambda.
*
* @param visitor the visitor which will visit data in this lambda
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmLambdaVisitor) {
visitor.visitFunction(function.flags, function.name)?.let(function::accept)
visitor.visitEnd()
}
}
/**
@@ -315,11 +164,7 @@ public class KmLambda : KmLambdaVisitor() {
* Various constructor attributes can be read and manipulated via extension properties,
* such as [KmConstructor.visibility] or [KmConstructor.isSecondary].
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmConstructor @Deprecated(flagsCtorDeprecated, level = DeprecationLevel.ERROR) constructor(
@Deprecated("$flagAccessPrefix KmConstructor, such as KmConstructor.visibility", level = DeprecationLevel.ERROR) public var flags: Int,
) :
KmConstructorVisitor() {
public class KmConstructor internal constructor(internal var flags: Int) {
public constructor() : this(0)
/**
@@ -334,31 +179,6 @@ public class KmConstructor @Deprecated(flagsCtorDeprecated, level = DeprecationL
internal val extensions: List<KmConstructorExtension> =
MetadataExtensions.INSTANCES.map(MetadataExtensions::createConstructorExtension)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitValueParameter(flags: Int, name: String): KmValueParameterVisitor =
KmValueParameter(flags, name).addTo(valueParameters)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitVersionRequirement(): KmVersionRequirementVisitor =
KmVersionRequirement().addTo(versionRequirements)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExtensions(type: KmExtensionType): KmConstructorExtensionVisitor =
extensions.singleOfType(type)
/**
* Populates the given visitor with data in this constructor.
*
* @param visitor the visitor which will visit data in this class
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmConstructorVisitor) {
valueParameters.forEach { visitor.visitValueParameter(it.flags, it.name)?.let(it::accept) }
versionRequirements.forEach { visitor.visitVersionRequirement()?.let(it::accept) }
extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
@@ -369,11 +189,7 @@ public class KmConstructor @Deprecated(flagsCtorDeprecated, level = DeprecationL
*
* @property name the name of the function
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmFunction @Deprecated(flagsCtorDeprecated, level = DeprecationLevel.ERROR) constructor(
@Deprecated("$flagAccessPrefix KmFunction, such as KmFunction.visibility", level = DeprecationLevel.ERROR) public var flags: Int,
public var name: String,
) : KmFunctionVisitor() {
public class KmFunction internal constructor(internal var flags: Int, public var name: String) {
public constructor(name: String) : this(0, name)
@@ -416,59 +232,6 @@ public class KmFunction @Deprecated(flagsCtorDeprecated, level = DeprecationLeve
internal val extensions: List<KmFunctionExtension> =
MetadataExtensions.INSTANCES.map(MetadataExtensions::createFunctionExtension)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor =
KmTypeParameter(flags, name, id, variance).addTo(typeParameters)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitReceiverParameterType(flags: Int): KmTypeVisitor =
KmType(flags).also { receiverParameterType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
@ExperimentalContextReceivers
override fun visitContextReceiverType(flags: Int): KmTypeVisitor =
KmType(flags).addTo(contextReceiverTypes)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitValueParameter(flags: Int, name: String): KmValueParameterVisitor =
KmValueParameter(flags, name).addTo(valueParameters)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitReturnType(flags: Int): KmTypeVisitor =
KmType(flags).also { returnType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitVersionRequirement(): KmVersionRequirementVisitor =
KmVersionRequirement().addTo(versionRequirements)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
@ExperimentalContracts
override fun visitContract(): KmContractVisitor =
KmContract().also { contract = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExtensions(type: KmExtensionType): KmFunctionExtensionVisitor =
extensions.singleOfType(type)
/**
* Populates the given visitor with data in this function.
*
* @param visitor the visitor which will visit data in this function
*/
@OptIn(ExperimentalContextReceivers::class)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public 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) }
contextReceiverTypes.forEach { visitor.visitContextReceiverType(it.flags)?.let(it::accept) }
valueParameters.forEach { visitor.visitValueParameter(it.flags, it.name)?.let(it::accept) }
visitor.visitReturnType(returnType.flags)?.let(returnType::accept)
versionRequirements.forEach { visitor.visitVersionRequirement()?.let(it::accept) }
@OptIn(ExperimentalContracts::class) contract?.let { visitor.visitContract()?.let(it::accept) }
extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
@@ -491,14 +254,12 @@ public class KmPropertyAccessorAttributes internal constructor(internal var flag
*
* @property name the name of the property
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmProperty @Deprecated(flagsCtorDeprecated, level = DeprecationLevel.ERROR) constructor(
@Deprecated("$flagAccessPrefix KmProperty, such as KmProperty.visibility", level = DeprecationLevel.ERROR) public var flags: Int,
public class KmProperty internal constructor(
internal var flags: Int,
public var name: String,
getterFlags: Int,
setterFlags: Int,
) : KmPropertyVisitor() {
) {
public constructor(name: String) : this(0, name, 0, 0)
// needed for reading/writing flags back to protobuf as a whole pack
@@ -527,41 +288,6 @@ public class KmProperty @Deprecated(flagsCtorDeprecated, level = DeprecationLeve
field = new
}
/**
* A legacy accessor for getter attributes.
*
* Property accessor flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag
* and [Flag.PropertyAccessor] flags.
*/
@Deprecated("$flagAccessPrefix KmProperty.getter, such as KmProperty.getter.isNotDefault", level = DeprecationLevel.ERROR)
public var getterFlags: Int
get() = getter.flags
set(value) {
getter.flags = value
}
/**
* A legacy accessor to setter attributes.
*
* Property accessor flags, consisting of [Flag.HAS_ANNOTATIONS], visibility flag, modality flag
* and [Flag.PropertyAccessor] flags.
*
* Note that, for compatibility reasons, flags are present even the property is `val` and `setter` is null.
* In that case, flags for hasAnnotation, visibility and modality are copied from properties' flag, which may lead
* to incorrect results. For example, when property is annotated, [setterFlags] will also return true for [Flag.Common.HAS_ANNOTATIONS],
* even though there is no setter nor annotations on it.
*
* Setting this property when setter is absent changes the value, but does not create new [setter].
* This behavior is for compatibility only and will be removed in future versions.
*/
@Deprecated("$flagAccessPrefix KmProperty.setter, such as KmProperty.setter.isNotDefault", level = DeprecationLevel.ERROR)
public var setterFlags: Int = setterFlags // It's either the correct flags from deserializer, or always 0 in the case of hand-created property
get() = setter?.flags ?: field
set(value) {
setter?.flags = value
field = value
}
/**
* Type parameters of the property.
*/
@@ -603,53 +329,6 @@ public class KmProperty @Deprecated(flagsCtorDeprecated, level = DeprecationLeve
internal val extensions: List<KmPropertyExtension> =
MetadataExtensions.INSTANCES.map(MetadataExtensions::createPropertyExtension)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor =
KmTypeParameter(flags, name, id, variance).addTo(typeParameters)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitReceiverParameterType(flags: Int): KmTypeVisitor =
KmType(flags).also { receiverParameterType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
@ExperimentalContextReceivers
override fun visitContextReceiverType(flags: Int): KmTypeVisitor =
KmType(flags).addTo(contextReceiverTypes)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitSetterParameter(flags: Int, name: String): KmValueParameterVisitor =
KmValueParameter(flags, name).also { setterParameter = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitReturnType(flags: Int): KmTypeVisitor =
KmType(flags).also { returnType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitVersionRequirement(): KmVersionRequirementVisitor =
KmVersionRequirement().addTo(versionRequirements)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExtensions(type: KmExtensionType): KmPropertyExtensionVisitor =
extensions.singleOfType(type)
/**
* Populates the given visitor with data in this property.
*
* @param visitor the visitor which will visit data in this property
*/
@OptIn(ExperimentalContextReceivers::class)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public 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) }
contextReceiverTypes.forEach { visitor.visitContextReceiverType(it.flags)?.let(it::accept) }
setterParameter?.let { visitor.visitSetterParameter(it.flags, it.name)?.let(it::accept) }
visitor.visitReturnType(returnType.flags)?.let(returnType::accept)
versionRequirements.forEach { visitor.visitVersionRequirement()?.let(it::accept) }
extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
@@ -660,11 +339,10 @@ public class KmProperty @Deprecated(flagsCtorDeprecated, level = DeprecationLeve
*
* @property name the name of the type alias
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmTypeAlias @Deprecated(flagsCtorDeprecated, level = DeprecationLevel.ERROR) constructor(
@Deprecated("$flagAccessPrefix KmTypeAlias, such as KmTypeAlias.visibility", level = DeprecationLevel.ERROR) public var flags: Int,
public class KmTypeAlias internal constructor(
internal var flags: Int,
public var name: String,
) : KmTypeAliasVisitor() {
) {
public constructor(name: String) : this(0, name)
@@ -696,47 +374,6 @@ public class KmTypeAlias @Deprecated(flagsCtorDeprecated, level = DeprecationLev
internal val extensions: List<KmTypeAliasExtension> =
MetadataExtensions.INSTANCES.mapNotNull(MetadataExtensions::createTypeAliasExtension)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitTypeParameter(flags: Int, name: String, id: Int, variance: KmVariance): KmTypeParameterVisitor =
KmTypeParameter(flags, name, id, variance).addTo(typeParameters)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitUnderlyingType(flags: Int): KmTypeVisitor =
KmType(flags).also { underlyingType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExpandedType(flags: Int): KmTypeVisitor =
KmType(flags).also { expandedType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitAnnotation(annotation: KmAnnotation) {
annotations.add(annotation)
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExtensions(type: KmExtensionType): KmTypeAliasExtensionVisitor? =
extensions.singleOfType(type)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitVersionRequirement(): KmVersionRequirementVisitor =
KmVersionRequirement().addTo(versionRequirements)
/**
* Populates the given visitor with data in this type alias.
*
* @param visitor the visitor which will visit data in this type alias
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public 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)
visitor.visitExpandedType(expandedType.flags)?.let(expandedType::accept)
annotations.forEach(visitor::visitAnnotation)
versionRequirements.forEach { visitor.visitVersionRequirement()?.let(it::accept) }
extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
@@ -747,14 +384,10 @@ public class KmTypeAlias @Deprecated(flagsCtorDeprecated, level = DeprecationLev
*
* @property name the name of the value parameter
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmValueParameter @Deprecated(flagsCtorDeprecated, level = DeprecationLevel.ERROR) constructor(
@Deprecated(
"$flagAccessPrefix KmValueParameter, such as KmValueParameter.declaresDefaultValue",
level = DeprecationLevel.ERROR
) public var flags: Int,
public class KmValueParameter internal constructor(
internal var flags: Int,
public var name: String,
) : KmValueParameterVisitor() {
) {
public constructor(name: String) : this(0, name)
@@ -771,31 +404,6 @@ public class KmValueParameter @Deprecated(flagsCtorDeprecated, level = Deprecati
internal val extensions: List<KmValueParameterExtension> =
MetadataExtensions.INSTANCES.mapNotNull(MetadataExtensions::createValueParameterExtension)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitType(flags: Int): KmTypeVisitor =
KmType(flags).also { type = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitVarargElementType(flags: Int): KmTypeVisitor =
KmType(flags).also { varargElementType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExtensions(type: KmExtensionType): KmValueParameterExtensionVisitor? =
extensions.singleOfType(type)
/**
* Populates the given visitor with data in this value parameter.
*
* @param visitor the visitor which will visit data in this value parameter
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmValueParameterVisitor) {
visitor.visitType(type.flags)?.let(type::accept)
varargElementType?.let { visitor.visitVarargElementType(it.flags)?.let(it::accept) }
extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
@@ -809,16 +417,12 @@ public class KmValueParameter @Deprecated(flagsCtorDeprecated, level = Deprecati
* the name is not enough (e.g. `class A<T> { fun <T> foo(t: T) }`)
* @property variance the declaration-site variance of the type parameter
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmTypeParameter @Deprecated(flagsCtorDeprecated, level = DeprecationLevel.ERROR) constructor(
@Deprecated(
"$flagAccessPrefix KmTypeParameter, such as KmTypeParameter.isReified",
level = DeprecationLevel.ERROR
) public var flags: Int,
public class KmTypeParameter internal constructor(
internal var flags: Int,
public var name: String,
public var id: Int,
public var variance: KmVariance,
) : KmTypeParameterVisitor() {
) {
public constructor(name: String, id: Int, variance: KmVariance) : this(0, name, id, variance)
@@ -829,26 +433,6 @@ public class KmTypeParameter @Deprecated(flagsCtorDeprecated, level = Deprecatio
internal val extensions: List<KmTypeParameterExtension> =
MetadataExtensions.INSTANCES.map(MetadataExtensions::createTypeParameterExtension)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitUpperBound(flags: Int): KmTypeVisitor =
KmType(flags).addTo(upperBounds)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExtensions(type: KmExtensionType): KmTypeParameterExtensionVisitor =
extensions.singleOfType(type)
/**
* Populates the given visitor with data in this type parameter.
*
* @param visitor the visitor which will visit data in this type parameter
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmTypeParameterVisitor) {
upperBounds.forEach { visitor.visitUpperBound(it.flags)?.let(it::accept) }
extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
@@ -857,10 +441,9 @@ public class KmTypeParameter @Deprecated(flagsCtorDeprecated, level = Deprecatio
* Various type attributes can be read and manipulated via extension properties,
* such as [KmType.isNullable].
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmType @Deprecated(flagsCtorDeprecated, level = DeprecationLevel.ERROR) constructor(
@Deprecated("$flagAccessPrefix KmType, such as KmType.isNullable", level = DeprecationLevel.ERROR) public var flags: Int,
) : KmTypeVisitor() {
public class KmType internal constructor(
internal var flags: Int,
) {
public constructor() : this(0)
@@ -906,75 +489,6 @@ public class KmType @Deprecated(flagsCtorDeprecated, level = DeprecationLevel.ER
internal val extensions: List<KmTypeExtension> =
MetadataExtensions.INSTANCES.map(MetadataExtensions::createTypeExtension)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitClass(name: ClassName) {
classifier = KmClassifier.Class(name)
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitTypeAlias(name: ClassName) {
classifier = KmClassifier.TypeAlias(name)
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitTypeParameter(id: Int) {
classifier = KmClassifier.TypeParameter(id)
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitArgument(flags: Int, variance: KmVariance): KmTypeVisitor =
KmType(flags).also { arguments.add(KmTypeProjection(variance, it)) }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitStarProjection() {
arguments.add(KmTypeProjection.STAR)
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitAbbreviatedType(flags: Int): KmTypeVisitor =
KmType(flags).also { abbreviatedType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitOuterType(flags: Int): KmTypeVisitor =
KmType(flags).also { outerType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitFlexibleTypeUpperBound(flags: Int, typeFlexibilityId: String?): KmTypeVisitor =
KmType(flags).also { flexibleTypeUpperBound = KmFlexibleTypeUpperBound(it, typeFlexibilityId) }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExtensions(type: KmExtensionType): KmTypeExtensionVisitor =
extensions.singleOfType(type)
/**
* Populates the given visitor with data in this type.
*
* @param visitor the visitor which will visit data in this type
* @throws IllegalArgumentException if type metadata is inconsistent
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmTypeVisitor) {
when (val classifier = classifier) {
is KmClassifier.Class -> visitor.visitClass(classifier.name)
is KmClassifier.TypeParameter -> visitor.visitTypeParameter(classifier.id)
is KmClassifier.TypeAlias -> visitor.visitTypeAlias(classifier.name)
}
arguments.forEach { argument ->
if (argument == KmTypeProjection.STAR) visitor.visitStarProjection()
else {
val (variance, type) = argument
if (variance == null || type == null)
throw InconsistentKotlinMetadataException("Variance and type must be set for non-star type projection")
visitor.visitArgument(type.flags, variance)?.let(type::accept)
}
}
abbreviatedType?.let { visitor.visitAbbreviatedType(it.flags)?.let(it::accept) }
outerType?.let { visitor.visitOuterType(it.flags)?.let(it::accept) }
flexibleTypeUpperBound?.let { visitor.visitFlexibleTypeUpperBound(it.type.flags, it.typeFlexibilityId)?.let(it.type::accept) }
extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
@@ -983,8 +497,7 @@ public class KmType @Deprecated(flagsCtorDeprecated, level = DeprecationLevel.ER
* Version requirement is an internal feature of the Kotlin compiler and the standard Kotlin library,
* enabled, for example, with the internal [kotlin.internal.RequireKotlin] annotation.
*/
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmVersionRequirement : KmVersionRequirementVisitor() {
public class KmVersionRequirement {
/**
* Kind of the version that this declaration requires.
*/
@@ -1010,31 +523,6 @@ public class KmVersionRequirement : KmVersionRequirementVisitor() {
*/
public lateinit var version: KmVersion
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visit(kind: KmVersionRequirementVersionKind, level: KmVersionRequirementLevel, errorCode: Int?, message: String?) {
this.kind = kind
this.level = level
this.errorCode = errorCode
this.message = message
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitVersion(major: Int, minor: Int, patch: Int) {
this.version = KmVersion(major, minor, patch)
}
/**
* Populates the given visitor with data in this version requirement.
*
* @param visitor the visitor which will visit data in this version requirement
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmVersionRequirementVisitor) {
visitor.visit(kind, level, errorCode, message)
visitor.visitVersion(version.major, version.minor, version.patch)
visitor.visitEnd()
}
/**
* Returns the String representation of this KmVersionRequirement object, consisting of
* [kind], [level], [version], [errorCode], and [message].
@@ -1044,169 +532,6 @@ public class KmVersionRequirement : KmVersionRequirementVisitor() {
}
}
/**
* Represents a contract of a Kotlin function.
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*/
@ExperimentalContracts
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmContract : KmContractVisitor() {
/**
* Effects of this contract.
*/
public val effects: MutableList<KmEffect> = ArrayList(1)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitEffect(type: KmEffectType, invocationKind: KmEffectInvocationKind?): KmEffectVisitor =
KmEffect(type, invocationKind).addTo(effects)
/**
* Populates the given visitor with data in this contract.
*
* @param visitor the visitor which will visit data in this contract
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmContractVisitor) {
effects.forEach { visitor.visitEffect(it.type, it.invocationKind)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
* Represents an effect (a part of the contract of a Kotlin function).
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*
* @property type type of the effect
* @property invocationKind optional number of invocations of the lambda parameter of this function,
* specified further in the effect expression
*/
@ExperimentalContracts
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmEffect(
public var type: KmEffectType,
public var invocationKind: KmEffectInvocationKind?
) : KmEffectVisitor() {
/**
* Arguments of the effect constructor, i.e. the constant value for the [KmEffectType.RETURNS_CONSTANT] effect,
* or the parameter reference for the [KmEffectType.CALLS] effect.
*/
public val constructorArguments: MutableList<KmEffectExpression> = ArrayList(1)
/**
* Conclusion of the effect. If this value is set, the effect represents an implication with this value as the right-hand side.
*/
public var conclusion: KmEffectExpression? = null
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitConstructorArgument(): KmEffectExpressionVisitor =
KmEffectExpression().addTo(constructorArguments)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitConclusionOfConditionalEffect(): KmEffectExpressionVisitor =
KmEffectExpression().also { conclusion = it }
/**
* Populates the given visitor with data in this effect.
*
* @param visitor the visitor which will visit data in this effect
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmEffectVisitor) {
constructorArguments.forEach { visitor.visitConstructorArgument()?.let(it::accept) }
conclusion?.let { visitor.visitConclusionOfConditionalEffect()?.let(it::accept) }
visitor.visitEnd()
}
}
/**
* Represents an effect expression, the contents of an effect (a part of the contract of a Kotlin function).
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*
* Various effect expression attributes can be read and manipulated via extension properties,
* such as [KmEffectExpression.isNegated].
*/
@ExperimentalContracts
@Suppress("DEPRECATION", "DEPRECATION_ERROR")
public class KmEffectExpression : KmEffectExpressionVisitor() {
/**
* Effect expression flags, consisting of [Flag.EffectExpression] flags.
*/
@Deprecated("$flagAccessPrefix KmEffectExpression, such as KmEffectExpression.isNegated", level = DeprecationLevel.ERROR)
public var flags: Int = flagsOf()
/**
* Optional 1-based index of the value parameter of the function, for effects which assert something about
* the function parameters. Index 0 means the extension receiver parameter.
*/
public var parameterIndex: Int? = null
/**
* Constant value used in the effect expression.
*/
public var constantValue: KmConstantValue? = null
/**
* Type used as the target of an `is`-expression in the effect expression.
*/
public var isInstanceType: KmType? = null
/**
* Arguments of an `&&`-expression. If this list is non-empty, the resulting effect expression is a conjunction of this expression
* and elements of the list.
*/
public val andArguments: MutableList<KmEffectExpression> = ArrayList(0)
/**
* Arguments of an `||`-expression. If this list is non-empty, the resulting effect expression is a disjunction of this expression
* and elements of the list.
*/
public val orArguments: MutableList<KmEffectExpression> = ArrayList(0)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visit(flags: Int, parameterIndex: Int?) {
this.flags = flags
this.parameterIndex = parameterIndex
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitConstantValue(value: Any?) {
constantValue = KmConstantValue(value)
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitIsInstanceType(flags: Int): KmTypeVisitor =
KmType(flags).also { isInstanceType = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitAndArgument(): KmEffectExpressionVisitor =
KmEffectExpression().addTo(andArguments)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitOrArgument(): KmEffectExpressionVisitor =
KmEffectExpression().addTo(orArguments)
/**
* Populates the given visitor with data in this effect expression.
*
* @param visitor the visitor which will visit data in this effect expression
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmEffectExpressionVisitor) {
visitor.visit(flags, parameterIndex)
constantValue?.let { visitor.visitConstantValue(it.value) }
isInstanceType?.let { visitor.visitIsInstanceType(it.flags)?.let(it::accept) }
andArguments.forEach { visitor.visitAndArgument()?.let(it::accept) }
orArguments.forEach { visitor.visitOrArgument()?.let(it::accept) }
visitor.visitEnd()
}
}
/**
* Represents a classifier of a Kotlin type. A classifier is a class, type parameter, or type alias.
* For example, in `MutableMap<in String?, *>`, `MutableMap` is the classifier.
@@ -1265,6 +590,27 @@ public data class KmTypeProjection(var variance: KmVariance?, var type: KmType?)
*/
public data class KmFlexibleTypeUpperBound(var type: KmType, var typeFlexibilityId: String?)
/**
* Variance applied to a type parameter on the declaration site (*declaration-site variance*),
* or to a type in a projection (*use-site variance*).
*/
public enum class KmVariance {
/**
* The affected type parameter or type is *invariant*, which means it has no variance applied to it.
*/
INVARIANT,
/**
* The affected type parameter or type is *contravariant*. Denoted by the `in` modifier in the source code.
*/
IN,
/**
* The affected type parameter or type is *covariant*. Denoted by the `out` modifier in the source code.
*/
OUT,
}
/**
* Represents a version used in a version requirement.
*
@@ -1281,22 +627,57 @@ public data class KmVersion(val major: Int, val minor: Int, val patch: Int) {
}
/**
* Represents a constant value used in an effect expression.
*
* Contracts are an internal feature of the standard Kotlin library, and their behavior and/or binary format
* may change in a subsequent release.
*
* @property value the constant value. May be `true`, `false` or `null`
* Severity of the diagnostic reported by the compiler when a version requirement is not satisfied.
*/
@ExperimentalContracts
public data class KmConstantValue(val value: Any?)
public enum class KmVersionRequirementLevel {
/**
* Represents a diagnostic with 'WARNING' severity.
*/
WARNING,
internal fun <T> T.addTo(collection: MutableCollection<T>): T {
collection.add(this)
return this
/**
* Represents a diagnostic with 'ERROR' severity.
*/
ERROR,
/**
* Excludes the declaration from the resolution process completely when the version requirement is not satisfied.
*/
HIDDEN,
}
private const val flagsCtorDeprecated =
"Constructor with flags is deprecated, use constructor without flags and assign them or corresponding extension properties directly."
/**
* The kind of the version that is required by a version requirement.
*/
public enum class KmVersionRequirementVersionKind {
/**
* Indicates that certain language version is required.
*/
LANGUAGE_VERSION,
private const val flagAccessPrefix = "Flag API is deprecated. Please use corresponding member extensions on"
/**
* Indicates that certain compiler version is required.
*/
COMPILER_VERSION,
/**
* Indicates that certain API version is required.
*/
API_VERSION,
/**
* Represents a version requirement not successfully parsed from the metadata.
*
* The old metadata format (from Kotlin 1.3 and earlier) did not have enough information for correct parsing of version requirements in some cases,
* so a stub of this kind is inserted instead.
*
* [KmVersionRequirement] with this kind always has [KmVersionRequirementLevel.HIDDEN] level, `256.256.256` [KmVersionRequirement.version],
* and `null` [KmVersionRequirement.errorCode] and [KmVersionRequirement.message].
*
* Version requirements of this kind are being ignored by writers (i.e., are not written back).
*
* See the following issues for details: [KT-60870](https://youtrack.jetbrains.com/issue/KT-60870), [KT-25120](https://youtrack.jetbrains.com/issue/KT-25120)
*/
UNKNOWN
;
}
File diff suppressed because it is too large Load Diff
@@ -2,8 +2,6 @@
* 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.
*/
@file:Suppress("DEPRECATION_ERROR") // flags will become internal eventually
package kotlin.metadata.internal
import kotlin.metadata.*
@@ -73,3 +71,11 @@ internal fun valueParameterBooleanFlag(flag: Flag) = BooleanFlagDelegate(KmValue
internal fun <Node> annotationsOn(flags: KMutableProperty1<Node, Int>) = BooleanFlagDelegate(flags, Flag(ProtoFlags.HAS_ANNOTATIONS))
// Used for kotlin-metadata-jvm tests:
public fun _flagAccess(kmClass: KmClass): Int = kmClass.flags
public fun _flagAccess(kmFunc: KmFunction): Int = kmFunc.flags
public fun _flagAccess(kmType: KmType): Int = kmType.flags
public fun _flagAccess(kmConstr: KmConstructor): Int = kmConstr.flags
@@ -2,8 +2,6 @@
* 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.
*/
@file:Suppress("DEPRECATION_ERROR") // flags will become internal eventually
package kotlin.metadata.internal
import kotlin.metadata.*
@@ -2,7 +2,6 @@
* 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.
*/
@file:Suppress("DEPRECATION_ERROR") // flags will become internal eventually
package kotlin.metadata.internal
import kotlin.metadata.*
@@ -2,21 +2,16 @@
* 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.
*/
@file:Suppress("DEPRECATION_ERROR") // deprecated .accept implementation
package kotlin.metadata.internal.common
import kotlin.metadata.*
import kotlin.metadata.VISITOR_API_MESSAGE
import kotlin.metadata.internal.toKmPackage
import kotlin.metadata.internal.toKmClass
import kotlin.metadata.internal.extensions.KmModuleFragmentExtension
import kotlin.metadata.internal.extensions.MetadataExtensions
import kotlin.metadata.internal.extensions.singleOfType
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.builtins.readBuiltinsPackageFragment
import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl
import java.io.ByteArrayInputStream
import kotlin.metadata.internal.extensions.*
/**
* Reads metadata that is not from annotation nor from `.kotlin_module` file.
@@ -27,22 +22,11 @@ public class KotlinCommonMetadata private constructor(proto: ProtoBuf.PackageFra
public val kmModuleFragment: KmModuleFragment = readImpl(proto)
@Deprecated(
"To avoid excessive copying, use .kmModuleFragment property instead. Note that it returns a view and not a copy.",
ReplaceWith("kmModuleFragment"),
DeprecationLevel.ERROR
)
public fun toKmModuleFragment(): KmModuleFragment =
KmModuleFragment().apply { kmModuleFragment.accept(this) }
// private because there are no use-cases and it is not finished
private class Writer : KmModuleFragmentVisitor() {
private class Writer {
// TODO
}
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(v: KmModuleFragmentVisitor): Unit = kmModuleFragment.accept(v)
private fun readImpl(proto: ProtoBuf.PackageFragment): KmModuleFragment {
val v = KmModuleFragment()
val strings = NameResolverImpl(proto.strings, proto.qualifiedNames)
@@ -73,7 +57,7 @@ public class KotlinCommonMetadata private constructor(proto: ProtoBuf.PackageFra
*
* Can be read with [KotlinCommonMetadata.read].
*/
public class KmModuleFragment : KmModuleFragmentVisitor() {
public class KmModuleFragment {
/**
* Top-level functions, type aliases and properties in the module fragment.
@@ -87,72 +71,4 @@ public class KmModuleFragment : KmModuleFragmentVisitor() {
internal val extensions: List<KmModuleFragmentExtension> =
MetadataExtensions.INSTANCES.map(MetadataExtensions::createModuleFragmentExtensions)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitPackage(): KmPackageVisitor? =
KmPackage().also { pkg = it }
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitExtensions(type: KmExtensionType): KmModuleFragmentExtensionVisitor? =
extensions.singleOfType(type)
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
override fun visitClass(): KmClassVisitor? =
KmClass().addTo(classes)
/**
* Populates the given visitor with data in this module fragment.
*
* @param visitor the visitor which will visit data in the module fragment.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public fun accept(visitor: KmModuleFragmentVisitor) {
pkg?.let { visitor.visitPackage()?.let(it::accept) }
classes.forEach { visitor.visitClass()?.let(it::accept) }
extensions.forEach { visitor.visitExtensions(it.type)?.let(it::accept) }
visitor.visitEnd()
}
}
/**
* A visitor to visit module fragments. The module fragment can have no more than one package, and any number of classes,
* and must have at least one declaration.
*
* When using this class, [visitEnd] must be called exactly once and after calls to all other visit* methods.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public abstract class KmModuleFragmentVisitor @JvmOverloads constructor(private val delegate: KmModuleFragmentVisitor? = null) {
/**
* Visits a package within the module fragment.
*/
public open fun visitPackage(): KmPackageVisitor? =
delegate?.visitPackage()
/**
* Visits a class within the module fragment.
*/
public open fun visitClass(): KmClassVisitor? =
delegate?.visitClass()
/**
* Visits the extensions of the given type on the module fragment.
*
* @param type the type of extension visitor to be returned.
*/
public open fun visitExtensions(type: KmExtensionType): KmModuleFragmentExtensionVisitor? =
delegate?.visitExtensions(type)
/**
* Visits the end of the module fragment.
*/
public open fun visitEnd() {
delegate?.visitEnd()
}
}
/**
* A visitor to visit platform-specific extensions for a module fragment.
*/
@Deprecated(VISITOR_API_MESSAGE, level = DeprecationLevel.ERROR)
public interface KmModuleFragmentExtensionVisitor : KmExtensionVisitor
@@ -2,33 +2,94 @@
* 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.
*/
@file:Suppress("DEPRECATION_ERROR") // deprecated visitors API
package kotlin.metadata.internal.extensions
import kotlin.metadata.*
import kotlin.metadata.internal.common.KmModuleFragmentExtensionVisitor
import kotlin.metadata.internal.common.KmModuleFragment
import kotlin.reflect.KClass
public interface KmExtension<V : KmExtensionVisitor> : KmExtensionVisitor {
public fun accept(visitor: V)
/**
* A type of the extension expected by the code that uses the extensions API.
*
* Each declaration that can have platform-specific extensions in the metadata has a method `getExtension`, e.g.:
* `fun KmFunction.getExtension(type: KmExtensionType): KmFunctionExtension`.
*
* These functions are used by -jvm and -klib counterparts to retrieve platform-specific metadata
* and should not be used in any other way.
*/
public class KmExtensionType(private val klass: KClass<out KmExtension>) {
override fun equals(other: Any?): Boolean =
other is KmExtensionType && klass == other.klass
override fun hashCode(): Int =
klass.hashCode()
override fun toString(): String =
klass.java.name
}
public interface KmClassExtension : KmClassExtensionVisitor, KmExtension<KmClassExtensionVisitor>
/**
* Base interface for all extensions to hold the extension type.
*/
public interface KmExtension {
public interface KmPackageExtension : KmPackageExtensionVisitor, KmExtension<KmPackageExtensionVisitor>
/**
* Type of this extension.
*/
public val type: KmExtensionType
}
public interface KmModuleFragmentExtension : KmModuleFragmentExtensionVisitor, KmExtension<KmModuleFragmentExtensionVisitor>
public interface KmClassExtension : KmExtension
public interface KmFunctionExtension : KmFunctionExtensionVisitor, KmExtension<KmFunctionExtensionVisitor>
public fun KmClass.getExtension(type: KmExtensionType): KmClassExtension = extensions.singleOfType(type)
public interface KmPropertyExtension : KmPropertyExtensionVisitor, KmExtension<KmPropertyExtensionVisitor>
public interface KmPackageExtension : KmExtension
public interface KmConstructorExtension : KmConstructorExtensionVisitor, KmExtension<KmConstructorExtensionVisitor>
public fun KmPackage.getExtension(type: KmExtensionType): KmPackageExtension = extensions.singleOfType(type)
public interface KmTypeParameterExtension : KmTypeParameterExtensionVisitor, KmExtension<KmTypeParameterExtensionVisitor>
public interface KmModuleFragmentExtension : KmExtension
public interface KmTypeExtension : KmTypeExtensionVisitor, KmExtension<KmTypeExtensionVisitor>
public fun KmModuleFragment.getExtension(type: KmExtensionType): KmModuleFragmentExtension = extensions.singleOfType(type)
public interface KmTypeAliasExtension : KmTypeAliasExtensionVisitor, KmExtension<KmTypeAliasExtensionVisitor>
public interface KmFunctionExtension : KmExtension
public interface KmValueParameterExtension : KmValueParameterExtensionVisitor, KmExtension<KmValueParameterExtensionVisitor>
public fun KmFunction.getExtension(type: KmExtensionType): KmFunctionExtension = extensions.singleOfType(type)
public interface KmPropertyExtension : KmExtension
public fun KmProperty.getExtension(type: KmExtensionType): KmPropertyExtension = extensions.singleOfType(type)
public interface KmConstructorExtension : KmExtension
public fun KmConstructor.getExtension(type: KmExtensionType): KmConstructorExtension = extensions.singleOfType(type)
public interface KmTypeParameterExtension : KmExtension
public fun KmTypeParameter.getExtension(type: KmExtensionType): KmTypeParameterExtension = extensions.singleOfType(type)
public interface KmTypeExtension : KmExtension
public fun KmType.getExtension(type: KmExtensionType): KmTypeExtension = extensions.singleOfType(type)
public interface KmTypeAliasExtension : KmExtension
public fun KmTypeAlias.getExtension(type: KmExtensionType): KmTypeAliasExtension = extensions.singleOfType(type)
public interface KmValueParameterExtension : KmExtension
public fun KmValueParameter.getExtension(type: KmExtensionType): KmValueParameterExtension = extensions.singleOfType(type)
private fun <N : KmExtension> Collection<N>.singleOfType(type: KmExtensionType): N {
var result: N? = null
for (node in this) {
if (node.type != type) continue
if (result != null) {
throw IllegalStateException("Multiple extensions handle the same extension type: $type")
}
result = node
}
if (result == null) {
throw IllegalStateException("No extensions handle the extension type: $type")
}
return result
}
@@ -1,23 +0,0 @@
/*
* 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.
*/
@file:Suppress("DEPRECATION_ERROR") // KmExtensionType will be moved to an internal package
package kotlin.metadata.internal.extensions
import kotlin.metadata.KmExtensionType
internal fun <N : KmExtension<*>> Collection<N>.singleOfType(type: KmExtensionType): N {
var result: N? = null
for (node in this) {
if (node.type != type) continue
if (result != null) {
throw IllegalStateException("Multiple extensions handle the same extension type: $type")
}
result = node
}
if (result == null) {
throw IllegalStateException("No extensions handle the extension type: $type")
}
return result
}