Tue, 25 Sep 2012 13:06:58 -0700
7193657: provide internal ArrayUtils class to simplify common usage of arrays in javac
Reviewed-by: mcimadamore, jjg
Contributed-by: vicenterz@yahoo.es
1 /*
2 * Copyright (c) 1999, 2012, 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 supported API.
33 * If 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 // operators and punctuation
51 public final Name asterisk;
52 public final Name comma;
53 public final Name empty;
54 public final Name hyphen;
55 public final Name one;
56 public final Name period;
57 public final Name semicolon;
58 public final Name slash;
59 public final Name slashequals;
61 // keywords
62 public final Name _class;
63 public final Name _default;
64 public final Name _super;
65 public final Name _this;
67 // field and method names
68 public final Name _name;
69 public final Name addSuppressed;
70 public final Name any;
71 public final Name append;
72 public final Name clinit;
73 public final Name clone;
74 public final Name close;
75 public final Name compareTo;
76 public final Name desiredAssertionStatus;
77 public final Name equals;
78 public final Name error;
79 public final Name family;
80 public final Name finalize;
81 public final Name forName;
82 public final Name getClass;
83 public final Name getClassLoader;
84 public final Name getComponentType;
85 public final Name getDeclaringClass;
86 public final Name getMessage;
87 public final Name hasNext;
88 public final Name hashCode;
89 public final Name init;
90 public final Name initCause;
91 public final Name iterator;
92 public final Name length;
93 public final Name next;
94 public final Name ordinal;
95 public final Name serialVersionUID;
96 public final Name toString;
97 public final Name value;
98 public final Name valueOf;
99 public final Name values;
101 // class names
102 public final Name java_io_Serializable;
103 public final Name java_lang_AutoCloseable;
104 public final Name java_lang_Class;
105 public final Name java_lang_Cloneable;
106 public final Name java_lang_Enum;
107 public final Name java_lang_Object;
108 public final Name java_lang_invoke_MethodHandle;
110 // names of builtin classes
111 public final Name Array;
112 public final Name Bound;
113 public final Name Method;
115 // package names
116 public final Name java_lang;
118 // attribute names
119 public final Name Annotation;
120 public final Name AnnotationDefault;
121 public final Name Bridge;
122 public final Name CharacterRangeTable;
123 public final Name Code;
124 public final Name CompilationID;
125 public final Name ConstantValue;
126 public final Name Deprecated;
127 public final Name EnclosingMethod;
128 public final Name Enum;
129 public final Name Exceptions;
130 public final Name InnerClasses;
131 public final Name LineNumberTable;
132 public final Name LocalVariableTable;
133 public final Name LocalVariableTypeTable;
134 public final Name RuntimeInvisibleAnnotations;
135 public final Name RuntimeInvisibleParameterAnnotations;
136 public final Name RuntimeInvisibleTypeAnnotations;
137 public final Name RuntimeVisibleAnnotations;
138 public final Name RuntimeVisibleParameterAnnotations;
139 public final Name RuntimeVisibleTypeAnnotations;
140 public final Name Signature;
141 public final Name SourceFile;
142 public final Name SourceID;
143 public final Name StackMap;
144 public final Name StackMapTable;
145 public final Name Synthetic;
146 public final Name Value;
147 public final Name Varargs;
149 // members of java.lang.annotation.ElementType
150 public final Name ANNOTATION_TYPE;
151 public final Name CONSTRUCTOR;
152 public final Name FIELD;
153 public final Name LOCAL_VARIABLE;
154 public final Name METHOD;
155 public final Name PACKAGE;
156 public final Name PARAMETER;
157 public final Name TYPE;
158 public final Name TYPE_PARAMETER;
159 public final Name TYPE_USE;
161 // members of java.lang.annotation.RetentionPolicy
162 public final Name CLASS;
163 public final Name RUNTIME;
164 public final Name SOURCE;
166 // other identifiers
167 public final Name T;
168 public final Name deprecated;
169 public final Name ex;
170 public final Name package_info;
172 // lambda-related
173 public final Name BootstrapMethods;
175 public final Name.Table table;
177 public Names(Context context) {
178 Options options = Options.instance(context);
179 table = createTable(options);
181 // operators and punctuation
182 asterisk = fromString("*");
183 comma = fromString(",");
184 empty = fromString("");
185 hyphen = fromString("-");
186 one = fromString("1");
187 period = fromString(".");
188 semicolon = fromString(";");
189 slash = fromString("/");
190 slashequals = fromString("/=");
192 // keywords
193 _class = fromString("class");
194 _default = fromString("default");
195 _super = fromString("super");
196 _this = fromString("this");
198 // field and method names
199 _name = fromString("name");
200 addSuppressed = fromString("addSuppressed");
201 any = fromString("<any>");
202 append = fromString("append");
203 clinit = fromString("<clinit>");
204 clone = fromString("clone");
205 close = fromString("close");
206 compareTo = fromString("compareTo");
207 desiredAssertionStatus = fromString("desiredAssertionStatus");
208 equals = fromString("equals");
209 error = fromString("<error>");
210 family = fromString("family");
211 finalize = fromString("finalize");
212 forName = fromString("forName");
213 getClass = fromString("getClass");
214 getClassLoader = fromString("getClassLoader");
215 getComponentType = fromString("getComponentType");
216 getDeclaringClass = fromString("getDeclaringClass");
217 getMessage = fromString("getMessage");
218 hasNext = fromString("hasNext");
219 hashCode = fromString("hashCode");
220 init = fromString("<init>");
221 initCause = fromString("initCause");
222 iterator = fromString("iterator");
223 length = fromString("length");
224 next = fromString("next");
225 ordinal = fromString("ordinal");
226 serialVersionUID = fromString("serialVersionUID");
227 toString = fromString("toString");
228 value = fromString("value");
229 valueOf = fromString("valueOf");
230 values = fromString("values");
232 // class names
233 java_io_Serializable = fromString("java.io.Serializable");
234 java_lang_AutoCloseable = fromString("java.lang.AutoCloseable");
235 java_lang_Class = fromString("java.lang.Class");
236 java_lang_Cloneable = fromString("java.lang.Cloneable");
237 java_lang_Enum = fromString("java.lang.Enum");
238 java_lang_Object = fromString("java.lang.Object");
239 java_lang_invoke_MethodHandle = fromString("java.lang.invoke.MethodHandle");
241 // names of builtin classes
242 Array = fromString("Array");
243 Bound = fromString("Bound");
244 Method = fromString("Method");
246 // package names
247 java_lang = fromString("java.lang");
249 // attribute names
250 Annotation = fromString("Annotation");
251 AnnotationDefault = fromString("AnnotationDefault");
252 Bridge = fromString("Bridge");
253 CharacterRangeTable = fromString("CharacterRangeTable");
254 Code = fromString("Code");
255 CompilationID = fromString("CompilationID");
256 ConstantValue = fromString("ConstantValue");
257 Deprecated = fromString("Deprecated");
258 EnclosingMethod = fromString("EnclosingMethod");
259 Enum = fromString("Enum");
260 Exceptions = fromString("Exceptions");
261 InnerClasses = fromString("InnerClasses");
262 LineNumberTable = fromString("LineNumberTable");
263 LocalVariableTable = fromString("LocalVariableTable");
264 LocalVariableTypeTable = fromString("LocalVariableTypeTable");
265 RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations");
266 RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
267 RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations");
268 RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations");
269 RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations");
270 RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations");
271 Signature = fromString("Signature");
272 SourceFile = fromString("SourceFile");
273 SourceID = fromString("SourceID");
274 StackMap = fromString("StackMap");
275 StackMapTable = fromString("StackMapTable");
276 Synthetic = fromString("Synthetic");
277 Value = fromString("Value");
278 Varargs = fromString("Varargs");
280 // members of java.lang.annotation.ElementType
281 ANNOTATION_TYPE = fromString("ANNOTATION_TYPE");
282 CONSTRUCTOR = fromString("CONSTRUCTOR");
283 FIELD = fromString("FIELD");
284 LOCAL_VARIABLE = fromString("LOCAL_VARIABLE");
285 METHOD = fromString("METHOD");
286 PACKAGE = fromString("PACKAGE");
287 PARAMETER = fromString("PARAMETER");
288 TYPE = fromString("TYPE");
289 TYPE_PARAMETER = fromString("TYPE_PARAMETER");
290 TYPE_USE = fromString("TYPE_USE");
292 // members of java.lang.annotation.RetentionPolicy
293 CLASS = fromString("CLASS");
294 RUNTIME = fromString("RUNTIME");
295 SOURCE = fromString("SOURCE");
297 // other identifiers
298 T = fromString("T");
299 deprecated = fromString("deprecated");
300 ex = fromString("ex");
301 package_info = fromString("package-info");
303 //lambda-related
304 BootstrapMethods = fromString("BootstrapMethods");
305 }
307 protected Name.Table createTable(Options options) {
308 boolean useUnsharedTable = options.isSet("useUnsharedTable");
309 if (useUnsharedTable)
310 return new UnsharedNameTable(this);
311 else
312 return new SharedNameTable(this);
313 }
315 public void dispose() {
316 table.dispose();
317 }
319 public Name fromChars(char[] cs, int start, int len) {
320 return table.fromChars(cs, start, len);
321 }
323 public Name fromString(String s) {
324 return table.fromString(s);
325 }
327 public Name fromUtf(byte[] cs) {
328 return table.fromUtf(cs);
329 }
331 public Name fromUtf(byte[] cs, int start, int len) {
332 return table.fromUtf(cs, start, len);
333 }
334 }