langtools/src/share/classes/com/sun/tools/javac/util/Names.java
changeset 1260 a772ba9ba43d
child 1264 076a3cde30d5
equal deleted inserted replaced
1259:61142e0aeb3f 1260:a772ba9ba43d
       
     1 /*
       
     2  * Copyright 1999-2006 Sun Microsystems, Inc.  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.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 package 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 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 {
       
    38 
       
    39     public static final Context.Key<Names> namesKey = new Context.Key<Names>();
       
    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     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 package_info;
       
    77     public final Name ConstantValue;
       
    78     public final Name LineNumberTable;
       
    79     public final Name LocalVariableTable;
       
    80     public final Name LocalVariableTypeTable;
       
    81     public final Name CharacterRangeTable;
       
    82     public final Name StackMap;
       
    83     public final Name StackMapTable;
       
    84     public final Name SourceID;
       
    85     public final Name CompilationID;
       
    86     public final Name Code;
       
    87     public final Name Exceptions;
       
    88     public final Name SourceFile;
       
    89     public final Name InnerClasses;
       
    90     public final Name Synthetic;
       
    91     public final Name Bridge;
       
    92     public final Name Deprecated;
       
    93     public final Name Enum;
       
    94     public final Name _name;
       
    95     public final Name Signature;
       
    96     public final Name Varargs;
       
    97     public final Name Annotation;
       
    98     public final Name RuntimeVisibleAnnotations;
       
    99     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 }