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