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 import java.util.Set; 29 30 /** 31 * Access to the compiler's name table. STandard names are defined, 32 * as well as methods to create new names. 33 * 34 * <p><b>This is NOT part of any supported API. 35 * If you write code that depends on this, you do so at your own risk. 36 * This code and its internal interfaces are subject to change or 37 * deletion without notice.</b> 38 */ 39 public class Names { 40 41 public static final Context.Key<Names> namesKey = new Context.Key<>(); 42 43 public static Names instance(Context context) { 44 Names instance = context.get(namesKey); 45 if (instance == null) { 46 instance = new Names(context); 47 context.put(namesKey, instance); 48 } 49 return instance; 50 } 51 52 // operators and punctuation 53 public final Name asterisk; 54 public final Name comma; 55 public final Name empty; 56 public final Name hyphen; 57 public final Name one; 58 public final Name slash; 59 60 // keywords 61 public final Name _class; 62 public final Name _super; 63 public final Name _this; 64 public final Name var; 65 public final Name exports; 66 public final Name opens; 67 public final Name module; 68 public final Name provides; 69 public final Name requires; 70 public final Name to; 71 public final Name transitive; 72 public final Name uses; 73 public final Name open; 74 public final Name with; 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 error; 89 public final Name finalize; 90 public final Name forRemoval; 91 public final Name essentialAPI; 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 165 // members of java.lang.annotation.ElementType 166 public final Name ANNOTATION_TYPE; 167 public final Name CONSTRUCTOR; 168 public final Name FIELD; 169 public final Name LOCAL_VARIABLE; 170 public final Name METHOD; 171 public final Name MODULE; 172 public final Name PACKAGE; 173 public final Name PARAMETER; 174 public final Name TYPE; 175 public final Name TYPE_PARAMETER; 176 public final Name TYPE_USE; 177 public final Name RECORD_COMPONENT; 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.runtime.ObjectMethods 203 public final Name bootstrap; 204 205 public final Name record; 206 207 // serialization members, used by records too 208 public final Name serialPersistentFields; 209 public final Name writeObject; 210 public final Name writeReplace; 211 public final Name readObjectNoData; 212 213 public final Name.Table table; 214 215 public Names(Context context) { 216 Options options = Options.instance(context); 217 table = createTable(options); 218 219 // operators and punctuation 220 asterisk = fromString("*"); 221 comma = fromString(","); 222 empty = fromString(""); 223 hyphen = fromString("-"); 224 one = fromString("1"); 225 slash = fromString("/"); 226 227 // keywords 228 _class = fromString("class"); 229 _super = fromString("super"); 230 _this = fromString("this"); 231 var = fromString("var"); 232 exports = fromString("exports"); 233 opens = fromString("opens"); 234 module = fromString("module"); 235 provides = fromString("provides"); 236 requires = fromString("requires"); 237 to = fromString("to"); 238 transitive = fromString("transitive"); 239 uses = fromString("uses"); 240 open = fromString("open"); 241 with = fromString("with"); 242 yield = fromString("yield"); 243 244 // field and method names 245 _name = fromString("name"); 246 addSuppressed = fromString("addSuppressed"); 247 any = fromString("<any>"); 248 append = fromString("append"); 249 clinit = fromString("<clinit>"); 250 clone = fromString("clone"); 251 close = fromString("close"); 252 deserializeLambda = fromString("$deserializeLambda$"); 253 desiredAssertionStatus = fromString("desiredAssertionStatus"); 254 equals = fromString("equals"); 255 error = fromString("<error>"); 256 finalize = fromString("finalize"); 257 forRemoval = fromString("forRemoval"); 258 essentialAPI = fromString("essentialAPI"); 259 getClass = fromString("getClass"); 260 hasNext = fromString("hasNext"); 261 hashCode = fromString("hashCode"); 262 init = fromString("<init>"); 263 iterator = fromString("iterator"); 264 length = fromString("length"); 265 next = fromString("next"); 266 ordinal = fromString("ordinal"); 267 provider = fromString("provider"); 268 serialVersionUID = fromString("serialVersionUID"); 269 toString = fromString("toString"); 270 value = fromString("value"); 271 valueOf = fromString("valueOf"); 272 values = fromString("values"); 273 readResolve = fromString("readResolve"); 274 readObject = fromString("readObject"); 275 dollarThis = fromString("$this"); 276 277 // class names 278 java_io_Serializable = fromString("java.io.Serializable"); 279 java_lang_Class = fromString("java.lang.Class"); 280 java_lang_Cloneable = fromString("java.lang.Cloneable"); 281 java_lang_Enum = fromString("java.lang.Enum"); 282 java_lang_Object = fromString("java.lang.Object"); 283 284 // names of builtin classes 285 Array = fromString("Array"); 286 Bound = fromString("Bound"); 287 Method = fromString("Method"); 288 289 // package names 290 java_lang = fromString("java.lang"); 291 292 // module names 293 java_base = fromString("java.base"); 294 295 // attribute names 296 Annotation = fromString("Annotation"); 297 AnnotationDefault = fromString("AnnotationDefault"); 298 BootstrapMethods = fromString("BootstrapMethods"); 299 Bridge = fromString("Bridge"); 300 CharacterRangeTable = fromString("CharacterRangeTable"); 301 Code = fromString("Code"); 302 CompilationID = fromString("CompilationID"); 303 ConstantValue = fromString("ConstantValue"); 304 Deprecated = fromString("Deprecated"); 305 EnclosingMethod = fromString("EnclosingMethod"); 306 Enum = fromString("Enum"); 307 Exceptions = fromString("Exceptions"); 308 InnerClasses = fromString("InnerClasses"); 309 LineNumberTable = fromString("LineNumberTable"); 310 LocalVariableTable = fromString("LocalVariableTable"); 311 LocalVariableTypeTable = fromString("LocalVariableTypeTable"); 312 MethodParameters = fromString("MethodParameters"); 313 Module = fromString("Module"); 314 ModuleResolution = fromString("ModuleResolution"); 315 NestHost = fromString("NestHost"); 316 NestMembers = fromString("NestMembers"); 317 Record = fromString("Record"); 318 RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations"); 319 RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations"); 320 RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations"); 321 RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations"); 322 RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations"); 323 RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations"); 324 Signature = fromString("Signature"); 325 SourceFile = fromString("SourceFile"); 326 SourceID = fromString("SourceID"); 327 StackMap = fromString("StackMap"); 328 StackMapTable = fromString("StackMapTable"); 329 Synthetic = fromString("Synthetic"); 330 Value = fromString("Value"); 331 Varargs = fromString("Varargs"); 332 333 // members of java.lang.annotation.ElementType 334 ANNOTATION_TYPE = fromString("ANNOTATION_TYPE"); 335 CONSTRUCTOR = fromString("CONSTRUCTOR"); 336 FIELD = fromString("FIELD"); 337 LOCAL_VARIABLE = fromString("LOCAL_VARIABLE"); 338 METHOD = fromString("METHOD"); 339 MODULE = fromString("MODULE"); 340 PACKAGE = fromString("PACKAGE"); 341 PARAMETER = fromString("PARAMETER"); 342 TYPE = fromString("TYPE"); 343 TYPE_PARAMETER = fromString("TYPE_PARAMETER"); 344 TYPE_USE = fromString("TYPE_USE"); 345 RECORD_COMPONENT = fromString("RECORD_COMPONENT"); 346 347 // members of java.lang.annotation.RetentionPolicy 348 CLASS = fromString("CLASS"); 349 RUNTIME = fromString("RUNTIME"); 350 SOURCE = fromString("SOURCE"); 351 352 // other identifiers 353 T = fromString("T"); 354 ex = fromString("ex"); 355 module_info = fromString("module-info"); 356 package_info = fromString("package-info"); 357 requireNonNull = fromString("requireNonNull"); 358 359 //lambda-related 360 lambda = fromString("lambda$"); 361 metafactory = fromString("metafactory"); 362 altMetafactory = fromString("altMetafactory"); 363 364 // string concat 365 makeConcat = fromString("makeConcat"); 366 makeConcatWithConstants = fromString("makeConcatWithConstants"); 367 368 bootstrap = fromString("bootstrap"); 369 record = fromString("record"); 370 371 serialPersistentFields = fromString("serialPersistentFields"); 372 writeObject = fromString("writeObject"); 373 writeReplace = fromString("writeReplace"); 374 readObjectNoData = fromString("readObjectNoData"); 375 } 376 377 protected Name.Table createTable(Options options) { 378 boolean useUnsharedTable = options.isSet("useUnsharedTable"); 379 if (useUnsharedTable) 380 return UnsharedNameTable.create(this); 381 else 382 return SharedNameTable.create(this); 383 } 384 385 public void dispose() { 386 table.dispose(); 387 } 388 389 public Name fromChars(char[] cs, int start, int len) { 390 return table.fromChars(cs, start, len); 391 } 392 393 public Name fromString(String s) { 394 return table.fromString(s); 395 } 396 397 public Name fromUtf(byte[] cs) { 398 return table.fromUtf(cs); 399 } 400 401 public Name fromUtf(byte[] cs, int start, int len) { 402 return table.fromUtf(cs, start, len); 403 } 404 }