0N/A/*
553N/A * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.tools.apt.mirror;
0N/A
0N/A
0N/Aimport com.sun.tools.apt.mirror.declaration.DeclarationMaker;
0N/Aimport com.sun.tools.apt.mirror.type.TypeMaker;
0N/Aimport com.sun.tools.javac.code.*;
0N/Aimport com.sun.tools.javac.code.Symbol.CompletionFailure;
0N/Aimport com.sun.tools.javac.comp.Attr;
0N/Aimport com.sun.tools.javac.comp.Enter;
0N/Aimport com.sun.tools.javac.util.Context;
112N/Aimport com.sun.tools.javac.util.Names;
0N/A
0N/A
0N/A/**
0N/A * The environment for a run of apt.
0N/A */
330N/A@SuppressWarnings("deprecation")
0N/Apublic class AptEnv {
0N/A
112N/A public Names names; // javac's name table
0N/A public Symtab symtab; // javac's predefined symbols
0N/A public Types jctypes; // javac's type utilities
0N/A public Enter enter; // javac's enter phase
0N/A public Attr attr; // javac's attr phase (to evaluate
0N/A // constant initializers)
0N/A public TypeMaker typeMaker; // apt's internal type utilities
0N/A public DeclarationMaker declMaker; // apt's internal declaration utilities
0N/A
0N/A
0N/A private static final Context.Key<AptEnv> aptEnvKey =
0N/A new Context.Key<AptEnv>();
0N/A
0N/A public static AptEnv instance(Context context) {
0N/A AptEnv instance = context.get(aptEnvKey);
0N/A if (instance == null) {
0N/A instance = new AptEnv(context);
0N/A }
0N/A return instance;
0N/A }
0N/A
0N/A private AptEnv(Context context) {
0N/A context.put(aptEnvKey, this);
0N/A
112N/A names = Names.instance(context);
0N/A symtab = Symtab.instance(context);
0N/A jctypes = Types.instance(context);
0N/A enter = Enter.instance(context);
0N/A attr = Attr.instance(context);
0N/A typeMaker = TypeMaker.instance(context);
0N/A declMaker = DeclarationMaker.instance(context);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Does a symbol have a given flag? Forces symbol completion.
0N/A */
0N/A public static boolean hasFlag(Symbol sym, long flag) {
0N/A return (getFlags(sym) & flag) != 0;
0N/A }
0N/A
0N/A /**
0N/A * Returns a symbol's flags. Forces completion.
0N/A */
0N/A public static long getFlags(Symbol sym) {
0N/A complete(sym);
0N/A return sym.flags();
0N/A }
0N/A
0N/A /**
0N/A * Completes a symbol, ignoring completion failures.
0N/A */
0N/A private static void complete(Symbol sym) {
0N/A while (true) {
0N/A try {
0N/A sym.complete();
0N/A return;
0N/A } catch (CompletionFailure e) {
0N/A // Should never see two in a row, but loop just to be sure.
0N/A }
0N/A }
0N/A }
0N/A}