1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package io.earcam.instrumental.agent.defy;
20
21 import static org.objectweb.asm.Opcodes.ACC_FINAL;
22 import static org.objectweb.asm.Opcodes.ACC_INTERFACE;
23 import static org.objectweb.asm.Opcodes.ASM6;
24
25 import org.objectweb.asm.ClassVisitor;
26 import org.objectweb.asm.FieldVisitor;
27 import org.objectweb.asm.MethodVisitor;
28
29 class RemoveFinalVisitor extends ClassVisitor {
30
31 private boolean isInterface;
32
33
34 RemoveFinalVisitor(ClassVisitor cv)
35 {
36 super(ASM6, cv);
37 }
38
39
40 @Override
41 public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
42 {
43 isInterface = isInterface(access);
44 cv.visit(version, removeFinalModifier(access), name, signature, superName, interfaces);
45 }
46
47
48 private boolean isInterface(int access)
49 {
50 return (access & ACC_INTERFACE) == ACC_INTERFACE;
51 }
52
53
54 private int removeFinalModifier(int access)
55 {
56 return isInterface ? access : access & ~ACC_FINAL;
57 }
58
59
60 @Override
61 public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
62 {
63 return super.visitMethod(removeFinalModifier(access), name, desc, signature, exceptions);
64 }
65
66
67 @Override
68 public FieldVisitor visitField(int access, String name, String desc, String signature, Object value)
69 {
70 return super.visitField(removeFinalModifier(access), name, desc, signature, value);
71 }
72 }