jvm-abi-gen: Don't strip nested classes from the Kotlin Metadata
This commit is contained in:
committed by
Alexander Udalov
parent
4a59af3b8b
commit
d94817cfb6
@@ -18,7 +18,7 @@ import org.jetbrains.org.objectweb.asm.Opcodes
|
|||||||
* Wrap the visitor for a Kotlin Metadata annotation to strip out private and local
|
* Wrap the visitor for a Kotlin Metadata annotation to strip out private and local
|
||||||
* functions, properties, and type aliases as well as local delegated properties.
|
* functions, properties, and type aliases as well as local delegated properties.
|
||||||
*/
|
*/
|
||||||
fun abiMetadataProcessor(internalName: String, publicClasses: Set<String>, annotationVisitor: AnnotationVisitor): AnnotationVisitor =
|
fun abiMetadataProcessor(annotationVisitor: AnnotationVisitor): AnnotationVisitor =
|
||||||
kotlinClassHeaderVisitor { header ->
|
kotlinClassHeaderVisitor { header ->
|
||||||
// kotlinx-metadata only supports writing Kotlin metadata of version >= 1.4, so we need to
|
// kotlinx-metadata only supports writing Kotlin metadata of version >= 1.4, so we need to
|
||||||
// update the metadata version if we encounter older metadata annotations.
|
// update the metadata version if we encounter older metadata annotations.
|
||||||
@@ -27,7 +27,7 @@ fun abiMetadataProcessor(internalName: String, publicClasses: Set<String>, annot
|
|||||||
val newHeader = when (val metadata = KotlinClassMetadata.read(header)) {
|
val newHeader = when (val metadata = KotlinClassMetadata.read(header)) {
|
||||||
is KotlinClassMetadata.Class -> {
|
is KotlinClassMetadata.Class -> {
|
||||||
val writer = KotlinClassMetadata.Class.Writer()
|
val writer = KotlinClassMetadata.Class.Writer()
|
||||||
metadata.accept(AbiKmClassVisitor(internalName, publicClasses, writer))
|
metadata.accept(AbiKmClassVisitor(writer))
|
||||||
writer.write(metadataVersion, header.extraInt).header
|
writer.write(metadataVersion, header.extraInt).header
|
||||||
}
|
}
|
||||||
is KotlinClassMetadata.FileFacade -> {
|
is KotlinClassMetadata.FileFacade -> {
|
||||||
@@ -121,7 +121,7 @@ private fun AnnotationVisitor.visitKotlinMetadata(header: KotlinClassHeader) {
|
|||||||
* Class metadata adapter which removes private functions, properties, type aliases,
|
* Class metadata adapter which removes private functions, properties, type aliases,
|
||||||
* and local delegated properties.
|
* and local delegated properties.
|
||||||
*/
|
*/
|
||||||
private class AbiKmClassVisitor(private val internalName: String, private val publicClasses: Set<String>, delegate: KmClassVisitor) : KmClassVisitor(delegate) {
|
private class AbiKmClassVisitor(delegate: KmClassVisitor) : KmClassVisitor(delegate) {
|
||||||
override fun visitConstructor(flags: Flags): KmConstructorVisitor? {
|
override fun visitConstructor(flags: Flags): KmConstructorVisitor? {
|
||||||
if (!isPrivateDeclaration(flags))
|
if (!isPrivateDeclaration(flags))
|
||||||
return super.visitConstructor(flags)
|
return super.visitConstructor(flags)
|
||||||
@@ -140,16 +140,6 @@ private class AbiKmClassVisitor(private val internalName: String, private val pu
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitNestedClass(name: String) {
|
|
||||||
if ("$internalName\$$name" in publicClasses)
|
|
||||||
super.visitNestedClass(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitCompanionObject(name: String) {
|
|
||||||
if ("$internalName\$$name" in publicClasses)
|
|
||||||
super.visitCompanionObject(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor? {
|
override fun visitTypeAlias(flags: Flags, name: String): KmTypeAliasVisitor? {
|
||||||
if (!isPrivateDeclaration(flags))
|
if (!isPrivateDeclaration(flags))
|
||||||
return super.visitTypeAlias(flags, name)
|
return super.visitTypeAlias(flags, name)
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ class JvmAbiOutputExtension(
|
|||||||
val delegate = super.visitAnnotation(descriptor, visible)
|
val delegate = super.visitAnnotation(descriptor, visible)
|
||||||
if (descriptor != JvmAnnotationNames.METADATA_DESC)
|
if (descriptor != JvmAnnotationNames.METADATA_DESC)
|
||||||
return delegate
|
return delegate
|
||||||
return abiMetadataProcessor(internalName, abiClassInfos.keys, delegate)
|
return abiMetadataProcessor(delegate)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitEnd() {
|
override fun visitEnd() {
|
||||||
|
|||||||
Reference in New Issue
Block a user