Rewrite light analysis mode test class filter
Instead of filtering local/synthetic classes based on ClassDescriptor instances, do it by interpreting kotlin.Metadata. This is needed to enable these tests for JVM IR, where descriptors are not available in this way.
This commit is contained in:
+8
-5
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.test.KtAssert
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.tree.ClassNode
|
||||
|
||||
class BytecodeListingTextCollectingVisitor(
|
||||
val filter: Filter,
|
||||
@@ -26,10 +27,12 @@ class BytecodeListingTextCollectingVisitor(
|
||||
.sortedBy { it.relativePath }
|
||||
.mapNotNull {
|
||||
val cr = ClassReader(it.asByteArray())
|
||||
val node = ClassNode(Opcodes.API_VERSION)
|
||||
cr.accept(node, ClassReader.SKIP_CODE)
|
||||
val visitor = BytecodeListingTextCollectingVisitor(filter, withSignatures, withAnnotations = withAnnotations)
|
||||
cr.accept(visitor, ClassReader.SKIP_CODE)
|
||||
node.accept(visitor)
|
||||
|
||||
if (!filter.shouldWriteClass(cr.access, cr.className)) null else visitor.text
|
||||
if (!filter.shouldWriteClass(node)) null else visitor.text
|
||||
}.joinToString("\n\n", postfix = "\n")
|
||||
|
||||
private val CLASS_OR_FIELD_OR_METHOD = setOf(ModifierTarget.CLASS, ModifierTarget.FIELD, ModifierTarget.METHOD)
|
||||
@@ -61,20 +64,20 @@ class BytecodeListingTextCollectingVisitor(
|
||||
}
|
||||
|
||||
interface Filter {
|
||||
fun shouldWriteClass(access: Int, name: String): Boolean
|
||||
fun shouldWriteClass(node: ClassNode): Boolean
|
||||
fun shouldWriteMethod(access: Int, name: String, desc: String): Boolean
|
||||
fun shouldWriteField(access: Int, name: String, desc: String): Boolean
|
||||
fun shouldWriteInnerClass(name: String, outerName: String?, innerName: String?): Boolean
|
||||
|
||||
object EMPTY : Filter {
|
||||
override fun shouldWriteClass(access: Int, name: String) = true
|
||||
override fun shouldWriteClass(node: ClassNode) = true
|
||||
override fun shouldWriteMethod(access: Int, name: String, desc: String) = true
|
||||
override fun shouldWriteField(access: Int, name: String, desc: String) = true
|
||||
override fun shouldWriteInnerClass(name: String, outerName: String?, innerName: String?) = true
|
||||
}
|
||||
|
||||
object ForCodegenTests : Filter {
|
||||
override fun shouldWriteClass(access: Int, name: String): Boolean = !name.startsWith("helpers/")
|
||||
override fun shouldWriteClass(node: ClassNode): Boolean = !node.name.startsWith("helpers/")
|
||||
override fun shouldWriteMethod(access: Int, name: String, desc: String): Boolean = true
|
||||
override fun shouldWriteField(access: Int, name: String, desc: String): Boolean = true
|
||||
override fun shouldWriteInnerClass(name: String, outerName: String?, innerName: String?): Boolean = true
|
||||
|
||||
Reference in New Issue
Block a user