Use last asm api for visitor construction

This commit is contained in:
Mikhael Bogdanov
2018-12-19 10:23:15 +01:00
parent c2837cf7d9
commit c19c979b7d
44 changed files with 93 additions and 93 deletions
@@ -67,11 +67,11 @@ class WrongBytecodeVersionTest : KtUsefulTestCase() {
companion object {
fun transformMetadataInClassFile(bytes: ByteArray, transform: (fieldName: String, value: Any?) -> Any?): ByteArray {
val writer = ClassWriter(0)
ClassReader(bytes).accept(object : ClassVisitor(Opcodes.ASM5, writer) {
ClassReader(bytes).accept(object : ClassVisitor(Opcodes.API_VERSION, writer) {
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor {
val superVisitor = super.visitAnnotation(desc, visible)
if (desc == JvmAnnotationNames.METADATA_DESC) {
return object : AnnotationVisitor(Opcodes.ASM5, superVisitor) {
return object : AnnotationVisitor(Opcodes.API_VERSION, superVisitor) {
override fun visit(name: String, value: Any) {
super.visit(name, transform(name, value) ?: value)
}
@@ -79,7 +79,7 @@ class WrongBytecodeVersionTest : KtUsefulTestCase() {
override fun visitArray(name: String): AnnotationVisitor {
val entries = arrayListOf<String>()
val arrayVisitor = { super.visitArray(name) }
return object : AnnotationVisitor(Opcodes.ASM5) {
return object : AnnotationVisitor(Opcodes.API_VERSION) {
override fun visit(name: String?, value: Any) {
entries.add(value as String)
}
@@ -230,12 +230,12 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
}
ClassReader reader = new ClassReader(file.asByteArray());
reader.accept(new ClassVisitor(Opcodes.ASM5) {
reader.accept(new ClassVisitor(Opcodes.API_VERSION) {
@Override
public MethodVisitor visitMethod(
int access, @NotNull String callerName, @NotNull String callerDesc, String signature, String[] exceptions
) {
return new MethodVisitor(Opcodes.ASM5) {
return new MethodVisitor(Opcodes.API_VERSION) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
assertFalse(
@@ -139,7 +139,7 @@ public class InnerClassInfoGenTest extends CodegenTestCase {
ClassReader reader = new ClassReader(bytes);
List<InnerClassAttribute> result = new ArrayList<>();
reader.accept(new ClassVisitor(ASM5) {
reader.accept(new ClassVisitor(API_VERSION) {
@Override
public void visitInnerClass(@NotNull String name, String outerName, String innerName, int access) {
result.add(new InnerClassAttribute(name, outerName, innerName, access));
@@ -168,7 +168,7 @@ class MethodOrderTest: CodegenTestCase() {
val methodNames = ArrayList<String>()
classReader.accept(object : ClassVisitor(Opcodes.ASM4) {
classReader.accept(object : ClassVisitor(Opcodes.API_VERSION) {
override fun visitMethod(access: Int, name: String, desc: String, signature: String?, exceptions: Array<out String>?): MethodVisitor? {
methodNames.add(name + desc)
return null
@@ -219,7 +219,7 @@ public class OuterClassGenTest extends CodegenTestCase {
@Nullable
private static OuterClassInfo readOuterClassInfo(@NotNull ClassReader reader) {
Ref<OuterClassInfo> info = Ref.create();
reader.accept(new ClassVisitor(Opcodes.ASM5) {
reader.accept(new ClassVisitor(Opcodes.API_VERSION) {
@Override
public void visitOuterClass(@NotNull String owner, @Nullable String name, @Nullable String desc) {
info.set(new OuterClassInfo(owner, name, desc));
@@ -44,7 +44,7 @@ public class SourceInfoGenTest extends CodegenTestCase {
ClassReader classReader = new ClassReader(file.asByteArray());
String[] producer = new String[1];
classReader.accept(new ClassVisitor(Opcodes.ASM5) {
classReader.accept(new ClassVisitor(Opcodes.API_VERSION) {
@Override
public void visitSource(String source, String debug) {
@@ -358,8 +358,8 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
compileKotlin("sourceInline.kt", tmpdir)
val inlineFunClass = File(tmpdir.absolutePath, "test/A.class")
val cw = ClassWriter(Opcodes.ASM5)
ClassReader(inlineFunClass.readBytes()).accept(object : ClassVisitor(Opcodes.ASM5, cw) {
val cw = ClassWriter(Opcodes.API_VERSION)
ClassReader(inlineFunClass.readBytes()).accept(object : ClassVisitor(Opcodes.API_VERSION, cw) {
override fun visitSource(source: String?, debug: String?) {
//skip debug info
}
@@ -374,7 +374,7 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
var debugInfo: String? = null
val resultFile = File(tmpdir.absolutePath, "test/B.class")
ClassReader(resultFile.readBytes()).accept(object : ClassVisitor(Opcodes.ASM5) {
ClassReader(resultFile.readBytes()).accept(object : ClassVisitor(Opcodes.API_VERSION) {
override fun visitSource(source: String?, debug: String?) {
debugInfo = debug
}
@@ -574,7 +574,7 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
private fun stripSuspensionMarksToImitateLegacyCompiler(bytes: ByteArray): Pair<ByteArray, Int> {
val writer = ClassWriter(0)
var removedCounter = 0
ClassReader(bytes).accept(object : ClassVisitor(Opcodes.ASM5, writer) {
ClassReader(bytes).accept(object : ClassVisitor(Opcodes.API_VERSION, writer) {
override fun visitMethod(
access: Int,
name: String?,
@@ -583,7 +583,7 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
exceptions: Array<out String>?
): MethodVisitor {
val superMV = super.visitMethod(access, name, desc, signature, exceptions)
return object : MethodNode(Opcodes.ASM5, access, name, desc, signature, exceptions) {
return object : MethodNode(Opcodes.API_VERSION, access, name, desc, signature, exceptions) {
override fun visitEnd() {
val removeList = instructions.asSequence()
.flatMap { suspendMarkerInsns(it).asSequence() }.toList()
@@ -644,11 +644,11 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
// If there's no "xi" field in the Metadata annotation, it's value is assumed to be 0, i.e. _not_ pre-release
var isPreRelease = false
ClassReader(file.readBytes()).accept(object : ClassVisitor(Opcodes.ASM6) {
ClassReader(file.readBytes()).accept(object : ClassVisitor(Opcodes.API_VERSION) {
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
if (desc != JvmAnnotationNames.METADATA_DESC) return null
return object : AnnotationVisitor(Opcodes.ASM6) {
return object : AnnotationVisitor(Opcodes.API_VERSION) {
override fun visit(name: String, value: Any) {
if (name != JvmAnnotationNames.METADATA_EXTRA_INT_FIELD_NAME) return