Wed, 21 Sep 2011 21:56:53 -0700
7092965: javac should not close processorClassLoader before end of compilation
Reviewed-by: darcy
1 /*
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.javac.code;
28 import java.util.EnumSet;
29 import java.util.Locale;
31 import com.sun.tools.javac.api.Formattable;
32 import com.sun.tools.javac.api.Messages;
34 import static com.sun.tools.javac.code.TypeTags.*;
35 import static com.sun.tools.javac.code.Flags.*;
37 /** Internal symbol kinds, which distinguish between elements of
38 * different subclasses of Symbol. Symbol kinds are organized so they can be
39 * or'ed to sets.
40 *
41 * <p><b>This is NOT part of any supported API.
42 * If you write code that depends on this, you do so at your own risk.
43 * This code and its internal interfaces are subject to change or
44 * deletion without notice.</b>
45 */
46 public class Kinds {
48 private Kinds() {} // uninstantiable
50 /** The empty set of kinds.
51 */
52 public final static int NIL = 0;
54 /** The kind of package symbols.
55 */
56 public final static int PCK = 1 << 0;
58 /** The kind of type symbols (classes, interfaces and type variables).
59 */
60 public final static int TYP = 1 << 1;
62 /** The kind of variable symbols.
63 */
64 public final static int VAR = 1 << 2;
66 /** The kind of values (variables or non-variable expressions), includes VAR.
67 */
68 public final static int VAL = (1 << 3) | VAR;
70 /** The kind of methods.
71 */
72 public final static int MTH = 1 << 4;
74 /** The error kind, which includes all other kinds.
75 */
76 public final static int ERR = (1 << 5) - 1;
78 /** The set of all kinds.
79 */
80 public final static int AllKinds = ERR;
82 /** Kinds for erroneous symbols that complement the above
83 */
84 public static final int ERRONEOUS = 1 << 6;
85 public static final int AMBIGUOUS = ERRONEOUS+1; // ambiguous reference
86 public static final int HIDDEN = ERRONEOUS+2; // hidden method or field
87 public static final int STATICERR = ERRONEOUS+3; // nonstatic member from static context
88 public static final int ABSENT_VAR = ERRONEOUS+4; // missing variable
89 public static final int WRONG_MTHS = ERRONEOUS+5; // methods with wrong arguments
90 public static final int WRONG_MTH = ERRONEOUS+6; // one method with wrong arguments
91 public static final int ABSENT_MTH = ERRONEOUS+7; // missing method
92 public static final int ABSENT_TYP = ERRONEOUS+8; // missing type
94 public enum KindName implements Formattable {
95 ANNOTATION("kindname.annotation"),
96 CONSTRUCTOR("kindname.constructor"),
97 INTERFACE("kindname.interface"),
98 ENUM("kindname.enum"),
99 STATIC("kindname.static"),
100 TYPEVAR("kindname.type.variable"),
101 BOUND("kindname.type.variable.bound"),
102 VAR("kindname.variable"),
103 VAL("kindname.value"),
104 METHOD("kindname.method"),
105 CLASS("kindname.class"),
106 STATIC_INIT("kindname.static.init"),
107 INSTANCE_INIT("kindname.instance.init"),
108 PACKAGE("kindname.package");
110 private String name;
112 KindName(String name) {
113 this.name = name;
114 }
116 public String toString() {
117 return name;
118 }
120 public String getKind() {
121 return "Kindname";
122 }
124 public String toString(Locale locale, Messages messages) {
125 String s = toString();
126 return messages.getLocalizedString(locale, "compiler.misc." + s);
127 }
128 }
130 /** A KindName representing a given symbol kind
131 */
132 public static KindName kindName(int kind) {
133 switch (kind) {
134 case PCK: return KindName.PACKAGE;
135 case TYP: return KindName.CLASS;
136 case VAR: return KindName.VAR;
137 case VAL: return KindName.VAL;
138 case MTH: return KindName.METHOD;
139 default : throw new AssertionError("Unexpected kind: "+kind);
140 }
141 }
143 /** A KindName representing a given symbol
144 */
145 public static KindName kindName(Symbol sym) {
146 switch (sym.getKind()) {
147 case PACKAGE:
148 return KindName.PACKAGE;
150 case ENUM:
151 return KindName.ENUM;
153 case ANNOTATION_TYPE:
154 case CLASS:
155 return KindName.CLASS;
157 case INTERFACE:
158 return KindName.INTERFACE;
160 case TYPE_PARAMETER:
161 return KindName.TYPEVAR;
163 case ENUM_CONSTANT:
164 case FIELD:
165 case PARAMETER:
166 case LOCAL_VARIABLE:
167 case EXCEPTION_PARAMETER:
168 case RESOURCE_VARIABLE:
169 return KindName.VAR;
171 case CONSTRUCTOR:
172 return KindName.CONSTRUCTOR;
174 case METHOD:
175 return KindName.METHOD;
176 case STATIC_INIT:
177 return KindName.STATIC_INIT;
178 case INSTANCE_INIT:
179 return KindName.INSTANCE_INIT;
181 default:
182 if (sym.kind == VAL)
183 // I don't think this can happen but it can't harm
184 // playing it safe --ahe
185 return KindName.VAL;
186 else
187 throw new AssertionError("Unexpected kind: "+sym.getKind());
188 }
189 }
191 /** A set of KindName(s) representing a set of symbol's kinds.
192 */
193 public static EnumSet<KindName> kindNames(int kind) {
194 EnumSet<KindName> kinds = EnumSet.noneOf(KindName.class);
195 if ((kind & VAL) != 0)
196 kinds.add(((kind & VAL) == VAR) ? KindName.VAR : KindName.VAL);
197 if ((kind & MTH) != 0) kinds.add(KindName.METHOD);
198 if ((kind & TYP) != 0) kinds.add(KindName.CLASS);
199 if ((kind & PCK) != 0) kinds.add(KindName.PACKAGE);
200 return kinds;
201 }
203 /** A KindName representing the kind of a given class/interface type.
204 */
205 public static KindName typeKindName(Type t) {
206 if (t.tag == TYPEVAR ||
207 t.tag == CLASS && (t.tsym.flags() & COMPOUND) != 0)
208 return KindName.BOUND;
209 else if (t.tag == PACKAGE)
210 return KindName.PACKAGE;
211 else if ((t.tsym.flags_field & ANNOTATION) != 0)
212 return KindName.ANNOTATION;
213 else if ((t.tsym.flags_field & INTERFACE) != 0)
214 return KindName.INTERFACE;
215 else
216 return KindName.CLASS;
217 }
219 /** A KindName representing the kind of a a missing symbol, given an
220 * error kind.
221 * */
222 public static KindName absentKind(int kind) {
223 switch (kind) {
224 case ABSENT_VAR:
225 return KindName.VAR;
226 case WRONG_MTHS: case WRONG_MTH: case ABSENT_MTH:
227 return KindName.METHOD;
228 case ABSENT_TYP:
229 return KindName.CLASS;
230 default:
231 throw new AssertionError("Unexpected kind: "+kind);
232 }
233 }
234 }