src/share/classes/com/sun/tools/apt/mirror/AptEnv.java

Thu, 02 Oct 2008 19:58:40 -0700

author
xdono
date
Thu, 02 Oct 2008 19:58:40 -0700
changeset 117
24a47c3062fe
parent 113
eff38cc97183
child 331
d043adadc8b6
permissions
-rw-r--r--

6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell

duke@1 1 /*
xdono@117 2 * Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation. Sun designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
duke@1 9 * by Sun in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
duke@1 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 22 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 23 * have any questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.apt.mirror;
duke@1 27
duke@1 28
duke@1 29 import com.sun.tools.apt.mirror.declaration.DeclarationMaker;
duke@1 30 import com.sun.tools.apt.mirror.type.TypeMaker;
duke@1 31 import com.sun.tools.javac.code.*;
duke@1 32 import com.sun.tools.javac.code.Symbol.CompletionFailure;
duke@1 33 import com.sun.tools.javac.comp.Attr;
duke@1 34 import com.sun.tools.javac.comp.Enter;
duke@1 35 import com.sun.tools.javac.util.Context;
jjg@113 36 import com.sun.tools.javac.util.Names;
duke@1 37
duke@1 38
duke@1 39 /**
duke@1 40 * The environment for a run of apt.
duke@1 41 */
duke@1 42
duke@1 43 public class AptEnv {
duke@1 44
jjg@113 45 public Names names; // javac's name table
duke@1 46 public Symtab symtab; // javac's predefined symbols
duke@1 47 public Types jctypes; // javac's type utilities
duke@1 48 public Enter enter; // javac's enter phase
duke@1 49 public Attr attr; // javac's attr phase (to evaluate
duke@1 50 // constant initializers)
duke@1 51 public TypeMaker typeMaker; // apt's internal type utilities
duke@1 52 public DeclarationMaker declMaker; // apt's internal declaration utilities
duke@1 53
duke@1 54
duke@1 55 private static final Context.Key<AptEnv> aptEnvKey =
duke@1 56 new Context.Key<AptEnv>();
duke@1 57
duke@1 58 public static AptEnv instance(Context context) {
duke@1 59 AptEnv instance = context.get(aptEnvKey);
duke@1 60 if (instance == null) {
duke@1 61 instance = new AptEnv(context);
duke@1 62 }
duke@1 63 return instance;
duke@1 64 }
duke@1 65
duke@1 66 private AptEnv(Context context) {
duke@1 67 context.put(aptEnvKey, this);
duke@1 68
jjg@113 69 names = Names.instance(context);
duke@1 70 symtab = Symtab.instance(context);
duke@1 71 jctypes = Types.instance(context);
duke@1 72 enter = Enter.instance(context);
duke@1 73 attr = Attr.instance(context);
duke@1 74 typeMaker = TypeMaker.instance(context);
duke@1 75 declMaker = DeclarationMaker.instance(context);
duke@1 76 }
duke@1 77
duke@1 78
duke@1 79 /**
duke@1 80 * Does a symbol have a given flag? Forces symbol completion.
duke@1 81 */
duke@1 82 public static boolean hasFlag(Symbol sym, long flag) {
duke@1 83 return (getFlags(sym) & flag) != 0;
duke@1 84 }
duke@1 85
duke@1 86 /**
duke@1 87 * Returns a symbol's flags. Forces completion.
duke@1 88 */
duke@1 89 public static long getFlags(Symbol sym) {
duke@1 90 complete(sym);
duke@1 91 return sym.flags();
duke@1 92 }
duke@1 93
duke@1 94 /**
duke@1 95 * Completes a symbol, ignoring completion failures.
duke@1 96 */
duke@1 97 private static void complete(Symbol sym) {
duke@1 98 while (true) {
duke@1 99 try {
duke@1 100 sym.complete();
duke@1 101 return;
duke@1 102 } catch (CompletionFailure e) {
duke@1 103 // Should never see two in a row, but loop just to be sure.
duke@1 104 }
duke@1 105 }
duke@1 106 }
duke@1 107 }

mercurial