Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix findIdent incompatibility with Java 13 #1439

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.sun.tools.javac.comp.Resolve;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.util.Name;
import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down Expand Up @@ -94,17 +95,49 @@ public static Symbol findIdent(String name, VisitorState state, KindSelector kin
env = MemberEnter.instance(state.context).getMethodEnv((JCMethodDecl) enclosingMethod, env);
}
try {
Method method =
Resolve.class.getDeclaredMethod("findIdent", Env.class, Name.class, KindSelector.class);
method.setAccessible(true);
Symbol result =
(Symbol) method.invoke(Resolve.instance(state.context), env, state.getName(name), kind);
(Symbol) FindIdent.method.invoke(
Resolve.instance(state.context),
FindIdent.args.of(env, state.getName(name), kind));
return result.exists() ? result : null;
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}

private static final class FindIdent {
static final Method method;
static final Args args;
static {
Method m;
Args a;
try {
// Java 13
m = Resolve.class.getDeclaredMethod(
"findIdent", DiagnosticPosition.class, Env.class, Name.class, KindSelector.class);
a = (env, name, kind) -> new Object[] { null, env, name, kind };
} catch (NoSuchMethodException e1) {
try {
// Java 12 and below
m = Resolve.class.getDeclaredMethod(
"findIdent", Env.class, Name.class, KindSelector.class);
a = (env, name, kind) -> new Object[] { env, name, kind };
} catch (NoSuchMethodException e2) {
LinkageError linkageError = new LinkageError(e1.getMessage(), e1);
linkageError.addSuppressed(e2);
throw linkageError;
}
}
m.setAccessible(true);
method = m;
args = a;
}

interface Args {
Object[] of(Env<AttrContext> env, Name name, KindSelector kind);
}
}

/**
* Finds the set of all bare variable identifiers in scope at the current location. Identifiers
* are ordered by ascending distance/scope count from the current location to match shadowing
Expand Down