use of com.sun.tools.javac.comp.Env in project checker-framework by typetools.
the class DefaultReflectionResolver method getSymbol.
private Symbol getSymbol(String className, Env<AttrContext> env, Names names, Resolve resolve) {
Method loadClass;
try {
loadClass = Resolve.class.getDeclaredMethod("loadClass", Env.class, Name.class, RecoveryLoadClass.class);
loadClass.setAccessible(true);
} catch (SecurityException | NoSuchMethodException | IllegalArgumentException e) {
// A problem with javac is serious and must be reported.
throw new BugInCF("Error in obtaining reflective method.", e);
}
try {
RecoveryLoadClass noRecovery = (e, n) -> null;
return (Symbol) loadClass.invoke(resolve, env, names.fromString(className), noRecovery);
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// A problem with javac is serious and must be reported.
throw new BugInCF("Error in invoking reflective method.", e);
}
}
use of com.sun.tools.javac.comp.Env in project error-prone by google.
the class Template method callCheckMethod.
/**
* Reflectively invoke Resolve.checkMethod(), which despite being package-private is apparently
* the only useful entry-point into javac8's type inference implementation.
*/
private MethodType callCheckMethod(Warner warner, Inliner inliner, Object resultInfo, List<Type> actualArgTypes, MethodSymbol methodSymbol, Type site, Env<AttrContext> env) throws InferException {
try {
Method checkMethod;
checkMethod = Resolve.class.getDeclaredMethod("checkMethod", Env.class, Type.class, Symbol.class, Class.forName(// ResultInfo is package-private
"com.sun.tools.javac.comp.Attr$ResultInfo"), List.class, List.class, Warner.class);
checkMethod.setAccessible(true);
return (MethodType) checkMethod.invoke(Resolve.instance(inliner.getContext()), env, site, methodSymbol, resultInfo, actualArgTypes, /*freeTypeVariables=*/
List.<Type>nil(), warner);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof Resolve.InapplicableMethodException) {
throw new InferException(ImmutableList.of(((Resolve.InapplicableMethodException) e.getTargetException()).getDiagnostic()));
}
throw new LinkageError(e.getMessage(), e.getCause());
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
}
Aggregations