Copy annotation and attributes on class transformation during inline
This commit is contained in:
@@ -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) {
|
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? =
|
override fun visitAnnotationDefault(): AnnotationVisitor? =
|
||||||
if (visitAnnotationsAndAttributes) super.visitAnnotationDefault() else null
|
if (visitAnnotationsAndAttributes) super.visitAnnotationDefault() else null
|
||||||
@@ -42,7 +44,9 @@ open class MethodBodyVisitor(mv: MethodVisitor, private val visitAnnotationsAndA
|
|||||||
if (visitAnnotationsAndAttributes) super.visitAttribute(attr)
|
if (visitAnnotationsAndAttributes) super.visitAttribute(attr)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitCode() {}
|
override fun visitCode() {
|
||||||
|
if (visitAnnotationsAndAttributes) super.visitCode()
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitMaxs(maxStack: Int, maxLocals: Int) {}
|
override fun visitMaxs(maxStack: Int, maxLocals: Int) {}
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,11 @@ class MethodInliner(
|
|||||||
API, transformedNode.access, transformedNode.name, transformedNode.desc,
|
API, transformedNode.access, transformedNode.name, transformedNode.desc,
|
||||||
transformedNode.signature, transformedNode.exceptions?.toTypedArray()
|
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 {
|
try {
|
||||||
transformedNode.accept(visitor)
|
transformedNode.accept(visitor)
|
||||||
}
|
}
|
||||||
@@ -109,7 +113,7 @@ class MethodInliner(
|
|||||||
|
|
||||||
processReturns(resultNode, labelOwner, remapReturn, end)
|
processReturns(resultNode, labelOwner, remapReturn, end)
|
||||||
//flush transformed node to output
|
//flush transformed node to output
|
||||||
resultNode.accept(MethodBodyVisitor(adapter))
|
resultNode.accept(MethodBodyVisitor(adapter, true))
|
||||||
|
|
||||||
sourceMapper.endMapping()
|
sourceMapper.endMapping()
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -34,9 +34,10 @@ public class RemapVisitor extends MethodBodyVisitor {
|
|||||||
public RemapVisitor(
|
public RemapVisitor(
|
||||||
@NotNull MethodVisitor mv,
|
@NotNull MethodVisitor mv,
|
||||||
@NotNull LocalVarRemapper remapper,
|
@NotNull LocalVarRemapper remapper,
|
||||||
@NotNull FieldRemapper nodeRemapper
|
@NotNull FieldRemapper nodeRemapper,
|
||||||
|
boolean copyAnnotationsAndAttributes
|
||||||
) {
|
) {
|
||||||
super(mv);
|
super(mv, copyAnnotationsAndAttributes);
|
||||||
this.instructionAdapter = new InstructionAdapter(mv);
|
this.instructionAdapter = new InstructionAdapter(mv);
|
||||||
this.remapper = remapper;
|
this.remapper = remapper;
|
||||||
this.nodeRemapper = nodeRemapper;
|
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" }
|
||||||
|
}
|
||||||
+12
@@ -212,6 +212,18 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("kt6552.kt")
|
||||||
public void testKt6552() throws Exception {
|
public void testKt6552() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
|
||||||
|
|||||||
+12
@@ -212,6 +212,18 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("kt6552.kt")
|
||||||
public void testKt6552() throws Exception {
|
public void testKt6552() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
|
||||||
|
|||||||
@@ -212,6 +212,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("kt6552.kt")
|
||||||
public void testKt6552() throws Exception {
|
public void testKt6552() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
|
||||||
|
|||||||
+12
@@ -212,6 +212,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("kt6552.kt")
|
||||||
public void testKt6552() throws Exception {
|
public void testKt6552() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/anonymousObject/kt6552.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user