Render different class kinds differently in bytecode listing test
This commit is contained in:
@@ -13,43 +13,43 @@ public final class A {
|
|||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnField
|
public annotation class AnnField
|
||||||
|
|
||||||
@kotlin.annotation.Target
|
@kotlin.annotation.Target
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnFieldProperty
|
public annotation class AnnFieldProperty
|
||||||
|
|
||||||
@kotlin.annotation.Target
|
@kotlin.annotation.Target
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnParameterField
|
public annotation class AnnParameterField
|
||||||
|
|
||||||
@kotlin.annotation.Target
|
@kotlin.annotation.Target
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnParameterProperty
|
public annotation class AnnParameterProperty
|
||||||
|
|
||||||
@kotlin.annotation.Target
|
@kotlin.annotation.Target
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnProperty
|
public annotation class AnnProperty
|
||||||
|
|
||||||
@kotlin.annotation.Target
|
@kotlin.annotation.Target
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnTypeField
|
public annotation class AnnTypeField
|
||||||
|
|
||||||
@kotlin.annotation.Target
|
@kotlin.annotation.Target
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class Anno
|
public annotation class Anno
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public final class DefaultTargetsKt {
|
public final class DefaultTargetsKt {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class Ann
|
public annotation class Ann
|
||||||
|
|
||||||
@kotlin.annotation.Target
|
@kotlin.annotation.Target
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnExpr
|
public annotation class AnnExpr
|
||||||
|
|
||||||
@Ann
|
@Ann
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
|
|||||||
@@ -2,19 +2,19 @@
|
|||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class ClsAnn
|
public annotation class ClsAnn
|
||||||
|
|
||||||
@kotlin.annotation.Target
|
@kotlin.annotation.Target
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class ExprAnn
|
public annotation class ExprAnn
|
||||||
|
|
||||||
@kotlin.annotation.Target
|
@kotlin.annotation.Target
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@java.lang.annotation.Target
|
@java.lang.annotation.Target
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class FunAnn
|
public annotation class FunAnn
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
final class LiteralsKt$foo$1 {
|
final class LiteralsKt$foo$1 {
|
||||||
|
|||||||
@@ -20,31 +20,31 @@ public final class A {
|
|||||||
|
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnDelegate
|
public annotation class AnnDelegate
|
||||||
|
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnField
|
public annotation class AnnField
|
||||||
|
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnGetter
|
public annotation class AnnGetter
|
||||||
|
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnParam
|
public annotation class AnnParam
|
||||||
|
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnProp
|
public annotation class AnnProp
|
||||||
|
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnProp2
|
public annotation class AnnProp2
|
||||||
|
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class AnnSetter
|
public annotation class AnnSetter
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public final class CustomDelegate {
|
public final class CustomDelegate {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public final class A {
|
|||||||
|
|
||||||
@java.lang.annotation.Retention
|
@java.lang.annotation.Retention
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class Ann
|
public annotation class Ann
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public final class OnReceiverKt {
|
public final class OnReceiverKt {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class A
|
public interface A
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class B {
|
public interface B {
|
||||||
public abstract method foo(): void
|
public abstract method foo(): void
|
||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class C {
|
public interface C {
|
||||||
public abstract method getBar(): int
|
public abstract method getBar(): int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ public final class D$DefaultImpls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class D {
|
public interface D {
|
||||||
inner class D$DefaultImpls
|
inner class D$DefaultImpls
|
||||||
public abstract method baz(): int
|
public abstract method baz(): int
|
||||||
}
|
}
|
||||||
@@ -30,6 +30,6 @@ public final class E$InsideE {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class E {
|
public interface E {
|
||||||
inner class E$InsideE
|
inner class E$InsideE
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ public final class I1$DefaultImpls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class I1 {
|
public interface I1 {
|
||||||
inner class I1$DefaultImpls
|
inner class I1$DefaultImpls
|
||||||
public abstract method contains(p0: java.lang.Object): boolean
|
public abstract method contains(p0: java.lang.Object): boolean
|
||||||
public abstract method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean
|
public abstract method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean
|
||||||
@@ -134,7 +134,7 @@ public final class I2$DefaultImpls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@kotlin.Metadata
|
@kotlin.Metadata
|
||||||
public abstract class I2 {
|
public interface I2 {
|
||||||
inner class I2$DefaultImpls
|
inner class I2$DefaultImpls
|
||||||
public abstract method contains(@org.jetbrains.annotations.NotNull p0: java.lang.String): boolean
|
public abstract method contains(@org.jetbrains.annotations.NotNull p0: java.lang.String): boolean
|
||||||
public abstract method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean
|
public abstract method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen
|
|||||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.jetbrains.org.objectweb.asm.*
|
import org.jetbrains.org.objectweb.asm.*
|
||||||
|
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
||||||
@@ -40,7 +41,7 @@ abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
|||||||
KotlinTestUtils.assertEqualsToFile(txtFile, generatedFiles)
|
KotlinTestUtils.assertEqualsToFile(txtFile, generatedFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TextCollectingVisitor : ClassVisitor(Opcodes.ASM5) {
|
private class TextCollectingVisitor : ClassVisitor(ASM5) {
|
||||||
private class Declaration(val text: String, val annotations: MutableList<String> = arrayListOf())
|
private class Declaration(val text: String, val annotations: MutableList<String> = arrayListOf())
|
||||||
|
|
||||||
private val declarationsInsideClass = arrayListOf<Declaration>()
|
private val declarationsInsideClass = arrayListOf<Declaration>()
|
||||||
@@ -58,22 +59,32 @@ abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleModifiers(access: Int, list: MutableList<String> = declarationsInsideClass.last().annotations) {
|
private fun handleModifiers(access: Int, list: MutableList<String> = declarationsInsideClass.last().annotations) {
|
||||||
if ((access and Opcodes.ACC_PUBLIC) != 0) addModifier("public", list)
|
if (access and ACC_PUBLIC != 0) addModifier("public", list)
|
||||||
if ((access and Opcodes.ACC_PROTECTED) != 0) addModifier("protected", list)
|
if (access and ACC_PROTECTED != 0) addModifier("protected", list)
|
||||||
if ((access and Opcodes.ACC_PRIVATE) != 0) addModifier("private", list)
|
if (access and ACC_PRIVATE != 0) addModifier("private", list)
|
||||||
|
|
||||||
if ((access and Opcodes.ACC_SYNTHETIC) != 0) addModifier("synthetic", list)
|
if (access and ACC_SYNTHETIC != 0) addModifier("synthetic", list)
|
||||||
if ((access and Opcodes.ACC_DEPRECATED) != 0) addModifier("deprecated", list)
|
if (access and ACC_DEPRECATED != 0) addModifier("deprecated", list)
|
||||||
if ((access and Opcodes.ACC_FINAL) != 0) addModifier("final", list)
|
if (access and ACC_FINAL != 0) addModifier("final", list)
|
||||||
if ((access and Opcodes.ACC_ABSTRACT) != 0) addModifier("abstract", list)
|
if (access and ACC_ABSTRACT != 0 && access and ACC_INTERFACE == 0) addModifier("abstract", list)
|
||||||
if ((access and Opcodes.ACC_STATIC) != 0) addModifier("static", list)
|
if (access and ACC_STATIC != 0) addModifier("static", list)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun classOrInterface(access: Int): String {
|
||||||
|
return when {
|
||||||
|
access and ACC_ANNOTATION != 0 -> "annotation class"
|
||||||
|
access and ACC_ENUM != 0 -> "enum class"
|
||||||
|
access and ACC_INTERFACE != 0 -> "interface"
|
||||||
|
else -> "class"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val text: String
|
val text: String
|
||||||
get() = StringBuilder().apply {
|
get() = StringBuilder().apply {
|
||||||
append(classAnnotations.joinToString("\n", postfix = "\n"))
|
append(classAnnotations.joinToString("\n", postfix = "\n"))
|
||||||
arrayListOf<String>().apply { handleModifiers(classAccess, this) }.forEach { append(it) }
|
arrayListOf<String>().apply { handleModifiers(classAccess, this) }.forEach { append(it) }
|
||||||
append("class ")
|
append(classOrInterface(classAccess))
|
||||||
|
append(" ")
|
||||||
append(className)
|
append(className)
|
||||||
if (declarationsInsideClass.isNotEmpty()) {
|
if (declarationsInsideClass.isNotEmpty()) {
|
||||||
append(" {\n")
|
append(" {\n")
|
||||||
@@ -98,7 +109,7 @@ abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
|||||||
|
|
||||||
handleModifiers(access, methodAnnotations)
|
handleModifiers(access, methodAnnotations)
|
||||||
|
|
||||||
return object : MethodVisitor(Opcodes.ASM5) {
|
return object : MethodVisitor(ASM5) {
|
||||||
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
|
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
|
||||||
val type = Type.getType(desc).className
|
val type = Type.getType(desc).className
|
||||||
methodAnnotations += "@$type "
|
methodAnnotations += "@$type "
|
||||||
@@ -127,7 +138,7 @@ abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
|||||||
declarationsInsideClass.add(Declaration("field $name: $type"))
|
declarationsInsideClass.add(Declaration("field $name: $type"))
|
||||||
handleModifiers(access)
|
handleModifiers(access)
|
||||||
|
|
||||||
return object : FieldVisitor(Opcodes.ASM5) {
|
return object : FieldVisitor(ASM5) {
|
||||||
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
|
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
|
||||||
addAnnotation(desc)
|
addAnnotation(desc)
|
||||||
return super.visitAnnotation(desc, visible)
|
return super.visitAnnotation(desc, visible)
|
||||||
|
|||||||
Reference in New Issue
Block a user