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
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.kotlinp
|
||||
import kotlinx.metadata.InconsistentKotlinMetadataException
|
||||
import kotlinx.metadata.jvm.KotlinClassMetadata
|
||||
import kotlinx.metadata.jvm.KotlinModuleMetadata
|
||||
import kotlinx.metadata.jvm.UnstableMetadataApi
|
||||
import java.io.File
|
||||
|
||||
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 =
|
||||
if (metadata != null) ModuleFilePrinter(settings).print(metadata)
|
||||
else buildString { appendLine("unsupported file") }
|
||||
|
||||
@OptIn(UnstableMetadataApi::class)
|
||||
internal fun readModuleFile(file: File): KotlinModuleMetadata? =
|
||||
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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.kotlinp
|
||||
|
||||
import kotlinx.metadata.jvm.UnstableMetadataApi
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import kotlin.system.exitProcess
|
||||
@@ -40,7 +41,7 @@ object Main {
|
||||
val text = try {
|
||||
when (file.extension) {
|
||||
"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")
|
||||
}
|
||||
} 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.
|
||||
*/
|
||||
|
||||
@@ -685,6 +685,7 @@ class ModuleFilePrinter(private val settings: KotlinpSettings) {
|
||||
sb.appendLine("}")
|
||||
}
|
||||
|
||||
@UnstableMetadataApi
|
||||
fun print(metadata: KotlinModuleMetadata): String {
|
||||
val kmModule = metadata.toKmModule()
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.openapi.Disposable
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import kotlinx.metadata.jvm.KotlinClassMetadata
|
||||
import kotlinx.metadata.jvm.KotlinModuleMetadata
|
||||
import kotlinx.metadata.jvm.UnstableMetadataApi
|
||||
import org.jetbrains.kotlin.checkers.setupLanguageVersionSettingsForCompilerTests
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
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))
|
||||
|
||||
@OptIn(UnstableMetadataApi::class)
|
||||
compile(file, disposable, tmpdir) { outputFile ->
|
||||
when (outputFile.extension) {
|
||||
"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
|
||||
@OptIn(UnstableMetadataApi::class)
|
||||
private fun transformModuleFileWithReadWriteVisitors(moduleFile: KotlinModuleMetadata): KotlinModuleMetadata =
|
||||
KotlinModuleMetadata.Writer().apply(moduleFile::accept).write()
|
||||
|
||||
@OptIn(UnstableMetadataApi::class)
|
||||
private fun transformModuleFileWithNodes(moduleFile: KotlinModuleMetadata): KotlinModuleMetadata =
|
||||
KotlinModuleMetadata.write(moduleFile.toKmModule())
|
||||
|
||||
Reference in New Issue
Block a user