Search in sources :

Example 1 with RecoveryLoadClass

use of com.sun.tools.javac.comp.Resolve.RecoveryLoadClass 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);
    }
}
Also used : MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) AnnotatedArrayType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType) BugInCF(org.checkerframework.javacutil.BugInCF) JavacScope(com.sun.tools.javac.api.JavacScope) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) TypeTag(com.sun.tools.javac.code.TypeTag) Trees(com.sun.source.util.Trees) Method(java.lang.reflect.Method) TreePath(com.sun.source.util.TreePath) Symbol(com.sun.tools.javac.code.Symbol) Set(java.util.Set) Env(com.sun.tools.javac.comp.Env) TreeUtils(org.checkerframework.javacutil.TreeUtils) InvocationTargetException(java.lang.reflect.InvocationTargetException) TypeKind(javax.lang.model.type.TypeKind) ParameterizedExecutableType(org.checkerframework.framework.type.AnnotatedTypeFactory.ParameterizedExecutableType) List(java.util.List) Flags(com.sun.tools.javac.code.Flags) Context(com.sun.tools.javac.util.Context) Name(com.sun.tools.javac.util.Name) Type(com.sun.tools.javac.code.Type) VariableElement(javax.lang.model.element.VariableElement) Constructor(java.lang.reflect.Constructor) AttrContext(com.sun.tools.javac.comp.AttrContext) ArrayList(java.util.ArrayList) RecoveryLoadClass(com.sun.tools.javac.comp.Resolve.RecoveryLoadClass) UnknownMethod(org.checkerframework.common.reflection.qual.UnknownMethod) NewClassTree(com.sun.source.tree.NewClassTree) JCNewClass(com.sun.tools.javac.tree.JCTree.JCNewClass) ElementFilter(javax.lang.model.util.ElementFilter) AnnotationUtils(org.checkerframework.javacutil.AnnotationUtils) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment) MethodVal(org.checkerframework.common.reflection.qual.MethodVal) NewInstance(org.checkerframework.common.reflection.qual.NewInstance) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) ElementKind(javax.lang.model.element.ElementKind) ExpressionTree(com.sun.source.tree.ExpressionTree) ExecutableElement(javax.lang.model.element.ExecutableElement) TreeMaker(com.sun.tools.javac.tree.TreeMaker) BaseTypeChecker(org.checkerframework.common.basetype.BaseTypeChecker) Names(com.sun.tools.javac.util.Names) AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotatedTypeFactory(org.checkerframework.framework.type.AnnotatedTypeFactory) Invoke(org.checkerframework.common.reflection.qual.Invoke) TypeMirror(javax.lang.model.type.TypeMirror) AnnotationProvider(org.checkerframework.javacutil.AnnotationProvider) JCMethodInvocation(com.sun.tools.javac.tree.JCTree.JCMethodInvocation) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) Collections(java.util.Collections) Resolve(com.sun.tools.javac.comp.Resolve) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) Symbol(com.sun.tools.javac.code.Symbol) RecoveryLoadClass(com.sun.tools.javac.comp.Resolve.RecoveryLoadClass) Method(java.lang.reflect.Method) UnknownMethod(org.checkerframework.common.reflection.qual.UnknownMethod) Env(com.sun.tools.javac.comp.Env) BugInCF(org.checkerframework.javacutil.BugInCF) Resolve(com.sun.tools.javac.comp.Resolve) InvocationTargetException(java.lang.reflect.InvocationTargetException) Name(com.sun.tools.javac.util.Name)

Aggregations

ExpressionTree (com.sun.source.tree.ExpressionTree)1 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)1 NewClassTree (com.sun.source.tree.NewClassTree)1 TreePath (com.sun.source.util.TreePath)1 Trees (com.sun.source.util.Trees)1 JavacScope (com.sun.tools.javac.api.JavacScope)1 Flags (com.sun.tools.javac.code.Flags)1 Symbol (com.sun.tools.javac.code.Symbol)1 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)1 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)1 Type (com.sun.tools.javac.code.Type)1 TypeTag (com.sun.tools.javac.code.TypeTag)1 AttrContext (com.sun.tools.javac.comp.AttrContext)1 Env (com.sun.tools.javac.comp.Env)1 Resolve (com.sun.tools.javac.comp.Resolve)1 RecoveryLoadClass (com.sun.tools.javac.comp.Resolve.RecoveryLoadClass)1 JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)1 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)1 JCMethodInvocation (com.sun.tools.javac.tree.JCTree.JCMethodInvocation)1 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)1