Mon, 28 Feb 2011 11:48:53 +0000
7015430: Incorrect thrown type determined for unchecked invocations
Summary: Thrown types do not get updated after 15.12.2.8, and do not get erased as per 15.12.2.6
Reviewed-by: jjg, dlsmith
1 /*
2 * Copyright (c) 1999, 2010, 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 PACKAGE("kindname.package");
108 private String name;
110 KindName(String name) {
111 this.name = name;
112 }
114 public String toString() {
115 return name;
116 }
118 public String getKind() {
119 return "Kindname";
120 }
122 public String toString(Locale locale, Messages messages) {
123 String s = toString();
124 return messages.getLocalizedString(locale, "compiler.misc." + s);
125 }
126 }
128 /** A KindName representing a given symbol kind
129 */
130 public static KindName kindName(int kind) {
131 switch (kind) {
132 case PCK: return KindName.PACKAGE;
133 case TYP: return KindName.CLASS;
134 case VAR: return KindName.VAR;
135 case VAL: return KindName.VAL;
136 case MTH: return KindName.METHOD;
137 default : throw new AssertionError("Unexpected kind: "+kind);
138 }
139 }
141 /** A KindName representing a given symbol
142 */
143 public static KindName kindName(Symbol sym) {
144 switch (sym.getKind()) {
145 case PACKAGE:
146 return KindName.PACKAGE;
148 case ENUM:
149 return KindName.ENUM;
151 case ANNOTATION_TYPE:
152 case CLASS:
153 return KindName.CLASS;
155 case INTERFACE:
156 return KindName.INTERFACE;
158 case TYPE_PARAMETER:
159 return KindName.TYPEVAR;
161 case ENUM_CONSTANT:
162 case FIELD:
163 case PARAMETER:
164 case LOCAL_VARIABLE:
165 case EXCEPTION_PARAMETER:
166 return KindName.VAR;
168 case CONSTRUCTOR:
169 return KindName.CONSTRUCTOR;
171 case METHOD:
172 case STATIC_INIT:
173 case INSTANCE_INIT:
174 return KindName.METHOD;
176 default:
177 if (sym.kind == VAL)
178 // I don't think this can happen but it can't harm
179 // playing it safe --ahe
180 return KindName.VAL;
181 else
182 throw new AssertionError("Unexpected kind: "+sym.getKind());
183 }
184 }
186 /** A set of KindName(s) representing a set of symbol's kinds.
187 */
188 public static EnumSet<KindName> kindNames(int kind) {
189 EnumSet<KindName> kinds = EnumSet.noneOf(KindName.class);
190 if ((kind & VAL) != 0)
191 kinds.add(((kind & VAL) == VAR) ? KindName.VAR : KindName.VAL);
192 if ((kind & MTH) != 0) kinds.add(KindName.METHOD);
193 if ((kind & TYP) != 0) kinds.add(KindName.CLASS);
194 if ((kind & PCK) != 0) kinds.add(KindName.PACKAGE);
195 return kinds;
196 }
198 /** A KindName representing the kind of a given class/interface type.
199 */
200 public static KindName typeKindName(Type t) {
201 if (t.tag == TYPEVAR ||
202 t.tag == CLASS && (t.tsym.flags() & COMPOUND) != 0)
203 return KindName.BOUND;
204 else if (t.tag == PACKAGE)
205 return KindName.PACKAGE;
206 else if ((t.tsym.flags_field & ANNOTATION) != 0)
207 return KindName.ANNOTATION;
208 else if ((t.tsym.flags_field & INTERFACE) != 0)
209 return KindName.INTERFACE;
210 else
211 return KindName.CLASS;
212 }
214 /** A KindName representing the kind of a a missing symbol, given an
215 * error kind.
216 * */
217 public static KindName absentKind(int kind) {
218 switch (kind) {
219 case ABSENT_VAR:
220 return KindName.VAR;
221 case WRONG_MTHS: case WRONG_MTH: case ABSENT_MTH:
222 return KindName.METHOD;
223 case ABSENT_TYP:
224 return KindName.CLASS;
225 default:
226 throw new AssertionError("Unexpected kind: "+kind);
227 }
228 }
229 }