Provide @UnstableMetadataApi and mark kotlin_module related API with it,
as it is not finished yet.
This commit is contained in:
committed by
Space Team
parent
165e779e3e
commit
1828e293ea
@@ -1391,3 +1391,6 @@ public final class kotlinx/metadata/jvm/KotlinModuleMetadata$Writer : kotlinx/me
|
|||||||
public static synthetic fun write$default (Lkotlinx/metadata/jvm/KotlinModuleMetadata$Writer;[IILjava/lang/Object;)Lkotlinx/metadata/jvm/KotlinModuleMetadata;
|
public static synthetic fun write$default (Lkotlinx/metadata/jvm/KotlinModuleMetadata$Writer;[IILjava/lang/Object;)Lkotlinx/metadata/jvm/KotlinModuleMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract interface annotation class kotlinx/metadata/jvm/UnstableMetadataApi : java/lang/annotation/Annotation {
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.metadata.jvm.deserialization.serializeToByteArray
|
|||||||
*
|
*
|
||||||
* @property bytes the byte array representing the contents of a `.kotlin_module` file
|
* @property bytes the byte array representing the contents of a `.kotlin_module` file
|
||||||
*/
|
*/
|
||||||
|
@UnstableMetadataApi
|
||||||
class KotlinModuleMetadata(@Suppress("MemberVisibilityCanBePrivate") val bytes: ByteArray) {
|
class KotlinModuleMetadata(@Suppress("MemberVisibilityCanBePrivate") val bytes: ByteArray) {
|
||||||
@get:IgnoreInApiDump
|
@get:IgnoreInApiDump
|
||||||
internal val data: ModuleMapping = ModuleMapping.loadModuleMapping(
|
internal val data: ModuleMapping = ModuleMapping.loadModuleMapping(
|
||||||
@@ -126,6 +127,7 @@ class KotlinModuleMetadata(@Suppress("MemberVisibilityCanBePrivate") val bytes:
|
|||||||
* which means that it's either not the content of a .kotlin_module file, or it has been corrupted.
|
* which means that it's either not the content of a .kotlin_module file, or it has been corrupted.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@UnstableMetadataApi
|
||||||
fun read(bytes: ByteArray): KotlinModuleMetadata? {
|
fun read(bytes: ByteArray): KotlinModuleMetadata? {
|
||||||
try {
|
try {
|
||||||
val result = KotlinModuleMetadata(bytes)
|
val result = KotlinModuleMetadata(bytes)
|
||||||
@@ -149,6 +151,7 @@ class KotlinModuleMetadata(@Suppress("MemberVisibilityCanBePrivate") val bytes:
|
|||||||
* @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]),
|
* @param metadataVersion metadata version to be written to the metadata (see [Metadata.metadataVersion]),
|
||||||
* [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default
|
* [KotlinClassMetadata.COMPATIBLE_METADATA_VERSION] by default
|
||||||
*/
|
*/
|
||||||
|
@UnstableMetadataApi
|
||||||
fun write(kmModule: KmModule, metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION): KotlinModuleMetadata =
|
fun write(kmModule: KmModule, metadataVersion: IntArray = COMPATIBLE_METADATA_VERSION): KotlinModuleMetadata =
|
||||||
Writer().also { kmModule.accept(it) }.write(metadataVersion)
|
Writer().also { kmModule.accept(it) }.write(metadataVersion)
|
||||||
}
|
}
|
||||||
@@ -160,6 +163,7 @@ class KotlinModuleMetadata(@Suppress("MemberVisibilityCanBePrivate") val bytes:
|
|||||||
* When using this class, [visitEnd] must be called exactly once and after calls to all other visit* methods.
|
* When using this class, [visitEnd] must be called exactly once and after calls to all other visit* methods.
|
||||||
*/
|
*/
|
||||||
@Deprecated(VISITOR_API_MESSAGE)
|
@Deprecated(VISITOR_API_MESSAGE)
|
||||||
|
@UnstableMetadataApi
|
||||||
abstract class KmModuleVisitor(private val delegate: KmModuleVisitor? = null) {
|
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.
|
* Visits the table of all single- and multi-file facades declared in some package of this module.
|
||||||
@@ -208,6 +212,7 @@ abstract class KmModuleVisitor(private val delegate: KmModuleVisitor? = null) {
|
|||||||
/**
|
/**
|
||||||
* Represents a Kotlin JVM module file.
|
* Represents a Kotlin JVM module file.
|
||||||
*/
|
*/
|
||||||
|
@UnstableMetadataApi
|
||||||
class KmModule : KmModuleVisitor() {
|
class KmModule : KmModuleVisitor() {
|
||||||
/**
|
/**
|
||||||
* Table of all single- and multi-file facades declared in some package of this module, where keys are '.'-separated package names.
|
* Table of all single- and multi-file facades declared in some package of this module, where keys are '.'-separated package names.
|
||||||
@@ -267,6 +272,7 @@ class KmModule : KmModuleVisitor() {
|
|||||||
* @property multiFileClassParts the map of multi-file classes where keys are names of multi-file class parts,
|
* @property 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
|
* and values are names of the corresponding multi-file facades
|
||||||
*/
|
*/
|
||||||
|
@UnstableMetadataApi
|
||||||
class KmPackageParts(
|
class KmPackageParts(
|
||||||
val fileFacades: MutableList<String>,
|
val fileFacades: MutableList<String>,
|
||||||
val multiFileClassParts: MutableMap<String, String>
|
val multiFileClassParts: MutableMap<String, String>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* 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 kotlinx.metadata.jvm
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Annotation marks an API that is still in development and not feature-complete or finalized.
|
||||||
|
* Such an API does not provide compatibility guarantees.
|
||||||
|
* It can be changed in future releases without migration aids or removed without replacement.
|
||||||
|
*/
|
||||||
|
@RequiresOptIn(
|
||||||
|
"This part of API is not yet finished, does not provide compatibility guarantees and can be changed in the future without notice",
|
||||||
|
level = RequiresOptIn.Level.WARNING
|
||||||
|
)
|
||||||
|
annotation class UnstableMetadataApi
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -191,6 +191,7 @@ class MetadataSmokeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@OptIn(UnstableMetadataApi::class)
|
||||||
fun metadataVersionEarlierThan1_4() {
|
fun metadataVersionEarlierThan1_4() {
|
||||||
val dummy = (KotlinClassMetadata.read(MetadataSmokeTest::class.java.readMetadata()) as KotlinClassMetadata.Class).toKmClass()
|
val dummy = (KotlinClassMetadata.read(MetadataSmokeTest::class.java.readMetadata()) as KotlinClassMetadata.Class).toKmClass()
|
||||||
val mv = intArrayOf(1, 3)
|
val mv = intArrayOf(1, 3)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.kotlinp
|
|||||||
import kotlinx.metadata.InconsistentKotlinMetadataException
|
import kotlinx.metadata.InconsistentKotlinMetadataException
|
||||||
import kotlinx.metadata.jvm.KotlinClassMetadata
|
import kotlinx.metadata.jvm.KotlinClassMetadata
|
||||||
import kotlinx.metadata.jvm.KotlinModuleMetadata
|
import kotlinx.metadata.jvm.KotlinModuleMetadata
|
||||||
|
import kotlinx.metadata.jvm.UnstableMetadataApi
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class Kotlinp(private val settings: KotlinpSettings) {
|
class Kotlinp(private val settings: KotlinpSettings) {
|
||||||
@@ -34,10 +35,12 @@ class Kotlinp(private val settings: KotlinpSettings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(UnstableMetadataApi::class)
|
||||||
internal fun renderModuleFile(metadata: KotlinModuleMetadata?): String =
|
internal fun renderModuleFile(metadata: KotlinModuleMetadata?): String =
|
||||||
if (metadata != null) ModuleFilePrinter(settings).print(metadata)
|
if (metadata != null) ModuleFilePrinter(settings).print(metadata)
|
||||||
else buildString { appendLine("unsupported file") }
|
else buildString { appendLine("unsupported file") }
|
||||||
|
|
||||||
|
@OptIn(UnstableMetadataApi::class)
|
||||||
internal fun readModuleFile(file: File): KotlinModuleMetadata? =
|
internal fun readModuleFile(file: File): KotlinModuleMetadata? =
|
||||||
KotlinModuleMetadata.read(file.readBytes())
|
KotlinModuleMetadata.read(file.readBytes())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.kotlinp
|
package org.jetbrains.kotlin.kotlinp
|
||||||
|
|
||||||
|
import kotlinx.metadata.jvm.UnstableMetadataApi
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
@@ -40,7 +41,7 @@ object Main {
|
|||||||
val text = try {
|
val text = try {
|
||||||
when (file.extension) {
|
when (file.extension) {
|
||||||
"class" -> kotlinp.renderClassFile(kotlinp.readClassFile(file))
|
"class" -> kotlinp.renderClassFile(kotlinp.readClassFile(file))
|
||||||
"kotlin_module" -> kotlinp.renderModuleFile(kotlinp.readModuleFile(file))
|
"kotlin_module" -> @OptIn(UnstableMetadataApi::class) kotlinp.renderModuleFile(kotlinp.readModuleFile(file))
|
||||||
else -> throw KotlinpException("only .class and .kotlin_module files are supported")
|
else -> throw KotlinpException("only .class and .kotlin_module files are supported")
|
||||||
}
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2000-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -685,6 +685,7 @@ class ModuleFilePrinter(private val settings: KotlinpSettings) {
|
|||||||
sb.appendLine("}")
|
sb.appendLine("}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UnstableMetadataApi
|
||||||
fun print(metadata: KotlinModuleMetadata): String {
|
fun print(metadata: KotlinModuleMetadata): String {
|
||||||
val kmModule = metadata.toKmModule()
|
val kmModule = metadata.toKmModule()
|
||||||
kmModule.packageParts.forEach { (fqName, kmPackageParts) ->
|
kmModule.packageParts.forEach { (fqName, kmPackageParts) ->
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ import com.intellij.openapi.Disposable
|
|||||||
import junit.framework.TestCase.assertEquals
|
import junit.framework.TestCase.assertEquals
|
||||||
import kotlinx.metadata.jvm.KotlinClassMetadata
|
import kotlinx.metadata.jvm.KotlinClassMetadata
|
||||||
import kotlinx.metadata.jvm.KotlinModuleMetadata
|
import kotlinx.metadata.jvm.KotlinModuleMetadata
|
||||||
|
import kotlinx.metadata.jvm.UnstableMetadataApi
|
||||||
import org.jetbrains.kotlin.checkers.setupLanguageVersionSettingsForCompilerTests
|
import org.jetbrains.kotlin.checkers.setupLanguageVersionSettingsForCompilerTests
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
@@ -32,6 +33,7 @@ fun compileAndPrintAllFiles(file: File, disposable: Disposable, tmpdir: File, co
|
|||||||
|
|
||||||
val kotlinp = Kotlinp(KotlinpSettings(isVerbose = true))
|
val kotlinp = Kotlinp(KotlinpSettings(isVerbose = true))
|
||||||
|
|
||||||
|
@OptIn(UnstableMetadataApi::class)
|
||||||
compile(file, disposable, tmpdir) { outputFile ->
|
compile(file, disposable, tmpdir) { outputFile ->
|
||||||
when (outputFile.extension) {
|
when (outputFile.extension) {
|
||||||
"kotlin_module" -> {
|
"kotlin_module" -> {
|
||||||
@@ -130,8 +132,10 @@ private fun transformClassFileWithNodes(classFile: KotlinClassMetadata): KotlinC
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION") // We're testing that reading/writing with KmNodes is identical to direct
|
@Suppress("DEPRECATION") // We're testing that reading/writing with KmNodes is identical to direct
|
||||||
|
@OptIn(UnstableMetadataApi::class)
|
||||||
private fun transformModuleFileWithReadWriteVisitors(moduleFile: KotlinModuleMetadata): KotlinModuleMetadata =
|
private fun transformModuleFileWithReadWriteVisitors(moduleFile: KotlinModuleMetadata): KotlinModuleMetadata =
|
||||||
KotlinModuleMetadata.Writer().apply(moduleFile::accept).write()
|
KotlinModuleMetadata.Writer().apply(moduleFile::accept).write()
|
||||||
|
|
||||||
|
@OptIn(UnstableMetadataApi::class)
|
||||||
private fun transformModuleFileWithNodes(moduleFile: KotlinModuleMetadata): KotlinModuleMetadata =
|
private fun transformModuleFileWithNodes(moduleFile: KotlinModuleMetadata): KotlinModuleMetadata =
|
||||||
KotlinModuleMetadata.write(moduleFile.toKmModule())
|
KotlinModuleMetadata.write(moduleFile.toKmModule())
|
||||||
|
|||||||
Reference in New Issue
Block a user