001    /*
002     * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
003     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004     *
005     * This code is free software; you can redistribute it and/or modify it
006     * under the terms of the GNU General Public License version 2 only, as
007     * published by the Free Software Foundation.  Sun designates this
008     * particular file as subject to the "Classpath" exception as provided
009     * by Sun in the LICENSE file that accompanied this code.
010     *
011     * This code is distributed in the hope that it will be useful, but WITHOUT
012     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014     * version 2 for more details (a copy is included in the LICENSE file that
015     * accompanied this code).
016     *
017     * You should have received a copy of the GNU General Public License version
018     * 2 along with this work; if not, write to the Free Software Foundation,
019     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020     *
021     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022     * CA 95054 USA or visit www.sun.com if you need additional information or
023     * have any questions.
024     */
025    
026    package com.sun.tools.javac.util;
027    
028    /**
029     * Access to the compiler's name table.  STandard names are defined,
030     * as well as methods to create new names.
031     *
032     *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
033     *  you write code that depends on this, you do so at your own risk.
034     *  This code and its internal interfaces are subject to change or
035     *  deletion without notice.</b>
036     */
037    public class Names {
038    
039        public static final Context.Key<Names> namesKey = new Context.Key<Names>();
040    
041        public static Names instance(Context context) {
042            Names instance = context.get(namesKey);
043            if (instance == null) {
044                instance = new Names(context);
045                context.put(namesKey, instance);
046            }
047            return instance;
048        }
049    
050        public final Name slash;
051        public final Name hyphen;
052        public final Name T;
053        public final Name slashequals;
054        public final Name deprecated;
055        public final Name init;
056        public final Name clinit;
057        public final Name error;
058        public final Name any;
059        public final Name empty;
060        public final Name one;
061        public final Name period;
062        public final Name comma;
063        public final Name semicolon;
064        public final Name asterisk;
065        public final Name _this;
066        public final Name _super;
067        public final Name _default;
068        public final Name _class;
069        public final Name java_lang;
070        public final Name java_lang_Object;
071        public final Name java_lang_Class;
072        public final Name java_lang_Cloneable;
073        public final Name java_io_Serializable;
074        public final Name serialVersionUID;
075        public final Name java_lang_Enum;
076        public final Name package_info;
077        public final Name ConstantValue;
078        public final Name LineNumberTable;
079        public final Name LocalVariableTable;
080        public final Name LocalVariableTypeTable;
081        public final Name CharacterRangeTable;
082        public final Name StackMap;
083        public final Name StackMapTable;
084        public final Name SourceID;
085        public final Name CompilationID;
086        public final Name Code;
087        public final Name Exceptions;
088        public final Name SourceFile;
089        public final Name InnerClasses;
090        public final Name Synthetic;
091        public final Name Bridge;
092        public final Name Deprecated;
093        public final Name Enum;
094        public final Name _name;
095        public final Name Signature;
096        public final Name Varargs;
097        public final Name Annotation;
098        public final Name RuntimeVisibleAnnotations;
099        public final Name RuntimeInvisibleAnnotations;
100        public final Name RuntimeVisibleParameterAnnotations;
101        public final Name RuntimeInvisibleParameterAnnotations;
102        public final Name Value;
103        public final Name EnclosingMethod;
104        public final Name desiredAssertionStatus;
105        public final Name append;
106        public final Name family;
107        public final Name forName;
108        public final Name toString;
109        public final Name length;
110        public final Name valueOf;
111        public final Name value;
112        public final Name getMessage;
113        public final Name getClass;
114        public final Name TYPE;
115        public final Name FIELD;
116        public final Name METHOD;
117        public final Name PARAMETER;
118        public final Name CONSTRUCTOR;
119        public final Name LOCAL_VARIABLE;
120        public final Name ANNOTATION_TYPE;
121        public final Name PACKAGE;
122        public final Name SOURCE;
123        public final Name CLASS;
124        public final Name RUNTIME;
125        public final Name Array;
126        public final Name Method;
127        public final Name Bound;
128        public final Name clone;
129        public final Name getComponentType;
130        public final Name getClassLoader;
131        public final Name initCause;
132        public final Name values;
133        public final Name iterator;
134        public final Name hasNext;
135        public final Name next;
136        public final Name AnnotationDefault;
137        public final Name ordinal;
138        public final Name equals;
139        public final Name hashCode;
140        public final Name compareTo;
141        public final Name getDeclaringClass;
142        public final Name ex;
143        public final Name finalize;
144    
145        public final Name.Table table;
146    
147        public Names(Context context) {
148            Options options = Options.instance(context);
149            table = createTable(options);
150    
151            slash = fromString("/");
152            hyphen = fromString("-");
153            T = fromString("T");
154            slashequals = fromString("/=");
155            deprecated = fromString("deprecated");
156    
157            init = fromString("<init>");
158            clinit = fromString("<clinit>");
159            error = fromString("<error>");
160            any = fromString("<any>");
161            empty = fromString("");
162            one = fromString("1");
163            period = fromString(".");
164            comma = fromString(",");
165            semicolon = fromString(";");
166            asterisk = fromString("*");
167            _this = fromString("this");
168            _super = fromString("super");
169            _default = fromString("default");
170    
171            _class = fromString("class");
172            java_lang = fromString("java.lang");
173            java_lang_Object = fromString("java.lang.Object");
174            java_lang_Class = fromString("java.lang.Class");
175            java_lang_Cloneable = fromString("java.lang.Cloneable");
176            java_io_Serializable = fromString("java.io.Serializable");
177            java_lang_Enum = fromString("java.lang.Enum");
178            package_info = fromString("package-info");
179            serialVersionUID = fromString("serialVersionUID");
180            ConstantValue = fromString("ConstantValue");
181            LineNumberTable = fromString("LineNumberTable");
182            LocalVariableTable = fromString("LocalVariableTable");
183            LocalVariableTypeTable = fromString("LocalVariableTypeTable");
184            CharacterRangeTable = fromString("CharacterRangeTable");
185            StackMap = fromString("StackMap");
186            StackMapTable = fromString("StackMapTable");
187            SourceID = fromString("SourceID");
188            CompilationID = fromString("CompilationID");
189            Code = fromString("Code");
190            Exceptions = fromString("Exceptions");
191            SourceFile = fromString("SourceFile");
192            InnerClasses = fromString("InnerClasses");
193            Synthetic = fromString("Synthetic");
194            Bridge = fromString("Bridge");
195            Deprecated = fromString("Deprecated");
196            Enum = fromString("Enum");
197            _name = fromString("name");
198            Signature = fromString("Signature");
199            Varargs = fromString("Varargs");
200            Annotation = fromString("Annotation");
201            RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations");
202            RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations");
203            RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations");
204            RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
205            Value = fromString("Value");
206            EnclosingMethod = fromString("EnclosingMethod");
207    
208            desiredAssertionStatus = fromString("desiredAssertionStatus");
209    
210            append = fromString("append");
211            family = fromString("family");
212            forName = fromString("forName");
213            toString = fromString("toString");
214            length = fromString("length");
215            valueOf = fromString("valueOf");
216            value = fromString("value");
217            getMessage = fromString("getMessage");
218            getClass = fromString("getClass");
219    
220            TYPE = fromString("TYPE");
221            FIELD = fromString("FIELD");
222            METHOD = fromString("METHOD");
223            PARAMETER = fromString("PARAMETER");
224            CONSTRUCTOR = fromString("CONSTRUCTOR");
225            LOCAL_VARIABLE = fromString("LOCAL_VARIABLE");
226            ANNOTATION_TYPE = fromString("ANNOTATION_TYPE");
227            PACKAGE = fromString("PACKAGE");
228    
229            SOURCE = fromString("SOURCE");
230            CLASS = fromString("CLASS");
231            RUNTIME = fromString("RUNTIME");
232    
233            Array = fromString("Array");
234            Method = fromString("Method");
235            Bound = fromString("Bound");
236            clone = fromString("clone");
237            getComponentType = fromString("getComponentType");
238            getClassLoader = fromString("getClassLoader");
239            initCause = fromString("initCause");
240            values = fromString("values");
241            iterator = fromString("iterator");
242            hasNext = fromString("hasNext");
243            next = fromString("next");
244            AnnotationDefault = fromString("AnnotationDefault");
245            ordinal = fromString("ordinal");
246            equals = fromString("equals");
247            hashCode = fromString("hashCode");
248            compareTo = fromString("compareTo");
249            getDeclaringClass = fromString("getDeclaringClass");
250            ex = fromString("ex");
251            finalize = fromString("finalize");
252        }
253    
254        protected Name.Table createTable(Options options) {
255            boolean useUnsharedTable = options.get("useUnsharedTable") != null;
256            if (useUnsharedTable)
257                return new UnsharedNameTable(this);
258            else
259                return new SharedNameTable(this);
260        }
261    
262        public void dispose() {
263            table.dispose();
264        }
265    
266        public Name fromChars(char[] cs, int start, int len) {
267            return table.fromChars(cs, start, len);
268        }
269    
270        public Name fromString(String s) {
271            return table.fromString(s);
272        }
273    
274        public Name fromUtf(byte[] cs) {
275            return table.fromUtf(cs);
276        }
277    
278        public Name fromUtf(byte[] cs, int start, int len) {
279            return table.fromUtf(cs, start, len);
280        }
281    }