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;