src/share/classes/com/sun/tools/javac/util/Names.java

Thu, 21 Feb 2013 17:49:56 -0800

author
lana
date
Thu, 21 Feb 2013 17:49:56 -0800
changeset 1603
6118072811e5
parent 1587
f1f605f85850
child 1882
39ec5d8a691b
permissions
-rw-r--r--

Merge

jjg@113 1 /*
jjg@1208 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
jjg@113 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@113 4 *
jjg@113 5 * This code is free software; you can redistribute it and/or modify it
jjg@113 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
jjg@113 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
jjg@113 10 *
jjg@113 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@113 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@113 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@113 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@113 15 * accompanied this code).
jjg@113 16 *
jjg@113 17 * You should have received a copy of the GNU General Public License version
jjg@113 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@113 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@113 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
jjg@113 24 */
jjg@113 25
jjg@113 26 package com.sun.tools.javac.util;
jjg@113 27
jjg@113 28 /**
jjg@113 29 * Access to the compiler's name table. STandard names are defined,
jjg@113 30 * as well as methods to create new names.
jjg@113 31 *
jjg@581 32 * <p><b>This is NOT part of any supported API.
jjg@581 33 * If you write code that depends on this, you do so at your own risk.
jjg@113 34 * This code and its internal interfaces are subject to change or
jjg@113 35 * deletion without notice.</b>
jjg@113 36 */
jjg@113 37 public class Names {
jjg@113 38
jjg@113 39 public static final Context.Key<Names> namesKey = new Context.Key<Names>();
jjg@113 40
jjg@113 41 public static Names instance(Context context) {
jjg@113 42 Names instance = context.get(namesKey);
jjg@113 43 if (instance == null) {
jjg@113 44 instance = new Names(context);
jjg@113 45 context.put(namesKey, instance);
jjg@113 46 }
jjg@113 47 return instance;
jjg@113 48 }
jjg@113 49
jjg@1208 50 // operators and punctuation
jjg@1208 51 public final Name asterisk;
jjg@1208 52 public final Name comma;
jjg@1208 53 public final Name empty;
jjg@113 54 public final Name hyphen;
jjg@113 55 public final Name one;
jjg@113 56 public final Name period;
jjg@113 57 public final Name semicolon;
jjg@1208 58 public final Name slash;
jjg@1208 59 public final Name slashequals;
jjg@1208 60
jjg@1208 61 // keywords
jjg@1208 62 public final Name _class;
jjg@1208 63 public final Name _default;
jjg@1208 64 public final Name _super;
jjg@113 65 public final Name _this;
jjg@1208 66
jjg@1208 67 // field and method names
jjg@1208 68 public final Name _name;
jjg@1208 69 public final Name addSuppressed;
jjg@1208 70 public final Name any;
jjg@1208 71 public final Name append;
jjg@1208 72 public final Name clinit;
jjg@1208 73 public final Name clone;
jjg@1208 74 public final Name close;
jjg@1208 75 public final Name compareTo;
rfield@1587 76 public final Name deserializeLambda;
jjg@1208 77 public final Name desiredAssertionStatus;
jjg@1208 78 public final Name equals;
jjg@1208 79 public final Name error;
jjg@1208 80 public final Name family;
jjg@1208 81 public final Name finalize;
jjg@1208 82 public final Name forName;
jjg@1208 83 public final Name getClass;
jjg@1208 84 public final Name getClassLoader;
jjg@1208 85 public final Name getComponentType;
jjg@1208 86 public final Name getDeclaringClass;
jjg@1208 87 public final Name getMessage;
jjg@1208 88 public final Name hasNext;
jjg@1208 89 public final Name hashCode;
jjg@1208 90 public final Name init;
jjg@1208 91 public final Name initCause;
jjg@1208 92 public final Name iterator;
jjg@1208 93 public final Name length;
jjg@1208 94 public final Name next;
jjg@1208 95 public final Name ordinal;
jjg@1208 96 public final Name serialVersionUID;
jjg@1208 97 public final Name toString;
jjg@1208 98 public final Name value;
jjg@1208 99 public final Name valueOf;
jjg@1208 100 public final Name values;
jjg@1208 101
jjg@1208 102 // class names
jjg@1208 103 public final Name java_io_Serializable;
jjg@1208 104 public final Name java_lang_AutoCloseable;
jjg@113 105 public final Name java_lang_Class;
jjg@113 106 public final Name java_lang_Cloneable;
jjg@113 107 public final Name java_lang_Enum;
jjg@1208 108 public final Name java_lang_Object;
mcimadamore@857 109 public final Name java_lang_invoke_MethodHandle;
jjg@1208 110
jjg@1208 111 // names of builtin classes
jjg@1208 112 public final Name Array;
jjg@1208 113 public final Name Bound;
jjg@1208 114 public final Name Method;
jjg@1208 115
jjg@1208 116 // package names
jjg@1208 117 public final Name java_lang;
jjg@1208 118
jjg@1208 119 // attribute names
jjg@1208 120 public final Name Annotation;
jjg@1208 121 public final Name AnnotationDefault;
mcimadamore@1342 122 public final Name BootstrapMethods;
jjg@1208 123 public final Name Bridge;
jjg@1208 124 public final Name CharacterRangeTable;
jjg@1208 125 public final Name Code;
jjg@1208 126 public final Name CompilationID;
jjg@113 127 public final Name ConstantValue;
jjg@1208 128 public final Name Deprecated;
jjg@1208 129 public final Name EnclosingMethod;
jjg@1208 130 public final Name Enum;
jjg@1208 131 public final Name Exceptions;
jjg@1208 132 public final Name InnerClasses;
jjg@113 133 public final Name LineNumberTable;
jjg@113 134 public final Name LocalVariableTable;
jjg@113 135 public final Name LocalVariableTypeTable;
jjg@1473 136 public final Name MethodParameters;
jjg@1208 137 public final Name RuntimeInvisibleAnnotations;
jjg@1208 138 public final Name RuntimeInvisibleParameterAnnotations;
jjg@1208 139 public final Name RuntimeInvisibleTypeAnnotations;
jjg@1208 140 public final Name RuntimeVisibleAnnotations;
jjg@1208 141 public final Name RuntimeVisibleParameterAnnotations;
jjg@1208 142 public final Name RuntimeVisibleTypeAnnotations;
jjg@1208 143 public final Name Signature;
jjg@1208 144 public final Name SourceFile;
jjg@1208 145 public final Name SourceID;
jjg@113 146 public final Name StackMap;
jjg@113 147 public final Name StackMapTable;
jjg@113 148 public final Name Synthetic;
jjg@1208 149 public final Name Value;
jjg@113 150 public final Name Varargs;
jjg@1208 151
jjg@1208 152 // members of java.lang.annotation.ElementType
jjg@1208 153 public final Name ANNOTATION_TYPE;
jjg@1208 154 public final Name CONSTRUCTOR;
jjg@1208 155 public final Name FIELD;
jjg@1208 156 public final Name LOCAL_VARIABLE;
jjg@1208 157 public final Name METHOD;
jjg@1208 158 public final Name PACKAGE;
jjg@1208 159 public final Name PARAMETER;
jjg@113 160 public final Name TYPE;
jjg@1208 161 public final Name TYPE_PARAMETER;
jjg@308 162 public final Name TYPE_USE;
jjg@1208 163
jjg@1208 164 // members of java.lang.annotation.RetentionPolicy
jjg@113 165 public final Name CLASS;
jjg@113 166 public final Name RUNTIME;
jjg@1208 167 public final Name SOURCE;
jjg@1208 168
jjg@1208 169 // other identifiers
jjg@1208 170 public final Name T;
jjg@1208 171 public final Name deprecated;
jjg@113 172 public final Name ex;
jjg@1208 173 public final Name package_info;
jjg@113 174
rfield@1380 175 //lambda-related
rfield@1380 176 public final Name lambda;
rfield@1380 177 public final Name metaFactory;
rfield@1587 178 public final Name altMetaFactory;
rfield@1380 179
jjg@113 180 public final Name.Table table;
jjg@113 181
jjg@113 182 public Names(Context context) {
jjg@113 183 Options options = Options.instance(context);
jjg@113 184 table = createTable(options);
jjg@113 185
jjg@1208 186 // operators and punctuation
jjg@1208 187 asterisk = fromString("*");
jjg@1208 188 comma = fromString(",");
jjg@1208 189 empty = fromString("");
jjg@113 190 hyphen = fromString("-");
jjg@113 191 one = fromString("1");
jjg@113 192 period = fromString(".");
jjg@113 193 semicolon = fromString(";");
jjg@1208 194 slash = fromString("/");
jjg@1208 195 slashequals = fromString("/=");
jjg@1208 196
jjg@1208 197 // keywords
jjg@1208 198 _class = fromString("class");
jjg@1208 199 _default = fromString("default");
jjg@1208 200 _super = fromString("super");
jjg@113 201 _this = fromString("this");
jjg@113 202
jjg@1208 203 // field and method names
jjg@1208 204 _name = fromString("name");
jjg@1208 205 addSuppressed = fromString("addSuppressed");
jjg@1208 206 any = fromString("<any>");
jjg@1208 207 append = fromString("append");
jjg@1208 208 clinit = fromString("<clinit>");
jjg@1208 209 clone = fromString("clone");
jjg@1208 210 close = fromString("close");
jjg@1208 211 compareTo = fromString("compareTo");
rfield@1587 212 deserializeLambda = fromString("$deserializeLambda$");
jjg@1208 213 desiredAssertionStatus = fromString("desiredAssertionStatus");
jjg@1208 214 equals = fromString("equals");
jjg@1208 215 error = fromString("<error>");
jjg@1208 216 family = fromString("family");
jjg@1208 217 finalize = fromString("finalize");
jjg@1208 218 forName = fromString("forName");
jjg@1208 219 getClass = fromString("getClass");
jjg@1208 220 getClassLoader = fromString("getClassLoader");
jjg@1208 221 getComponentType = fromString("getComponentType");
jjg@1208 222 getDeclaringClass = fromString("getDeclaringClass");
jjg@1208 223 getMessage = fromString("getMessage");
jjg@1208 224 hasNext = fromString("hasNext");
jjg@1208 225 hashCode = fromString("hashCode");
jjg@1208 226 init = fromString("<init>");
jjg@1208 227 initCause = fromString("initCause");
jjg@1208 228 iterator = fromString("iterator");
jjg@1208 229 length = fromString("length");
jjg@1208 230 next = fromString("next");
jjg@1208 231 ordinal = fromString("ordinal");
jjg@1208 232 serialVersionUID = fromString("serialVersionUID");
jjg@1208 233 toString = fromString("toString");
jjg@1208 234 value = fromString("value");
jjg@1208 235 valueOf = fromString("valueOf");
jjg@1208 236 values = fromString("values");
jjg@1208 237
jjg@1208 238 // class names
jjg@1208 239 java_io_Serializable = fromString("java.io.Serializable");
jjg@1208 240 java_lang_AutoCloseable = fromString("java.lang.AutoCloseable");
jjg@113 241 java_lang_Class = fromString("java.lang.Class");
jjg@113 242 java_lang_Cloneable = fromString("java.lang.Cloneable");
jjg@113 243 java_lang_Enum = fromString("java.lang.Enum");
jjg@1208 244 java_lang_Object = fromString("java.lang.Object");
mcimadamore@857 245 java_lang_invoke_MethodHandle = fromString("java.lang.invoke.MethodHandle");
jjg@1208 246
jjg@1208 247 // names of builtin classes
jjg@1208 248 Array = fromString("Array");
jjg@1208 249 Bound = fromString("Bound");
jjg@1208 250 Method = fromString("Method");
jjg@1208 251
jjg@1208 252 // package names
jjg@1208 253 java_lang = fromString("java.lang");
jjg@1208 254
jjg@1208 255 // attribute names
jjg@1208 256 Annotation = fromString("Annotation");
jjg@1208 257 AnnotationDefault = fromString("AnnotationDefault");
mcimadamore@1342 258 BootstrapMethods = fromString("BootstrapMethods");
jjg@1208 259 Bridge = fromString("Bridge");
jjg@1208 260 CharacterRangeTable = fromString("CharacterRangeTable");
jjg@1208 261 Code = fromString("Code");
jjg@1208 262 CompilationID = fromString("CompilationID");
jjg@113 263 ConstantValue = fromString("ConstantValue");
jjg@1208 264 Deprecated = fromString("Deprecated");
jjg@1208 265 EnclosingMethod = fromString("EnclosingMethod");
jjg@1208 266 Enum = fromString("Enum");
jjg@1208 267 Exceptions = fromString("Exceptions");
jjg@1208 268 InnerClasses = fromString("InnerClasses");
jjg@113 269 LineNumberTable = fromString("LineNumberTable");
jjg@113 270 LocalVariableTable = fromString("LocalVariableTable");
jjg@113 271 LocalVariableTypeTable = fromString("LocalVariableTypeTable");
jjg@1473 272 MethodParameters = fromString("MethodParameters");
jjg@1208 273 RuntimeInvisibleAnnotations = fromString("RuntimeInvisibleAnnotations");
jjg@1208 274 RuntimeInvisibleParameterAnnotations = fromString("RuntimeInvisibleParameterAnnotations");
jjg@1208 275 RuntimeInvisibleTypeAnnotations = fromString("RuntimeInvisibleTypeAnnotations");
jjg@1208 276 RuntimeVisibleAnnotations = fromString("RuntimeVisibleAnnotations");
jjg@1208 277 RuntimeVisibleParameterAnnotations = fromString("RuntimeVisibleParameterAnnotations");
jjg@1208 278 RuntimeVisibleTypeAnnotations = fromString("RuntimeVisibleTypeAnnotations");
jjg@1208 279 Signature = fromString("Signature");
jjg@1208 280 SourceFile = fromString("SourceFile");
jjg@1208 281 SourceID = fromString("SourceID");
jjg@113 282 StackMap = fromString("StackMap");
jjg@113 283 StackMapTable = fromString("StackMapTable");
jjg@113 284 Synthetic = fromString("Synthetic");
jjg@1208 285 Value = fromString("Value");
jjg@113 286 Varargs = fromString("Varargs");
jjg@113 287
jjg@1208 288 // members of java.lang.annotation.ElementType
jjg@1208 289 ANNOTATION_TYPE = fromString("ANNOTATION_TYPE");
jjg@1208 290 CONSTRUCTOR = fromString("CONSTRUCTOR");
jjg@1208 291 FIELD = fromString("FIELD");
jjg@1208 292 LOCAL_VARIABLE = fromString("LOCAL_VARIABLE");
jjg@1208 293 METHOD = fromString("METHOD");
jjg@1208 294 PACKAGE = fromString("PACKAGE");
jjg@1208 295 PARAMETER = fromString("PARAMETER");
jjg@1208 296 TYPE = fromString("TYPE");
jjg@1208 297 TYPE_PARAMETER = fromString("TYPE_PARAMETER");
jjg@1208 298 TYPE_USE = fromString("TYPE_USE");
jjg@113 299
jjg@1208 300 // members of java.lang.annotation.RetentionPolicy
jjg@113 301 CLASS = fromString("CLASS");
jjg@113 302 RUNTIME = fromString("RUNTIME");
jjg@1208 303 SOURCE = fromString("SOURCE");
jjg@113 304
jjg@1208 305 // other identifiers
jjg@1208 306 T = fromString("T");
jjg@1208 307 deprecated = fromString("deprecated");
jjg@113 308 ex = fromString("ex");
jjg@1208 309 package_info = fromString("package-info");
rfield@1380 310
rfield@1380 311 //lambda-related
rfield@1587 312 lambda = fromString("lambda$");
rfield@1380 313 metaFactory = fromString("metaFactory");
rfield@1587 314 altMetaFactory = fromString("altMetaFactory");
jjg@113 315 }
jjg@113 316
jjg@113 317 protected Name.Table createTable(Options options) {
jjg@700 318 boolean useUnsharedTable = options.isSet("useUnsharedTable");
jjg@113 319 if (useUnsharedTable)
jjg@113 320 return new UnsharedNameTable(this);
jjg@113 321 else
jjg@113 322 return new SharedNameTable(this);
jjg@113 323 }
jjg@113 324
jjg@113 325 public void dispose() {
jjg@113 326 table.dispose();
jjg@113 327 }
jjg@113 328
jjg@113 329 public Name fromChars(char[] cs, int start, int len) {
jjg@113 330 return table.fromChars(cs, start, len);
jjg@113 331 }
jjg@113 332
jjg@113 333 public Name fromString(String s) {
jjg@113 334 return table.fromString(s);
jjg@113 335 }
jjg@113 336
jjg@113 337 public Name fromUtf(byte[] cs) {
jjg@113 338 return table.fromUtf(cs);
jjg@113 339 }
jjg@113 340
jjg@113 341 public Name fromUtf(byte[] cs, int start, int len) {
jjg@113 342 return table.fromUtf(cs, start, len);
jjg@113 343 }
jjg@113 344 }

mercurial