Thu, 10 Jun 2010 09:29:23 +0100
6945418: Project Coin: Simplified Varargs Method Invocation
Summary: Add new mandatory warning for unsafe vararg method declaration. Warning can be suppressed as usual (@SuppressWarnings("varargs")/-Xlint:-varargs)
Reviewed-by: jjg, darcy
1 /*
2 * Copyright (c) 1999, 2008, 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.util;
28 /**
29 * Access to the compiler's name table. STandard names are defined,
30 * as well as methods to create new names.
31 *
32 * <p><b>This is NOT part of any API supported by Sun Microsystems. If
33 * you write code that depends on this, you do so at your own risk.
34 * This code and its internal interfaces are subject to change or
35 * deletion without notice.</b>
36 */
37 public class Names {
39 public static final Context.Key<Names> namesKey = new Context.Key<Names>();
41 public static Names instance(Context context) {
42 Names instance = context.get(namesKey);
43 if (instance == null) {
44 instance = new Names(context);
45 context.put(namesKey, instance);
46 }
47 return instance;
48 }
50 public final Name slash;
51 public final Name hyphen;
52 public final Name T;
53 public final Name slashequals;
54 public final Name deprecated;
55 public final Name init;
56 public final Name clinit;
57 public final Name error;
58 public final Name any;
59 public final Name empty;
60 public final Name one;
61 public final Name period;
62 public final Name comma;
63 public final Name semicolon;
64 public final Name asterisk;
65 public final Name _this;
66 public final Name _super;
67 public final Name _default;
68 public final Name _class;
69 public final Name java_lang;
70 public final Name java_lang_Object;
71 public final Name java_lang_Class;
72 public final Name java_lang_Cloneable;
73 public final Name java_io_Serializable;
74 public final Name serialVersionUID;
75 public final Name java_lang_Enum;
76 public final Name java_dyn_MethodHandle;
77 public final Name java_dyn_InvokeDynamic;
78 public final Name package_info;
79 public final Name ConstantValue;
80 public final Name LineNumberTable;
81 public final Name LocalVariableTable;
82 public final Name LocalVariableTypeTable;
83 public final Name CharacterRangeTable;
84 public final Name StackMap;
85 public final Name StackMapTable;
86 public final Name SourceID;
87 public final Name CompilationID;
88 public final Name Code;
89 public final Name Exceptions;
90 public final Name SourceFile;
91 public final Name InnerClasses;
92 public final Name Synthetic;
93 public final Name Bridge;
94 public final Name Deprecated;
95 public final Name Enum;
96 public final Name _name;
97 public final Name Signature;
98 public final Name Varargs;
99 public final Name Annotation;
100 public final Name RuntimeVisibleAnnotations;
101 public final Name RuntimeInvisibleAnnotations;
102 public final Name RuntimeVisibleTypeAnnotations;
103 public final Name RuntimeInvisibleTypeAnnotations;
104 public final Name RuntimeVisibleParameterAnnotations;
105 public final Name RuntimeInvisibleParameterAnnotations;
106 public final Name Value;
107 public final Name EnclosingMethod;
108 public final Name desiredAssertionStatus;
109 public final Name append;
110 public final Name family;
111 public final Name forName;
112 public final Name toString;
113 public final Name length;
114 public final Name valueOf;
115 public final Name value;
116 public final Name getMessage;
117 public final Name getClass;
118 public final Name invoke;
119 public final Name TYPE;
120 public final Name TYPE_USE;
121 public final Name TYPE_PARAMETER;
122 public final Name FIELD;
123 public final Name METHOD;
124 public final Name PARAMETER;
125 public final Name CONSTRUCTOR;
126 public final Name LOCAL_VARIABLE;
127 public final Name ANNOTATION_TYPE;
128 public final Name PACKAGE;
129 public final Name SOURCE;
130 public final Name CLASS;
131 public final Name RUNTIME;
132 public final Name Array;
133 public final Name Method;
134 public final Name Bound;
135 public final Name clone;
136 public final Name getComponentType;
137 public final Name getClassLoader;
138 public final Name initCause;
139 public final Name values;
140 public final Name iterator;
141 public final Name hasNext;
142 public final Name next;
143 public final Name AnnotationDefault;
144 public final Name ordinal;
145 public final Name equals;
146 public final Name hashCode;
147 public final Name compareTo;
148 public final Name getDeclaringClass;
149 public final Name ex;
150 public final Name finalize;
152 public final Name.Table table;
154 public Names(Context context) {
155 Options options = Options.instance(context);
156 table = createTable(options);
158 slash = fromString("/");
159 hyphen = fromString("-");
160 T = fromString("T");
161 slashequals = fromString("/=");
162 deprecated = fromString("deprecated");
164 init = fromString("<init>");
165 clinit = fromString("<clinit>");
166 error = fromString("<error>");
167 any = fromString("<any>");
168 empty = fromString("");
169 one = fromString("1");
170 period = fromString(".");
171 comma = fromString(",");
172 semicolon = fromString(";");
173 asterisk = fromString("*");
174 _this = fromString("this");
175 _super = fromString("super");
176 _default = fromString("default");
178 _class = fromString("class");
179 java_lang = fromString("java.lang");
180 java_lang_Object = fromString("java.lang.Object");
181 java_lang_Class = fromString("java.lang.Class");
182 java_lang_Cloneable = fromString("java.lang.Cloneable");
183 java_io_Serializable = fromString("java.io.Serializable");
184 java_lang_Enum = fromString("java.lang.Enum");
185 java_dyn_MethodHandle = fromString("java.dyn.MethodHandle");
186 java_dyn_InvokeDynamic = fromString("java.dyn.InvokeDynamic");
187 package_info = fromString("package-info");
188 serialVersionUID = fromString("serialVersionUID");
189 ConstantValue = fromString("ConstantValue");
190 LineNumberTable = fromString("LineNumberTable");
191 LocalVariableTable = fromString("LocalVariableTable");
192 LocalVariableTypeTable = fromString("LocalVariableTypeTable");
193 CharacterRangeTable = fromString("CharacterRangeTable");
194 StackMap = fromString("StackMap");
195 StackMapTable = fromString("StackMapTable");
196 SourceID = fromString("SourceID");
197 CompilationID = fromString("CompilationID");
198 Code = fromString("Code");
199 Exceptions = fromString("Exceptions");
200 SourceFile = fromString("SourceFile");
201 InnerClasses = fromString("InnerClasses");
202 Synthetic = fromString("Synthetic");
203 Bridge = fromString("Bridge");
204 Deprecated = fromString("Deprecated");
205 Enum = fromString("Enum");
206 _name = fromString("name");
207 Signature = fromString("Signature");
208 Varargs = fromString("Varargs");
209 Annotation = fromString("Annotation");
210 RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations");
211 RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations");
212 RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations");
213 RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations");
214 RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations");
215 RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
216 Value = fromString("Value");
217 EnclosingMethod = fromString("EnclosingMethod");
219 desiredAssertionStatus = fromString("desiredAssertionStatus");
221 append = fromString("append");
222 family = fromString("family");
223 forName = fromString("forName");
224 toString = fromString("toString");
225 length = fromString("length");
226 valueOf = fromString("valueOf");
227 value = fromString("value");
228 getMessage = fromString("getMessage");
229 getClass = fromString("getClass");
230 invoke = fromString("invoke");
232 TYPE = fromString("TYPE");
233 TYPE_USE = fromString("TYPE_USE");
234 TYPE_PARAMETER = fromString("TYPE_PARAMETER");
235 FIELD = fromString("FIELD");
236 METHOD = fromString("METHOD");
237 PARAMETER = fromString("PARAMETER");
238 CONSTRUCTOR = fromString("CONSTRUCTOR");
239 LOCAL_VARIABLE = fromString("LOCAL_VARIABLE");
240 ANNOTATION_TYPE = fromString("ANNOTATION_TYPE");
241 PACKAGE = fromString("PACKAGE");
243 SOURCE = fromString("SOURCE");
244 CLASS = fromString("CLASS");
245 RUNTIME = fromString("RUNTIME");
247 Array = fromString("Array");
248 Method = fromString("Method");
249 Bound = fromString("Bound");
250 clone = fromString("clone");
251 getComponentType = fromString("getComponentType");
252 getClassLoader = fromString("getClassLoader");
253 initCause = fromString("initCause");
254 values = fromString("values");
255 iterator = fromString("iterator");
256 hasNext = fromString("hasNext");
257 next = fromString("next");
258 AnnotationDefault = fromString("AnnotationDefault");
259 ordinal = fromString("ordinal");
260 equals = fromString("equals");
261 hashCode = fromString("hashCode");
262 compareTo = fromString("compareTo");
263 getDeclaringClass = fromString("getDeclaringClass");
264 ex = fromString("ex");
265 finalize = fromString("finalize");
266 }
268 protected Name.Table createTable(Options options) {
269 boolean useUnsharedTable = options.get("useUnsharedTable") != null;
270 if (useUnsharedTable)
271 return new UnsharedNameTable(this);
272 else
273 return new SharedNameTable(this);
274 }
276 public void dispose() {
277 table.dispose();
278 }
280 public Name fromChars(char[] cs, int start, int len) {
281 return table.fromChars(cs, start, len);
282 }
284 public Name fromString(String s) {
285 return table.fromString(s);
286 }
288 public Name fromUtf(byte[] cs) {
289 return table.fromUtf(cs);
290 }
292 public Name fromUtf(byte[] cs, int start, int len) {
293 return table.fromUtf(cs, start, len);
294 }
295 }