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