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