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