Promote DeprecationLevel on Visitors API to ERROR

Rewrite Readers.kt and Writers.kt to avoid using
Visitors API

Align KotlinCommonMetadata/KotlinModuleMetadata API with
KotlinClassMetadata one (it is necessary for restructured reading/writing)

#KT-59442 In Progress
This commit is contained in:
Leonid Startsev
2023-07-18 19:58:31 +02:00
committed by Space Team
parent 4e3dbcada3
commit b8e4b44b04
24 changed files with 827 additions and 1126 deletions
@@ -2,7 +2,7 @@
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("DEPRECATION")
@file:Suppress("DEPRECATION_ERROR")
package kotlinx.metadata.klib
@@ -90,7 +90,7 @@ class KlibModuleMetadata(
library.packageMetadataParts(packageFqName).map { part ->
val packageFragment = parsePackageFragment(library.packageMetadata(packageFqName, part))
val nameResolver = NameResolverImpl(packageFragment.strings, packageFragment.qualifiedNames)
KmModuleFragment().apply { packageFragment.accept(this, nameResolver, listOf(fileIndex)) }
packageFragment.toKmModuleFragment(nameResolver, listOf(fileIndex))
}.let(readStrategy::processModuleParts)
}
return KlibModuleMetadata(moduleHeader.moduleName, moduleFragments, moduleHeader.annotation)
@@ -119,9 +119,9 @@ class KlibModuleMetadata(
annotations
)
val groupedProtos = groupedFragments.mapValues { (_, fragments) ->
fragments.map {
fragments.map { mf ->
val c = WriteContext(ApproximatingStringTable(), listOf(reverseIndex))
KlibModuleFragmentWriter(c.strings as ApproximatingStringTable, c.contextExtensions).also(it::accept).write()
KlibModuleFragmentWriter(c.strings as ApproximatingStringTable, c.contextExtensions).also { it.writeModuleFragment(mf) }.write()
}
}
// This context and string table is only required for module-level annotations.
@@ -2,7 +2,7 @@
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("DEPRECATION")
@file:Suppress("DEPRECATION_ERROR")
package kotlinx.metadata.klib.impl
@@ -151,9 +151,9 @@ internal class KlibMetadataExtensions : MetadataExtensions {
}
}
override fun writeClassExtensions(type: KmExtensionType, proto: ProtoBuf.Class.Builder, c: WriteContext): KmClassExtensionVisitor? {
if (type != KlibClassExtensionVisitor.TYPE) return null
return object : KlibClassExtensionVisitor() {
override fun writeClassExtensions(extension: KmClassExtension, proto: ProtoBuf.Class.Builder, c: WriteContext): Boolean {
if (extension.type != KlibClassExtensionVisitor.TYPE) return false
extension.accept(object : KlibClassExtensionVisitor() {
override fun visitAnnotation(annotation: KmAnnotation) {
proto.addExtension(
KlibMetadataProtoBuf.classAnnotation,
@@ -191,21 +191,23 @@ internal class KlibMetadataExtensions : MetadataExtensions {
proto.setEnumEntry(entryIndex, entryProto.build())
}
}
}
})
return true
}
override fun writePackageExtensions(
type: KmExtensionType,
extension: KmPackageExtension,
proto: ProtoBuf.Package.Builder,
c: WriteContext
): KmPackageExtensionVisitor? {
if (type != KlibPackageExtensionVisitor.TYPE) return null
return object : KlibPackageExtensionVisitor() {
): Boolean {
if (extension.type != KlibPackageExtensionVisitor.TYPE) return false
extension.accept(object : KlibPackageExtensionVisitor() {
override fun visitFqName(name: String) {
val nameIdx = (c.strings as StringTableImpl).getPackageFqNameIndex(FqName(name))
proto.setExtension(KlibMetadataProtoBuf.packageFqName, nameIdx)
}
}
})
return true
}
override fun writeModuleFragmentExtensions(
@@ -2,11 +2,11 @@
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("DEPRECATION")
package kotlinx.metadata.klib.impl
import kotlinx.metadata.internal.*
import kotlinx.metadata.internal.common.KmModuleFragment
import kotlinx.metadata.klib.KlibSourceFile
import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf
import org.jetbrains.kotlin.metadata.ProtoBuf
@@ -34,7 +34,8 @@ class KlibModuleFragmentWriter(
fun write(): ProtoBuf.PackageFragment =
t.build()
override fun visitEnd() {
override fun writeModuleFragment(kmPackageFragment: KmModuleFragment) {
super.writeModuleFragment(kmPackageFragment)
// TODO: This should be moved to ModuleFragmentWriter.
val (strings, qualifiedNames) = (c.strings as ApproximatingStringTable).buildProto()
@@ -49,4 +50,4 @@ class KlibModuleFragmentWriter(
val isEmpty = t.class_Count == 0 && isPackageEmpty
t.setExtension(KlibMetadataProtoBuf.isEmpty, isEmpty)
}
}
}
@@ -2,7 +2,7 @@
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("DEPRECATION")
@file:Suppress("DEPRECATION_ERROR")
package kotlinx.metadata.klib