/** Finds a declaration with the given name and type that is in scope at the current location. */ @Nullable public static Symbol findIdent(String name, VisitorState state, KindSelector kind) { ClassType enclosingClass = ASTHelpers.getType(state.findEnclosing(ClassTree.class)); if (enclosingClass == null || enclosingClass.tsym == null) { return null; } Env<AttrContext> env = Enter.instance(state.context).getClassEnv(enclosingClass.tsym); MethodTree enclosingMethod = state.findEnclosing(MethodTree.class); if (enclosingMethod != null) { 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); return result.exists() ? result : null; } catch (ReflectiveOperationException e) { throw new LinkageError(e.getMessage(), e); } }
undef.add(ee); } else if (existingReturnType.getKind() == TypeKind.DECLARED && eeReturnType.getKind() == TypeKind.DECLARED) { Env<AttrContext> env = Enter.instance(ctx).getClassEnv((TypeSymbol)impl); DeclaredType subType = env != null ? findCommonSubtype((DeclaredType)existingReturnType, (DeclaredType)eeReturnType, env) : null; if (subType != null) {
public static void analyze(Iterable<? extends Element> elems, Context ctx) { assert elems != null; PostFlowAnalysis postFlowAnalysis = new PostFlowAnalysis(ctx); for (Element e : elems) { if (e instanceof TypeSymbol) { Env<AttrContext> env = postFlowAnalysis.enter.getClassEnv((TypeSymbol)e); if (env != null) { JavaFileObject prev = postFlowAnalysis.log.useSource(env.enclClass.sym.sourcefile != null ? env.enclClass.sym.sourcefile : env.toplevel.sourcefile); try { postFlowAnalysis.scan(env.toplevel); } finally { postFlowAnalysis.log.useSource(prev); } } } } }
/** Finds a declaration with the given name and type that is in scope at the current location. */ public static Symbol findIdent(String name, VisitorState state, KindSelector kind) { ClassType enclosingClass = ASTHelpers.getType(state.findEnclosing(ClassTree.class)); if (enclosingClass == null || enclosingClass.tsym == null) { return null; } Env<AttrContext> env = Enter.instance(state.context).getClassEnv(enclosingClass.tsym); MethodTree enclosingMethod = state.findEnclosing(MethodTree.class); if (enclosingMethod != null) { 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); return result.exists() ? result : null; } catch (ReflectiveOperationException e) { throw new LinkageError(e.getMessage(), e); } }
/**Parses given type in given context. * * @param expr type specification * @param scope in which simple names should be resolved * @return parsed {@link TypeMirror} or null if the given specification cannot be parsed */ public TypeMirror parseType(String expr, TypeElement scope) { Enter enter = Enter.instance(info.impl.getJavacTask().getContext()); com.sun.tools.javac.tree.TreeMaker jcMaker = com.sun.tools.javac.tree.TreeMaker.instance(info.impl.getJavacTask().getContext()); int oldPos = jcMaker.pos; try { if (enter.getClassEnv((Symbol.TypeSymbol)scope) == null) { if (info.getTrees().getTree(scope) == null) return null; } return info.impl.getJavacTask().parseType(expr, scope); } finally { jcMaker.pos = oldPos; } }
case CLASS: env = enter.getClassEnv(((JCClassDecl)tree).sym); break; case METHOD:
case CLASS: env = enter.getClassEnv(((JCClassDecl)tree).sym); break; case METHOD:
case INTERFACE: env = enter.getClassEnv(((JCClassDecl)tree).sym); break; case METHOD:
case INTERFACE: env = enter.getClassEnv(((JCClassDecl)tree).sym); break; case METHOD: