[jdk9] Fix members_field error

This commit is contained in:
Roel Spilker committed 2017-02-14 01:21:27 +01:00
1 parent 05f93771e9
commit e3a86782e5
1 file changed
+18 -5
@@ -894,16 +894,20 @@ public class JavacHandlerUtil {
static class ClassSymbolMembersField {
private static final Field membersField;
private static final Method removeMethod;
private static final Method enterMethod;
static {
Field f = null;
Method m = null;
Method r = null;
Method e = null;
try {
f = ClassSymbol.class.getField("members_field");
m = f.getType().getMethod("remove", Symbol.class);
} catch (Exception e) {}
r = f.getType().getMethod("remove", Symbol.class);
e = f.getType().getMethod("enter", Symbol.class);
} catch (Exception ex) {}
membersField = f;
removeMethod = m;
removeMethod = r;
enterMethod = r;
}
static void remove(ClassSymbol from, Symbol toRemove) {
@@ -914,6 +918,15 @@ public class JavacHandlerUtil {
removeMethod.invoke(scope, toRemove);
} catch (Exception e) {}
}
static void enter(ClassSymbol from, Symbol toEnter) {
if (from == null) return;
try {
Scope scope = (Scope) membersField.get(from);
if (scope == null) return;
enterMethod.invoke(scope, toEnter);
} catch (Exception e) {}
}
}
public static void injectMethod(JavacNode typeNode, JCMethodDecl method) {
@@ -959,7 +972,7 @@ public class JavacHandlerUtil {
if (typeMirror == null || paramTypes == null || returnType == null) return;
ClassSymbol cs = (ClassSymbol) typeMirror;
MethodSymbol methodSymbol = new MethodSymbol(access, methodName, new MethodType(paramTypes, returnType, List.<Type>nil(), Symtab.instance(context).methodClass), cs);
cs.members_field.enter(methodSymbol);
ClassSymbolMembersField.enter(cs, methodSymbol);
}
/**