1 /* 2 * Copyright (c) 1999, 2008, 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<Names>(); 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 public final Name slash; 51 public final Name hyphen; 52 public final Name T; 53 public final Name slashequals; 54 public final Name deprecated; 55 public final Name init; 56 public final Name clinit; 57 public final Name error; 58 public final Name any; 59 public final Name empty; 60 public final Name one; 61 public final Name period; 62 public final Name comma; 63 public final Name semicolon; 64 public final Name asterisk; 65 public final Name _this; 66 public final Name _super; 67 public final Name _default; 68 public final Name _class; 69 public final Name java_lang; 70 public final Name java_lang_Object; 71 public final Name java_lang_Class; 72 public final Name java_lang_Cloneable; 73 public final Name java_io_Serializable; 74 public final Name serialVersionUID; 75 public final Name java_lang_Enum; 76 public final Name java_dyn_MethodHandle; 77 public final Name java_dyn_InvokeDynamic; 78 public final Name package_info; 79 public final Name ConstantValue; 80 public final Name LineNumberTable; 81 public final Name LocalVariableTable; 82 public final Name LocalVariableTypeTable; 83 public final Name CharacterRangeTable; 84 public final Name StackMap; 85 public final Name StackMapTable; 86 public final Name SourceID; 87 public final Name CompilationID; 88 public final Name Code; 89 public final Name Exceptions; 90 public final Name SourceFile; 91 public final Name InnerClasses; 92 public final Name Synthetic; 93 public final Name Bridge; 94 public final Name Deprecated; 95 public final Name Enum; 96 public final Name _name; 97 public final Name Signature; 98 public final Name Varargs; 99 public final Name Annotation; 100 public final Name RuntimeVisibleAnnotations; 101 public final Name RuntimeInvisibleAnnotations; 102 public final Name RuntimeVisibleTypeAnnotations; 103 public final Name RuntimeInvisibleTypeAnnotations; 104 public final Name RuntimeVisibleParameterAnnotations; 105 public final Name RuntimeInvisibleParameterAnnotations; 106 public final Name PolymorphicSignature; 107 public final Name Value; 108 public final Name EnclosingMethod; 109 public final Name desiredAssertionStatus; 110 public final Name append; 111 public final Name family; 112 public final Name forName; 113 public final Name toString; 114 public final Name length; 115 public final Name valueOf; 116 public final Name value; 117 public final Name getMessage; 118 public final Name getClass; 119 public final Name TYPE; 120 public final Name TYPE_USE; 121 public final Name TYPE_PARAMETER; 122 public final Name FIELD; 123 public final Name METHOD; 124 public final Name PARAMETER; 125 public final Name CONSTRUCTOR; 126 public final Name LOCAL_VARIABLE; 127 public final Name ANNOTATION_TYPE; 128 public final Name PACKAGE; 129 public final Name SOURCE; 130 public final Name CLASS; 131 public final Name RUNTIME; 132 public final Name Array; 133 public final Name Method; 134 public final Name Bound; 135 public final Name clone; 136 public final Name getComponentType; 137 public final Name getClassLoader; 138 public final Name initCause; 139 public final Name values; 140 public final Name iterator; 141 public final Name hasNext; 142 public final Name next; 143 public final Name AnnotationDefault; 144 public final Name ordinal; 145 public final Name equals; 146 public final Name hashCode; 147 public final Name compareTo; 148 public final Name getDeclaringClass; 149 public final Name ex; 150 public final Name finalize; 151 public final Name java_lang_AutoCloseable; 152 public final Name close; 153 154 public final Name.Table table; 155 156 public Names(Context context) { 157 Options options = Options.instance(context); 158 table = createTable(options); 159 160 slash = fromString("/"); 161 hyphen = fromString("-"); 162 T = fromString("T"); 163 slashequals = fromString("/="); 164 deprecated = fromString("deprecated"); 165 166 init = fromString("<init>"); 167 clinit = fromString("<clinit>"); 168 error = fromString("<error>"); 169 any = fromString("<any>"); 170 empty = fromString(""); 171 one = fromString("1"); 172 period = fromString("."); 173 comma = fromString(","); 174 semicolon = fromString(";"); 175 asterisk = fromString("*"); 176 _this = fromString("this"); 177 _super = fromString("super"); 178 _default = fromString("default"); 179 180 _class = fromString("class"); 181 java_lang = fromString("java.lang"); 182 java_lang_Object = fromString("java.lang.Object"); 183 java_lang_Class = fromString("java.lang.Class"); 184 java_lang_Cloneable = fromString("java.lang.Cloneable"); 185 java_io_Serializable = fromString("java.io.Serializable"); 186 java_lang_Enum = fromString("java.lang.Enum"); 187 java_dyn_MethodHandle = fromString("java.dyn.MethodHandle"); 188 java_dyn_InvokeDynamic = fromString("java.dyn.InvokeDynamic"); 189 package_info = fromString("package-info"); 190 serialVersionUID = fromString("serialVersionUID"); 191 ConstantValue = fromString("ConstantValue"); 192 LineNumberTable = fromString("LineNumberTable"); 193 LocalVariableTable = fromString("LocalVariableTable"); 194 LocalVariableTypeTable = fromString("LocalVariableTypeTable"); 195 CharacterRangeTable = fromString("CharacterRangeTable"); 196 StackMap = fromString("StackMap"); 197 StackMapTable = fromString("StackMapTable"); 198 SourceID = fromString("SourceID"); 199 CompilationID = fromString("CompilationID"); 200 Code = fromString("Code"); 201 Exceptions = fromString("Exceptions"); 202 SourceFile = fromString("SourceFile"); 203 InnerClasses = fromString("InnerClasses"); 204 Synthetic = fromString("Synthetic"); 205 Bridge = fromString("Bridge"); 206 Deprecated = fromString("Deprecated"); 207 Enum = fromString("Enum"); 208 _name = fromString("name"); 209 Signature = fromString("Signature"); 210 Varargs = fromString("Varargs"); 211 Annotation = fromString("Annotation"); 212 RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations"); 213 RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations"); 214 RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations"); 215 RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations"); 216 RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations"); 217 RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations"); 218 PolymorphicSignature = fromString("PolymorphicSignature"); 219 Value = fromString("Value"); 220 EnclosingMethod = fromString("EnclosingMethod"); 221 222 desiredAssertionStatus = fromString("desiredAssertionStatus"); 223 224 append = fromString("append"); 225 family = fromString("family"); 226 forName = fromString("forName"); 227 toString = fromString("toString"); 228 length = fromString("length"); 229 valueOf = fromString("valueOf"); 230 value = fromString("value"); 231 getMessage = fromString("getMessage"); 232 getClass = fromString("getClass"); 233 234 TYPE = fromString("TYPE"); 235 TYPE_USE = fromString("TYPE_USE"); 236 TYPE_PARAMETER = fromString("TYPE_PARAMETER"); 237 FIELD = fromString("FIELD"); 238 METHOD = fromString("METHOD"); 239 PARAMETER = fromString("PARAMETER"); 240 CONSTRUCTOR = fromString("CONSTRUCTOR"); 241 LOCAL_VARIABLE = fromString("LOCAL_VARIABLE"); 242 ANNOTATION_TYPE = fromString("ANNOTATION_TYPE"); 243 PACKAGE = fromString("PACKAGE"); 244 245 SOURCE = fromString("SOURCE"); 246 CLASS = fromString("CLASS"); 247 RUNTIME = fromString("RUNTIME"); 248 249 Array = fromString("Array"); 250 Method = fromString("Method"); 251 Bound = fromString("Bound"); 252 clone = fromString("clone"); 253 getComponentType = fromString("getComponentType"); 254 getClassLoader = fromString("getClassLoader"); 255 initCause = fromString("initCause"); 256 values = fromString("values"); 257 iterator = fromString("iterator"); 258 hasNext = fromString("hasNext"); 259 next = fromString("next"); 260 AnnotationDefault = fromString("AnnotationDefault"); 261 ordinal = fromString("ordinal"); 262 equals = fromString("equals"); 263 hashCode = fromString("hashCode"); 264 compareTo = fromString("compareTo"); 265 getDeclaringClass = fromString("getDeclaringClass"); 266 ex = fromString("ex"); 267 finalize = fromString("finalize"); 268 269 java_lang_AutoCloseable = fromString("java.lang.AutoCloseable"); 270 close = fromString("close"); 271 } 272 273 protected Name.Table createTable(Options options) { 274 boolean useUnsharedTable = options.get("useUnsharedTable") != null; 275 if (useUnsharedTable) 276 return new UnsharedNameTable(this); 277 else 278 return new SharedNameTable(this); 279 } 280 281 public void dispose() { 282 table.dispose(); 283 } 284 285 public Name fromChars(char[] cs, int start, int len) { 286 return table.fromChars(cs, start, len); 287 } 288 289 public Name fromString(String s) { 290 return table.fromString(s); 291 } 292 293 public Name fromUtf(byte[] cs) { 294 return table.fromUtf(cs); 295 } 296 297 public Name fromUtf(byte[] cs, int start, int len) { 298 return table.fromUtf(cs, start, len); 299 } 300 }