Copy annotation and attributes on class transformation during inline

This commit is contained in:
Mikhael Bogdanov
2017-08-04 15:32:58 +02:00
parent 11ba805181
commit 15f401a473
9 changed files with 110 additions and 6 deletions
@@ -24,7 +24,9 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
open class MethodBodyVisitor(mv: MethodVisitor, private val visitAnnotationsAndAttributes: Boolean = false) : InstructionAdapter(API, mv) {
override fun visitParameter(name: String, access: Int) {}
override fun visitParameter(name: String, access: Int) {
if (visitAnnotationsAndAttributes) super.visitParameter(name, access)
}
override fun visitAnnotationDefault(): AnnotationVisitor? =
if (visitAnnotationsAndAttributes) super.visitAnnotationDefault() else null
@@ -42,7 +44,9 @@ open class MethodBodyVisitor(mv: MethodVisitor, private val visitAnnotationsAndA
if (visitAnnotationsAndAttributes) super.visitAttribute(attr)
}
override fun visitCode() {}
override fun visitCode() {
if (visitAnnotationsAndAttributes) super.visitCode()
}
override fun visitMaxs(maxStack: Int, maxLocals: Int) {}
@@ -90,7 +90,11 @@ class MethodInliner(
API, transformedNode.access, transformedNode.name, transformedNode.desc,
transformedNode.signature, transformedNode.exceptions?.toTypedArray()
)
val visitor = RemapVisitor(resultNode, remapper, nodeRemapper)
val visitor = RemapVisitor(
resultNode, remapper, nodeRemapper,
/*copy annotation and attributes*/
nodeRemapper is RegeneratedLambdaFieldRemapper
)
try {
transformedNode.accept(visitor)
}
@@ -109,7 +113,7 @@ class MethodInliner(
processReturns(resultNode, labelOwner, remapReturn, end)
//flush transformed node to output
resultNode.accept(MethodBodyVisitor(adapter))
resultNode.accept(MethodBodyVisitor(adapter, true))
sourceMapper.endMapping()
return result
@@ -34,9 +34,10 @@ public class RemapVisitor extends MethodBodyVisitor {
public RemapVisitor(
@NotNull MethodVisitor mv,
@NotNull LocalVarRemapper remapper,
@NotNull FieldRemapper nodeRemapper
@NotNull FieldRemapper nodeRemapper,
boolean copyAnnotationsAndAttributes
) {
super(mv);
super(mv, copyAnnotationsAndAttributes);
this.instructionAdapter = new InstructionAdapter(mv);
this.remapper = remapper;
this.nodeRemapper = nodeRemapper;
@@ -0,0 +1,23 @@
// FILE: 1.kt
//WITH_RUNTIME
package test
annotation class MethodAnnotation
inline fun reproduceIssue(crossinline s: () -> String): String {
val obj = object {
@MethodAnnotation fun annotatedMethod(): String {
return s()
}
}
val annotatedMethod = obj::class.java.declaredMethods.first { it.name == "annotatedMethod" }
if (annotatedMethod.annotations.isEmpty()) return "fail: can't find annotated method"
return obj.annotatedMethod()
}
// FILE: 2.kt
import test.*
fun box(): String {
return reproduceIssue { "OK" }
}
@@ -0,0 +1,24 @@
// FILE: 1.kt
//WITH_RUNTIME
package test
annotation class FieldAnnotation
inline fun reproduceIssue(crossinline s: () -> String): String {
val obj = object {
@field:FieldAnnotation val annotatedField = "O"
fun method(): String {
return annotatedField + s()
}
}
val annotatedMethod = obj::class.java.declaredFields.first { it.name == "annotatedField" }
if (annotatedMethod.annotations.isEmpty()) return "fail: can't find annotated field"
return obj.method()
}
// FILE: 2.kt
import test.*
fun box(): String {
return reproduceIssue { "K" }
}
@@ -212,6 +212,18 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
doTest(fileName);
}
@TestMetadata("kt19434.kt")
public void testKt19434() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt19434.kt");
doTest(fileName);
}
@TestMetadata("kt19434_2.kt")
public void testKt19434_2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt19434_2.kt");
doTest(fileName);
}
@TestMetadata("kt6552.kt")
public void testKt6552() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
@@ -212,6 +212,18 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
doTest(fileName);
}
@TestMetadata("kt19434.kt")
public void testKt19434() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt19434.kt");
doTest(fileName);
}
@TestMetadata("kt19434_2.kt")
public void testKt19434_2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt19434_2.kt");
doTest(fileName);
}
@TestMetadata("kt6552.kt")
public void testKt6552() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
@@ -212,6 +212,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
doTest(fileName);
}
@TestMetadata("kt19434.kt")
public void testKt19434() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt19434.kt");
doTest(fileName);
}
@TestMetadata("kt19434_2.kt")
public void testKt19434_2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt19434_2.kt");
doTest(fileName);
}
@TestMetadata("kt6552.kt")
public void testKt6552() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
@@ -212,6 +212,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
doTest(fileName);
}
@TestMetadata("kt19434.kt")
public void testKt19434() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt19434.kt");
doTest(fileName);
}
@TestMetadata("kt19434_2.kt")
public void testKt19434_2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt19434_2.kt");
doTest(fileName);
}
@TestMetadata("kt6552.kt")
public void testKt6552() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");