Names.java revision 3231:50467a1cf5b1
1/*
2 * Copyright (c) 1999, 2013, 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 */
25
26package com.sun.tools.javac.util;
27
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 */
37public class Names {
38
39    public static final Context.Key<Names> namesKey = new Context.Key<>();
40
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    }
49
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;
60
61    // keywords
62    public final Name _class;
63    public final Name _default;
64    public final Name _super;
65    public final Name _this;
66
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 deserializeLambda;
77    public final Name desiredAssertionStatus;
78    public final Name equals;
79    public final Name error;
80    public final Name family;
81    public final Name finalize;
82    public final Name forName;
83    public final Name getClass;
84    public final Name getClassLoader;
85    public final Name getComponentType;
86    public final Name getDeclaringClass;
87    public final Name getMessage;
88    public final Name hasNext;
89    public final Name hashCode;
90    public final Name init;
91    public final Name initCause;
92    public final Name iterator;
93    public final Name length;
94    public final Name next;
95    public final Name ordinal;
96    public final Name serialVersionUID;
97    public final Name toString;
98    public final Name value;
99    public final Name valueOf;
100    public final Name values;
101
102    // class names
103    public final Name java_io_Serializable;
104    public final Name java_lang_AutoCloseable;
105    public final Name java_lang_Class;
106    public final Name java_lang_Cloneable;
107    public final Name java_lang_Enum;
108    public final Name java_lang_Object;
109    public final Name java_lang_invoke_MethodHandle;
110
111    // names of builtin classes
112    public final Name Array;
113    public final Name Bound;
114    public final Name Method;
115
116    // package names
117    public final Name java_lang;
118
119    // attribute names
120    public final Name Annotation;
121    public final Name AnnotationDefault;
122    public final Name BootstrapMethods;
123    public final Name Bridge;
124    public final Name CharacterRangeTable;
125    public final Name Code;
126    public final Name CompilationID;
127    public final Name ConstantValue;
128    public final Name Deprecated;
129    public final Name EnclosingMethod;
130    public final Name Enum;
131    public final Name Exceptions;
132    public final Name InnerClasses;
133    public final Name LineNumberTable;
134    public final Name LocalVariableTable;
135    public final Name LocalVariableTypeTable;
136    public final Name MethodParameters;
137    public final Name RuntimeInvisibleAnnotations;
138    public final Name RuntimeInvisibleParameterAnnotations;
139    public final Name RuntimeInvisibleTypeAnnotations;
140    public final Name RuntimeVisibleAnnotations;
141    public final Name RuntimeVisibleParameterAnnotations;
142    public final Name RuntimeVisibleTypeAnnotations;
143    public final Name Signature;
144    public final Name SourceFile;
145    public final Name SourceID;
146    public final Name StackMap;
147    public final Name StackMapTable;
148    public final Name Synthetic;
149    public final Name Value;
150    public final Name Varargs;
151
152    // members of java.lang.annotation.ElementType
153    public final Name ANNOTATION_TYPE;
154    public final Name CONSTRUCTOR;
155    public final Name FIELD;
156    public final Name LOCAL_VARIABLE;
157    public final Name METHOD;
158    public final Name PACKAGE;
159    public final Name PARAMETER;
160    public final Name TYPE;
161    public final Name TYPE_PARAMETER;
162    public final Name TYPE_USE;
163
164    // members of java.lang.annotation.RetentionPolicy
165    public final Name CLASS;
166    public final Name RUNTIME;
167    public final Name SOURCE;
168
169    // other identifiers
170    public final Name T;
171    public final Name deprecated;
172    public final Name ex;
173    public final Name package_info;
174    public final Name requireNonNull;
175
176    //lambda-related
177    public final Name lambda;
178    public final Name metafactory;
179    public final Name altMetafactory;
180    public final Name dollarThis;
181
182    // string concat
183    public final Name makeConcat;
184    public final Name makeConcatWithConstants;
185
186    public final Name.Table table;
187
188    public Names(Context context) {
189        Options options = Options.instance(context);
190        table = createTable(options);
191
192        // operators and punctuation
193        asterisk = fromString("*");
194        comma = fromString(",");
195        empty = fromString("");
196        hyphen = fromString("-");
197        one = fromString("1");
198        period = fromString(".");
199        semicolon = fromString(";");
200        slash = fromString("/");
201        slashequals = fromString("/=");
202
203        // keywords
204        _class = fromString("class");
205        _default = fromString("default");
206        _super = fromString("super");
207        _this = fromString("this");
208
209        // field and method names
210        _name = fromString("name");
211        addSuppressed = fromString("addSuppressed");
212        any = fromString("<any>");
213        append = fromString("append");
214        clinit = fromString("<clinit>");
215        clone = fromString("clone");
216        close = fromString("close");
217        compareTo = fromString("compareTo");
218        deserializeLambda = fromString("$deserializeLambda$");
219        desiredAssertionStatus = fromString("desiredAssertionStatus");
220        equals = fromString("equals");
221        error = fromString("<error>");
222        family = fromString("family");
223        finalize = fromString("finalize");
224        forName = fromString("forName");
225        getClass = fromString("getClass");
226        getClassLoader = fromString("getClassLoader");
227        getComponentType = fromString("getComponentType");
228        getDeclaringClass = fromString("getDeclaringClass");
229        getMessage = fromString("getMessage");
230        hasNext = fromString("hasNext");
231        hashCode = fromString("hashCode");
232        init = fromString("<init>");
233        initCause = fromString("initCause");
234        iterator = fromString("iterator");
235        length = fromString("length");
236        next = fromString("next");
237        ordinal = fromString("ordinal");
238        serialVersionUID = fromString("serialVersionUID");
239        toString = fromString("toString");
240        value = fromString("value");
241        valueOf = fromString("valueOf");
242        values = fromString("values");
243        dollarThis = fromString("$this");
244
245        // class names
246        java_io_Serializable = fromString("java.io.Serializable");
247        java_lang_AutoCloseable = fromString("java.lang.AutoCloseable");
248        java_lang_Class = fromString("java.lang.Class");
249        java_lang_Cloneable = fromString("java.lang.Cloneable");
250        java_lang_Enum = fromString("java.lang.Enum");
251        java_lang_Object = fromString("java.lang.Object");
252        java_lang_invoke_MethodHandle = fromString("java.lang.invoke.MethodHandle");
253
254        // names of builtin classes
255        Array = fromString("Array");
256        Bound = fromString("Bound");
257        Method = fromString("Method");
258
259        // package names
260        java_lang = fromString("java.lang");
261
262        // attribute names
263        Annotation = fromString("Annotation");
264        AnnotationDefault = fromString("AnnotationDefault");
265        BootstrapMethods = fromString("BootstrapMethods");
266        Bridge = fromString("Bridge");
267        CharacterRangeTable = fromString("CharacterRangeTable");
268        Code = fromString("Code");
269        CompilationID = fromString("CompilationID");
270        ConstantValue = fromString("ConstantValue");
271        Deprecated = fromString("Deprecated");
272        EnclosingMethod = fromString("EnclosingMethod");
273        Enum = fromString("Enum");
274        Exceptions = fromString("Exceptions");
275        InnerClasses = fromString("InnerClasses");
276        LineNumberTable = fromString("LineNumberTable");
277        LocalVariableTable = fromString("LocalVariableTable");
278        LocalVariableTypeTable = fromString("LocalVariableTypeTable");
279        MethodParameters = fromString("MethodParameters");
280        RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations");
281        RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
282        RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations");
283        RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations");
284        RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations");
285        RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations");
286        Signature = fromString("Signature");
287        SourceFile = fromString("SourceFile");
288        SourceID = fromString("SourceID");
289        StackMap = fromString("StackMap");
290        StackMapTable = fromString("StackMapTable");
291        Synthetic = fromString("Synthetic");
292        Value = fromString("Value");
293        Varargs = fromString("Varargs");
294
295        // members of java.lang.annotation.ElementType
296        ANNOTATION_TYPE = fromString("ANNOTATION_TYPE");
297        CONSTRUCTOR = fromString("CONSTRUCTOR");
298        FIELD = fromString("FIELD");
299        LOCAL_VARIABLE = fromString("LOCAL_VARIABLE");
300        METHOD = fromString("METHOD");
301        PACKAGE = fromString("PACKAGE");
302        PARAMETER = fromString("PARAMETER");
303        TYPE = fromString("TYPE");
304        TYPE_PARAMETER = fromString("TYPE_PARAMETER");
305        TYPE_USE = fromString("TYPE_USE");
306
307        // members of java.lang.annotation.RetentionPolicy
308        CLASS = fromString("CLASS");
309        RUNTIME = fromString("RUNTIME");
310        SOURCE = fromString("SOURCE");
311
312        // other identifiers
313        T = fromString("T");
314        deprecated = fromString("deprecated");
315        ex = fromString("ex");
316        package_info = fromString("package-info");
317        requireNonNull = fromString("requireNonNull");
318
319        //lambda-related
320        lambda = fromString("lambda$");
321        metafactory = fromString("metafactory");
322        altMetafactory = fromString("altMetafactory");
323
324        // string concat
325        makeConcat = fromString("makeConcat");
326        makeConcatWithConstants = fromString("makeConcatWithConstants");
327    }
328
329    protected Name.Table createTable(Options options) {
330        boolean useUnsharedTable = options.isSet("useUnsharedTable");
331        if (useUnsharedTable)
332            return UnsharedNameTable.create(this);
333        else
334            return SharedNameTable.create(this);
335    }
336
337    public void dispose() {
338        table.dispose();
339    }
340
341    public Name fromChars(char[] cs, int start, int len) {
342        return table.fromChars(cs, start, len);
343    }
344
345    public Name fromString(String s) {
346        return table.fromString(s);
347    }
348
349    public Name fromUtf(byte[] cs) {
350        return table.fromUtf(cs);
351    }
352
353    public Name fromUtf(byte[] cs, int start, int len) {
354        return table.fromUtf(cs, start, len);
355    }
356}
357