src/share/classes/com/sun/tools/javac/util/Names.java

Sat, 29 Dec 2012 17:33:17 -0800

author
jjg
date
Sat, 29 Dec 2012 17:33:17 -0800
changeset 1473
31780dd06ec7
parent 1380
a65971893c50
child 1587
f1f605f85850
permissions
-rw-r--r--

8004727: Add compiler support for parameter reflection
Reviewed-by: jjg
Contributed-by: eric.mccorkle@oracle.com

     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 BootstrapMethods;
   122     public final Name Bridge;
   123     public final Name CharacterRangeTable;
   124     public final Name Code;
   125     public final Name CompilationID;
   126     public final Name ConstantValue;
   127     public final Name Deprecated;
   128     public final Name EnclosingMethod;
   129     public final Name Enum;
   130     public final Name Exceptions;
   131     public final Name InnerClasses;
   132     public final Name LineNumberTable;
   133     public final Name LocalVariableTable;
   134     public final Name LocalVariableTypeTable;
   135     public final Name MethodParameters;
   136     public final Name RuntimeInvisibleAnnotations;
   137     public final Name RuntimeInvisibleParameterAnnotations;
   138     public final Name RuntimeInvisibleTypeAnnotations;
   139     public final Name RuntimeVisibleAnnotations;
   140     public final Name RuntimeVisibleParameterAnnotations;
   141     public final Name RuntimeVisibleTypeAnnotations;
   142     public final Name Signature;
   143     public final Name SourceFile;
   144     public final Name SourceID;
   145     public final Name StackMap;
   146     public final Name StackMapTable;
   147     public final Name Synthetic;
   148     public final Name Value;
   149     public final Name Varargs;
   151     // members of java.lang.annotation.ElementType
   152     public final Name ANNOTATION_TYPE;
   153     public final Name CONSTRUCTOR;
   154     public final Name FIELD;
   155     public final Name LOCAL_VARIABLE;
   156     public final Name METHOD;
   157     public final Name PACKAGE;
   158     public final Name PARAMETER;
   159     public final Name TYPE;
   160     public final Name TYPE_PARAMETER;
   161     public final Name TYPE_USE;
   163     // members of java.lang.annotation.RetentionPolicy
   164     public final Name CLASS;
   165     public final Name RUNTIME;
   166     public final Name SOURCE;
   168     // other identifiers
   169     public final Name T;
   170     public final Name deprecated;
   171     public final Name ex;
   172     public final Name package_info;
   174     //lambda-related
   175     public final Name lambda;
   176     public final Name metaFactory;
   178     public final Name.Table table;
   180     public Names(Context context) {
   181         Options options = Options.instance(context);
   182         table = createTable(options);
   184         // operators and punctuation
   185         asterisk = fromString("*");
   186         comma = fromString(",");
   187         empty = fromString("");
   188         hyphen = fromString("-");
   189         one = fromString("1");
   190         period = fromString(".");
   191         semicolon = fromString(";");
   192         slash = fromString("/");
   193         slashequals = fromString("/=");
   195         // keywords
   196         _class = fromString("class");
   197         _default = fromString("default");
   198         _super = fromString("super");
   199         _this = fromString("this");
   201         // field and method names
   202         _name = fromString("name");
   203         addSuppressed = fromString("addSuppressed");
   204         any = fromString("<any>");
   205         append = fromString("append");
   206         clinit = fromString("<clinit>");
   207         clone = fromString("clone");
   208         close = fromString("close");
   209         compareTo = fromString("compareTo");
   210         desiredAssertionStatus = fromString("desiredAssertionStatus");
   211         equals = fromString("equals");
   212         error = fromString("<error>");
   213         family = fromString("family");
   214         finalize = fromString("finalize");
   215         forName = fromString("forName");
   216         getClass = fromString("getClass");
   217         getClassLoader = fromString("getClassLoader");
   218         getComponentType = fromString("getComponentType");
   219         getDeclaringClass = fromString("getDeclaringClass");
   220         getMessage = fromString("getMessage");
   221         hasNext = fromString("hasNext");
   222         hashCode = fromString("hashCode");
   223         init = fromString("<init>");
   224         initCause = fromString("initCause");
   225         iterator = fromString("iterator");
   226         length = fromString("length");
   227         next = fromString("next");
   228         ordinal = fromString("ordinal");
   229         serialVersionUID = fromString("serialVersionUID");
   230         toString = fromString("toString");
   231         value = fromString("value");
   232         valueOf = fromString("valueOf");
   233         values = fromString("values");
   235         // class names
   236         java_io_Serializable = fromString("java.io.Serializable");
   237         java_lang_AutoCloseable = fromString("java.lang.AutoCloseable");
   238         java_lang_Class = fromString("java.lang.Class");
   239         java_lang_Cloneable = fromString("java.lang.Cloneable");
   240         java_lang_Enum = fromString("java.lang.Enum");
   241         java_lang_Object = fromString("java.lang.Object");
   242         java_lang_invoke_MethodHandle = fromString("java.lang.invoke.MethodHandle");
   244         // names of builtin classes
   245         Array = fromString("Array");
   246         Bound = fromString("Bound");
   247         Method = fromString("Method");
   249         // package names
   250         java_lang = fromString("java.lang");
   252         // attribute names
   253         Annotation = fromString("Annotation");
   254         AnnotationDefault = fromString("AnnotationDefault");
   255         BootstrapMethods = fromString("BootstrapMethods");
   256         Bridge = fromString("Bridge");
   257         CharacterRangeTable = fromString("CharacterRangeTable");
   258         Code = fromString("Code");
   259         CompilationID = fromString("CompilationID");
   260         ConstantValue = fromString("ConstantValue");
   261         Deprecated = fromString("Deprecated");
   262         EnclosingMethod = fromString("EnclosingMethod");
   263         Enum = fromString("Enum");
   264         Exceptions = fromString("Exceptions");
   265         InnerClasses = fromString("InnerClasses");
   266         LineNumberTable = fromString("LineNumberTable");
   267         LocalVariableTable = fromString("LocalVariableTable");
   268         LocalVariableTypeTable = fromString("LocalVariableTypeTable");
   269         MethodParameters = fromString("MethodParameters");
   270         RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations");
   271         RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
   272         RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations");
   273         RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations");
   274         RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations");
   275         RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations");
   276         Signature = fromString("Signature");
   277         SourceFile = fromString("SourceFile");
   278         SourceID = fromString("SourceID");
   279         StackMap = fromString("StackMap");
   280         StackMapTable = fromString("StackMapTable");
   281         Synthetic = fromString("Synthetic");
   282         Value = fromString("Value");
   283         Varargs = fromString("Varargs");
   285         // members of java.lang.annotation.ElementType
   286         ANNOTATION_TYPE = fromString("ANNOTATION_TYPE");
   287         CONSTRUCTOR = fromString("CONSTRUCTOR");
   288         FIELD = fromString("FIELD");
   289         LOCAL_VARIABLE = fromString("LOCAL_VARIABLE");
   290         METHOD = fromString("METHOD");
   291         PACKAGE = fromString("PACKAGE");
   292         PARAMETER = fromString("PARAMETER");
   293         TYPE = fromString("TYPE");
   294         TYPE_PARAMETER = fromString("TYPE_PARAMETER");
   295         TYPE_USE = fromString("TYPE_USE");
   297         // members of java.lang.annotation.RetentionPolicy
   298         CLASS = fromString("CLASS");
   299         RUNTIME = fromString("RUNTIME");
   300         SOURCE = fromString("SOURCE");
   302         // other identifiers
   303         T = fromString("T");
   304         deprecated = fromString("deprecated");
   305         ex = fromString("ex");
   306         package_info = fromString("package-info");
   308         //lambda-related
   309         lambda = fromString("lambda");
   310         metaFactory = fromString("metaFactory");
   311     }
   313     protected Name.Table createTable(Options options) {
   314         boolean useUnsharedTable = options.isSet("useUnsharedTable");
   315         if (useUnsharedTable)
   316             return new UnsharedNameTable(this);
   317         else
   318             return new SharedNameTable(this);
   319     }
   321     public void dispose() {
   322         table.dispose();
   323     }
   325     public Name fromChars(char[] cs, int start, int len) {
   326         return table.fromChars(cs, start, len);
   327     }
   329     public Name fromString(String s) {
   330         return table.fromString(s);
   331     }
   333     public Name fromUtf(byte[] cs) {
   334         return table.fromUtf(cs);
   335     }
   337     public Name fromUtf(byte[] cs, int start, int len) {
   338         return table.fromUtf(cs, start, len);
   339     }
   340 }

mercurial