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