2727import java .nio .file .Paths ;
2828import java .nio .file .StandardCopyOption ;
2929import java .util .Collections ;
30+ import java .util .LinkedHashSet ;
31+ import java .util .Set ;
3032
3133import org .objectweb .asm .ClassReader ;
3234import org .objectweb .asm .ClassVisitor ;
3335import org .objectweb .asm .ClassWriter ;
36+ import org .objectweb .asm .FieldVisitor ;
3437import org .objectweb .asm .MethodVisitor ;
3538import org .objectweb .asm .Opcodes ;
3639
4144 */
4245public final class EclipseRewriter {
4346
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+
4463 private EclipseRewriter () {
4564 }
4665
@@ -73,10 +92,18 @@ private static class DefaultCodeFormatterManipulator extends ClassVisitor {
7392 super (Opcodes .ASM5 , visitor );
7493 }
7594
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+
76103 @ Override
77104 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 ;
80107 }
81108 return new DefaultCodeFormatterMethodManipulator (
82109 super .visitMethod (access , name , desc , signature , exceptions ));
@@ -92,9 +119,8 @@ private static class DefaultCodeFormatterMethodManipulator extends MethodVisitor
92119
93120 @ Override
94121 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 ;
98124 }
99125 super .visitMethodInsn (opcode , owner , name , desc , itf );
100126 }
0 commit comments