Names.java revision 2841:edf685b5d413
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 26package 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 */ 37public 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 181 public final Name.Table table; 182 183 public Names(Context context) { 184 Options options = Options.instance(context); 185 table = createTable(options); 186 187 // operators and punctuation 188 asterisk = fromString("*"); 189 comma = fromString(","); 190 empty = fromString(""); 191 hyphen = fromString("-"); 192 one = fromString("1"); 193 period = fromString("."); 194 semicolon = fromString(";"); 195 slash = fromString("/"); 196 slashequals = fromString("/="); 197 198 // keywords 199 _class = fromString("class"); 200 _default = fromString("default"); 201 _super = fromString("super"); 202 _this = fromString("this"); 203 204 // field and method names 205 _name = fromString("name"); 206 addSuppressed = fromString("addSuppressed"); 207 any = fromString("<any>"); 208 append = fromString("append"); 209 clinit = fromString("<clinit>"); 210 clone = fromString("clone"); 211 close = fromString("close"); 212 compareTo = fromString("compareTo"); 213 deserializeLambda = fromString("$deserializeLambda$"); 214 desiredAssertionStatus = fromString("desiredAssertionStatus"); 215 equals = fromString("equals"); 216 error = fromString("<error>"); 217 family = fromString("family"); 218 finalize = fromString("finalize"); 219 forName = fromString("forName"); 220 getClass = fromString("getClass"); 221 getClassLoader = fromString("getClassLoader"); 222 getComponentType = fromString("getComponentType"); 223 getDeclaringClass = fromString("getDeclaringClass"); 224 getMessage = fromString("getMessage"); 225 hasNext = fromString("hasNext"); 226 hashCode = fromString("hashCode"); 227 init = fromString("<init>"); 228 initCause = fromString("initCause"); 229 iterator = fromString("iterator"); 230 length = fromString("length"); 231 next = fromString("next"); 232 ordinal = fromString("ordinal"); 233 serialVersionUID = fromString("serialVersionUID"); 234 toString = fromString("toString"); 235 value = fromString("value"); 236 valueOf = fromString("valueOf"); 237 values = fromString("values"); 238 239 // class names 240 java_io_Serializable = fromString("java.io.Serializable"); 241 java_lang_AutoCloseable = fromString("java.lang.AutoCloseable"); 242 java_lang_Class = fromString("java.lang.Class"); 243 java_lang_Cloneable = fromString("java.lang.Cloneable"); 244 java_lang_Enum = fromString("java.lang.Enum"); 245 java_lang_Object = fromString("java.lang.Object"); 246 java_lang_invoke_MethodHandle = fromString("java.lang.invoke.MethodHandle"); 247 248 // names of builtin classes 249 Array = fromString("Array"); 250 Bound = fromString("Bound"); 251 Method = fromString("Method"); 252 253 // package names 254 java_lang = fromString("java.lang"); 255 256 // attribute names 257 Annotation = fromString("Annotation"); 258 AnnotationDefault = fromString("AnnotationDefault"); 259 BootstrapMethods = fromString("BootstrapMethods"); 260 Bridge = fromString("Bridge"); 261 CharacterRangeTable = fromString("CharacterRangeTable"); 262 Code = fromString("Code"); 263 CompilationID = fromString("CompilationID"); 264 ConstantValue = fromString("ConstantValue"); 265 Deprecated = fromString("Deprecated"); 266 EnclosingMethod = fromString("EnclosingMethod"); 267 Enum = fromString("Enum"); 268 Exceptions = fromString("Exceptions"); 269 InnerClasses = fromString("InnerClasses"); 270 LineNumberTable = fromString("LineNumberTable"); 271 LocalVariableTable = fromString("LocalVariableTable"); 272 LocalVariableTypeTable = fromString("LocalVariableTypeTable"); 273 MethodParameters = fromString("MethodParameters"); 274 RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations"); 275 RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations"); 276 RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations"); 277 RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations"); 278 RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations"); 279 RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations"); 280 Signature = fromString("Signature"); 281 SourceFile = fromString("SourceFile"); 282 SourceID = fromString("SourceID"); 283 StackMap = fromString("StackMap"); 284 StackMapTable = fromString("StackMapTable"); 285 Synthetic = fromString("Synthetic"); 286 Value = fromString("Value"); 287 Varargs = fromString("Varargs"); 288 289 // members of java.lang.annotation.ElementType 290 ANNOTATION_TYPE = fromString("ANNOTATION_TYPE"); 291 CONSTRUCTOR = fromString("CONSTRUCTOR"); 292 FIELD = fromString("FIELD"); 293 LOCAL_VARIABLE = fromString("LOCAL_VARIABLE"); 294 METHOD = fromString("METHOD"); 295 PACKAGE = fromString("PACKAGE"); 296 PARAMETER = fromString("PARAMETER"); 297 TYPE = fromString("TYPE"); 298 TYPE_PARAMETER = fromString("TYPE_PARAMETER"); 299 TYPE_USE = fromString("TYPE_USE"); 300 301 // members of java.lang.annotation.RetentionPolicy 302 CLASS = fromString("CLASS"); 303 RUNTIME = fromString("RUNTIME"); 304 SOURCE = fromString("SOURCE"); 305 306 // other identifiers 307 T = fromString("T"); 308 deprecated = fromString("deprecated"); 309 ex = fromString("ex"); 310 package_info = fromString("package-info"); 311 requireNonNull = fromString("requireNonNull"); 312 313 //lambda-related 314 lambda = fromString("lambda$"); 315 metafactory = fromString("metafactory"); 316 altMetafactory = fromString("altMetafactory"); 317 } 318 319 protected Name.Table createTable(Options options) { 320 boolean useUnsharedTable = options.isSet("useUnsharedTable"); 321 if (useUnsharedTable) 322 return UnsharedNameTable.create(this); 323 else 324 return SharedNameTable.create(this); 325 } 326 327 public void dispose() { 328 table.dispose(); 329 } 330 331 public Name fromChars(char[] cs, int start, int len) { 332 return table.fromChars(cs, start, len); 333 } 334 335 public Name fromString(String s) { 336 return table.fromString(s); 337 } 338 339 public Name fromUtf(byte[] cs) { 340 return table.fromUtf(cs); 341 } 342 343 public Name fromUtf(byte[] cs, int start, int len) { 344 return table.fromUtf(cs, start, len); 345 } 346} 347