27
27
import java .nio .file .Paths ;
28
28
import java .nio .file .StandardCopyOption ;
29
29
import java .util .Collections ;
30
+ import java .util .LinkedHashSet ;
31
+ import java .util .Set ;
30
32
31
33
import org .objectweb .asm .ClassReader ;
32
34
import org .objectweb .asm .ClassVisitor ;
33
35
import org .objectweb .asm .ClassWriter ;
36
+ import org .objectweb .asm .FieldVisitor ;
34
37
import org .objectweb .asm .MethodVisitor ;
35
38
import org .objectweb .asm .Opcodes ;
36
39
41
44
*/
42
45
public final class EclipseRewriter {
43
46
47
+ private static final Set <String > UPDATED_METHODS ;
48
+ static {
49
+ Set <String > updatedMethods = new LinkedHashSet <String >();
50
+ updatedMethods .add ("prepareWraps" );
51
+ updatedMethods .add ("tokenizeSource" );
52
+ UPDATED_METHODS = Collections .unmodifiableSet (updatedMethods );
53
+ }
54
+
55
+ private static final Set <String > UPDATED_FIELDS ;
56
+ static {
57
+ Set <String > updatedFields = new LinkedHashSet <String >();
58
+ updatedFields .add ("sourceLevel" );
59
+ updatedFields .add ("tokens" );
60
+ UPDATED_FIELDS = Collections .unmodifiableSet (updatedFields );
61
+ }
62
+
44
63
private EclipseRewriter () {
45
64
}
46
65
@@ -73,10 +92,18 @@ private static class DefaultCodeFormatterManipulator extends ClassVisitor {
73
92
super (Opcodes .ASM5 , visitor );
74
93
}
75
94
95
+ @ Override
96
+ public FieldVisitor visitField (int access , String name , String desc , String signature , Object value ) {
97
+ if (access == Opcodes .ACC_PRIVATE && UPDATED_FIELDS .contains (name )) {
98
+ access = Opcodes .ACC_PROTECTED ;
99
+ }
100
+ return super .visitField (access , name , desc , signature , value );
101
+ }
102
+
76
103
@ Override
77
104
public MethodVisitor visitMethod (int access , String name , String desc , String signature , String [] exceptions ) {
78
- if ("prepareWraps" . equals ( name ) && Opcodes .ACC_PRIVATE == access ) {
79
- return super . visitMethod ( Opcodes .ACC_PROTECTED , name , desc , signature , exceptions ) ;
105
+ if (access == Opcodes .ACC_PRIVATE && UPDATED_METHODS . contains ( name ) ) {
106
+ access = Opcodes .ACC_PROTECTED ;
80
107
}
81
108
return new DefaultCodeFormatterMethodManipulator (
82
109
super .visitMethod (access , name , desc , signature , exceptions ));
@@ -92,9 +119,8 @@ private static class DefaultCodeFormatterMethodManipulator extends MethodVisitor
92
119
93
120
@ Override
94
121
public void visitMethodInsn (int opcode , String owner , String name , String desc , boolean itf ) {
95
- if ("prepareWraps" .equals (name ) && opcode == Opcodes .INVOKESPECIAL ) {
96
- super .visitMethodInsn (Opcodes .INVOKEVIRTUAL , owner , name , desc , itf );
97
- return ;
122
+ if (opcode == Opcodes .INVOKESPECIAL && UPDATED_METHODS .contains (name )) {
123
+ opcode = Opcodes .INVOKEVIRTUAL ;
98
124
}
99
125
super .visitMethodInsn (opcode , owner , name , desc , itf );
100
126
}
0 commit comments