1 /* 2 * Copyright (c) 1999, 2010, 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 Value; 107 public final Name EnclosingMethod; 108 public final Name desiredAssertionStatus; 109 public final Name append; 110 public final Name family; 111 public final Name forName; 112 public final Name toString; 113 public final Name length; 114 public final Name valueOf; 115 public final Name value; 116 public final Name getMessage; 117 public final Name getClass; 118 public final Name invoke; //allowTransitionalJSR292 only 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 public final Name addSuppressed; 154 155 public final Name.Table table; 156 157 public Names(Context context) { 158 Options options = Options.instance(context); 159 table = createTable(options); 160 161 slash = fromString("/"); 162 hyphen = fromString("-"); 163 T = fromString("T"); 164 slashequals = fromString("/="); 165 deprecated = fromString("deprecated"); 166 167 init = fromString("<init>"); 168 clinit = fromString("<clinit>"); 169 error = fromString("<error>"); 170 any = fromString("<any>"); 171 empty = fromString(""); 172 one = fromString("1"); 173 period = fromString("."); 174 comma = fromString(","); 175 semicolon = fromString(";"); 176 asterisk = fromString("*"); 177 _this = fromString("this"); 178 _super = fromString("super"); 179 _default = fromString("default"); 180 181 _class = fromString("class"); 182 java_lang = fromString("java.lang"); 183 java_lang_Object = fromString("java.lang.Object"); 184 java_lang_Class = fromString("java.lang.Class"); 185 java_lang_Cloneable = fromString("java.lang.Cloneable"); 186 java_io_Serializable = fromString("java.io.Serializable"); 187 java_lang_Enum = fromString("java.lang.Enum"); 188 java_dyn_MethodHandle = fromString("java.dyn.MethodHandle"); 189 java_dyn_InvokeDynamic = fromString("java.dyn.InvokeDynamic"); 190 package_info = fromString("package-info"); 191 serialVersionUID = fromString("serialVersionUID"); 192 ConstantValue = fromString("ConstantValue"); 193 LineNumberTable = fromString("LineNumberTable"); 194 LocalVariableTable = fromString("LocalVariableTable"); 195 LocalVariableTypeTable = fromString("LocalVariableTypeTable"); 196 CharacterRangeTable = fromString("CharacterRangeTable"); 197 StackMap = fromString("StackMap"); 198 StackMapTable = fromString("StackMapTable"); 199 SourceID = fromString("SourceID"); 200 CompilationID = fromString("CompilationID"); 201 Code = fromString("Code"); 202 Exceptions = fromString("Exceptions"); 203 SourceFile = fromString("SourceFile"); 204 InnerClasses = fromString("InnerClasses"); 205 Synthetic = fromString("Synthetic"); 206 Bridge = fromString("Bridge"); 207 Deprecated = fromString("Deprecated"); 208 Enum = fromString("Enum"); 209 _name = fromString("name"); 210 Signature = fromString("Signature"); 211 Varargs = fromString("Varargs"); 212 Annotation = fromString("Annotation"); 213 RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations"); 214 RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations"); 215 RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations"); 216 RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations"); 217 RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations"); 218 RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations"); 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 invoke = fromString("invoke"); //allowTransitionalJSR292 only 234 235 TYPE = fromString("TYPE"); 236 TYPE_USE = fromString("TYPE_USE"); 237 TYPE_PARAMETER = fromString("TYPE_PARAMETER"); 238 FIELD = fromString("FIELD"); 239 METHOD = fromString("METHOD"); 240 PARAMETER = fromString("PARAMETER"); 241 CONSTRUCTOR = fromString("CONSTRUCTOR"); 242 LOCAL_VARIABLE = fromString("LOCAL_VARIABLE"); 243 ANNOTATION_TYPE = fromString("ANNOTATION_TYPE"); 244 PACKAGE = fromString("PACKAGE"); 245 246 SOURCE = fromString("SOURCE"); 247 CLASS = fromString("CLASS"); 248 RUNTIME = fromString("RUNTIME"); 249 250 Array = fromString("Array"); 251 Method = fromString("Method"); 252 Bound = fromString("Bound"); 253 clone = fromString("clone"); 254 getComponentType = fromString("getComponentType"); 255 getClassLoader = fromString("getClassLoader"); 256 initCause = fromString("initCause"); 257 values = fromString("values"); 258 iterator = fromString("iterator"); 259 hasNext = fromString("hasNext"); 260 next = fromString("next"); 261 AnnotationDefault = fromString("AnnotationDefault"); 262 ordinal = fromString("ordinal"); 263 equals = fromString("equals"); 264 hashCode = fromString("hashCode"); 265 compareTo = fromString("compareTo"); 266 getDeclaringClass = fromString("getDeclaringClass"); 267 ex = fromString("ex"); 268 finalize = fromString("finalize"); 269 270 java_lang_AutoCloseable = fromString("java.lang.AutoCloseable"); 271 close = fromString("close"); 272 addSuppressed = fromString("addSuppressed"); 273 } 274 275 protected Name.Table createTable(Options options) { 276 boolean useUnsharedTable = options.isSet("useUnsharedTable"); 277 if (useUnsharedTable) 278 return new UnsharedNameTable(this); 279 else 280 return new SharedNameTable(this); 281 } 282 283 public void dispose() { 284 table.dispose(); 285 } 286 287 public Name fromChars(char[] cs, int start, int len) { 288 return table.fromChars(cs, start, len); 289 } 290 291 public Name fromString(String s) { 292 return table.fromString(s); 293 } 294 295 public Name fromUtf(byte[] cs) { 296 return table.fromUtf(cs); 297 } 298 299 public Name fromUtf(byte[] cs, int start, int len) { 300 return table.fromUtf(cs, start, len); 301 } 302 }