src/share/classes/com/sun/tools/classfile/ConstantPool.java

Tue, 03 Jun 2008 13:26:47 -0700

author
jjg
date
Tue, 03 Jun 2008 13:26:47 -0700
changeset 46
7708bd6d800d
child 52
3cb4fb6e0720
permissions
-rw-r--r--

4075303: Use javap to enquire aboput a specific inner class
4348375: Javap is not internationalized
4459541: "javap -l" shows line numbers as signed short; they should be unsigned
4501660: change diagnostic of -help as 'print this help message and exit'
4776241: unused source file in javap...
4870651: javap should recognize generics, varargs, enum
4876942: javap invoked without args does not print help screen
4880663: javap could output whitespace between class name and opening brace
4975569: javap doesn't print new flag bits
6271787: javap dumps LocalVariableTypeTable attribute in hex, needs to print a table
6305779: javap: support annotations
6439940: Clean up javap implementation
6469569: wrong check of searchpath in JavapEnvironment
6474890: javap does not open .zip files in -classpath
6587786: Javap throws error : "ERROR:Could not find <classname>" for JRE classes
6622215: javap ignores certain relevant access flags
6622216: javap names some attributes incorrectly
6622232: javap gets whitespace confused
6622260: javap prints negative bytes incorrectly in hex
Reviewed-by: ksrini

jjg@46 1 /*
jjg@46 2 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
jjg@46 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@46 4 *
jjg@46 5 * This code is free software; you can redistribute it and/or modify it
jjg@46 6 * under the terms of the GNU General Public License version 2 only, as
jjg@46 7 * published by the Free Software Foundation. Sun designates this
jjg@46 8 * particular file as subject to the "Classpath" exception as provided
jjg@46 9 * by Sun in the LICENSE file that accompanied this code.
jjg@46 10 *
jjg@46 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@46 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@46 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@46 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@46 15 * accompanied this code).
jjg@46 16 *
jjg@46 17 * You should have received a copy of the GNU General Public License version
jjg@46 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@46 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@46 20 *
jjg@46 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@46 22 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@46 23 * have any questions.
jjg@46 24 */
jjg@46 25
jjg@46 26 package com.sun.tools.classfile;
jjg@46 27
jjg@46 28 import java.io.IOException;
jjg@46 29
jjg@46 30 /**
jjg@46 31 * See JVMS3, section 4.5.
jjg@46 32 *
jjg@46 33 * <p><b>This is NOT part of any API supported by Sun Microsystems. If
jjg@46 34 * you write code that depends on this, you do so at your own risk.
jjg@46 35 * This code and its internal interfaces are subject to change or
jjg@46 36 * deletion without notice.</b>
jjg@46 37 */
jjg@46 38 public class ConstantPool {
jjg@46 39
jjg@46 40 public class InvalidIndex extends ConstantPoolException {
jjg@46 41 InvalidIndex(int index) {
jjg@46 42 super(index);
jjg@46 43 }
jjg@46 44
jjg@46 45 @Override
jjg@46 46 public String getMessage() {
jjg@46 47 // i18n
jjg@46 48 return "invalid index #" + index;
jjg@46 49 }
jjg@46 50 }
jjg@46 51
jjg@46 52 public class UnexpectedEntry extends ConstantPoolException {
jjg@46 53 UnexpectedEntry(int index, int expected_tag, int found_tag) {
jjg@46 54 super(index);
jjg@46 55 this.expected_tag = expected_tag;
jjg@46 56 this.found_tag = found_tag;
jjg@46 57 }
jjg@46 58
jjg@46 59 @Override
jjg@46 60 public String getMessage() {
jjg@46 61 // i18n?
jjg@46 62 return "unexpected entry at #" + index + " -- expected tag " + expected_tag + ", found " + found_tag;
jjg@46 63 }
jjg@46 64
jjg@46 65 public final int expected_tag;
jjg@46 66 public final int found_tag;
jjg@46 67 }
jjg@46 68
jjg@46 69 public class InvalidEntry extends ConstantPoolException {
jjg@46 70 InvalidEntry(int index, int tag) {
jjg@46 71 super(index);
jjg@46 72 this.tag = tag;
jjg@46 73 }
jjg@46 74
jjg@46 75 @Override
jjg@46 76 public String getMessage() {
jjg@46 77 // i18n?
jjg@46 78 return "unexpected tag at #" + index + ": " + tag;
jjg@46 79 }
jjg@46 80
jjg@46 81 public final int tag;
jjg@46 82 }
jjg@46 83
jjg@46 84 public class EntryNotFound extends ConstantPoolException {
jjg@46 85 EntryNotFound(Object value) {
jjg@46 86 super(-1);
jjg@46 87 this.value = value;
jjg@46 88 }
jjg@46 89
jjg@46 90 @Override
jjg@46 91 public String getMessage() {
jjg@46 92 // i18n?
jjg@46 93 return "value not found: " + value;
jjg@46 94 }
jjg@46 95
jjg@46 96 public final Object value;
jjg@46 97 }
jjg@46 98
jjg@46 99 public static final int CONSTANT_Utf8 = 1;
jjg@46 100 public static final int CONSTANT_Integer = 3;
jjg@46 101 public static final int CONSTANT_Float = 4;
jjg@46 102 public static final int CONSTANT_Long = 5;
jjg@46 103 public static final int CONSTANT_Double = 6;
jjg@46 104 public static final int CONSTANT_Class = 7;
jjg@46 105 public static final int CONSTANT_String = 8;
jjg@46 106 public static final int CONSTANT_Fieldref = 9;
jjg@46 107 public static final int CONSTANT_Methodref = 10;
jjg@46 108 public static final int CONSTANT_InterfaceMethodref = 11;
jjg@46 109 public static final int CONSTANT_NameAndType = 12;
jjg@46 110
jjg@46 111 ConstantPool(ClassReader cr) throws IOException, InvalidEntry {
jjg@46 112 int count = cr.readUnsignedShort();
jjg@46 113 pool = new CPInfo[count];
jjg@46 114 for (int i = 1; i < count; i++) {
jjg@46 115 int tag = cr.readUnsignedByte();
jjg@46 116 switch (tag) {
jjg@46 117 case CONSTANT_Class:
jjg@46 118 pool[i] = new CONSTANT_Class_info(this, cr);
jjg@46 119 break;
jjg@46 120
jjg@46 121 case CONSTANT_Double:
jjg@46 122 pool[i] = new CONSTANT_Double_info(cr);
jjg@46 123 i++;
jjg@46 124 break;
jjg@46 125
jjg@46 126 case CONSTANT_Fieldref:
jjg@46 127 pool[i] = new CONSTANT_Fieldref_info(this, cr);
jjg@46 128 break;
jjg@46 129
jjg@46 130 case CONSTANT_Float:
jjg@46 131 pool[i] = new CONSTANT_Float_info(cr);
jjg@46 132 break;
jjg@46 133
jjg@46 134 case CONSTANT_Integer:
jjg@46 135 pool[i] = new CONSTANT_Integer_info(cr);
jjg@46 136 break;
jjg@46 137
jjg@46 138 case CONSTANT_InterfaceMethodref:
jjg@46 139 pool[i] = new CONSTANT_InterfaceMethodref_info(this, cr);
jjg@46 140 break;
jjg@46 141
jjg@46 142 case CONSTANT_Long:
jjg@46 143 pool[i] = new CONSTANT_Long_info(cr);
jjg@46 144 i++;
jjg@46 145 break;
jjg@46 146
jjg@46 147 case CONSTANT_Methodref:
jjg@46 148 pool[i] = new CONSTANT_Methodref_info(this, cr);
jjg@46 149 break;
jjg@46 150
jjg@46 151 case CONSTANT_NameAndType:
jjg@46 152 pool[i] = new CONSTANT_NameAndType_info(this, cr);
jjg@46 153 break;
jjg@46 154
jjg@46 155 case CONSTANT_String:
jjg@46 156 pool[i] = new CONSTANT_String_info(cr);
jjg@46 157 break;
jjg@46 158
jjg@46 159 case CONSTANT_Utf8:
jjg@46 160 pool[i] = new CONSTANT_Utf8_info(cr);
jjg@46 161 break;
jjg@46 162
jjg@46 163 default:
jjg@46 164 throw new InvalidEntry(i, tag);
jjg@46 165 }
jjg@46 166 }
jjg@46 167 }
jjg@46 168
jjg@46 169 public ConstantPool(CPInfo[] pool) {
jjg@46 170 this.pool = pool;
jjg@46 171 }
jjg@46 172
jjg@46 173 public int size() {
jjg@46 174 return pool.length;
jjg@46 175 }
jjg@46 176
jjg@46 177 public CPInfo get(int index) throws InvalidIndex {
jjg@46 178 if (index <= 0 || index >= pool.length)
jjg@46 179 throw new InvalidIndex(index);
jjg@46 180 CPInfo info = pool[index];
jjg@46 181 if (info == null) {
jjg@46 182 // this occurs for indices referencing the "second half" of an
jjg@46 183 // 8 byte constant, such as CONSTANT_Double or CONSTANT_Long
jjg@46 184 throw new InvalidIndex(index);
jjg@46 185 }
jjg@46 186 return pool[index];
jjg@46 187 }
jjg@46 188
jjg@46 189 private CPInfo get(int index, int expected_type) throws InvalidIndex, UnexpectedEntry {
jjg@46 190 CPInfo info = get(index);
jjg@46 191 if (info.getTag() != expected_type)
jjg@46 192 throw new UnexpectedEntry(index, expected_type, info.getTag());
jjg@46 193 return info;
jjg@46 194 }
jjg@46 195
jjg@46 196 public CONSTANT_Utf8_info getUTF8Info(int index) throws InvalidIndex, UnexpectedEntry {
jjg@46 197 return ((CONSTANT_Utf8_info) get(index, CONSTANT_Utf8));
jjg@46 198 }
jjg@46 199
jjg@46 200 public CONSTANT_Class_info getClassInfo(int index) throws InvalidIndex, UnexpectedEntry {
jjg@46 201 return ((CONSTANT_Class_info) get(index, CONSTANT_Class));
jjg@46 202 }
jjg@46 203
jjg@46 204 public CONSTANT_NameAndType_info getNameAndTypeInfo(int index) throws InvalidIndex, UnexpectedEntry {
jjg@46 205 return ((CONSTANT_NameAndType_info) get(index, CONSTANT_NameAndType));
jjg@46 206 }
jjg@46 207
jjg@46 208 public String getUTF8Value(int index) throws InvalidIndex, UnexpectedEntry {
jjg@46 209 return getUTF8Info(index).value;
jjg@46 210 }
jjg@46 211
jjg@46 212 public int getUTF8Index(String value) throws EntryNotFound {
jjg@46 213 for (int i = 1; i < pool.length; i++) {
jjg@46 214 CPInfo info = pool[i];
jjg@46 215 if (info instanceof CONSTANT_Utf8_info &&
jjg@46 216 ((CONSTANT_Utf8_info) info).value.equals(value))
jjg@46 217 return i;
jjg@46 218 }
jjg@46 219 throw new EntryNotFound(value);
jjg@46 220 }
jjg@46 221
jjg@46 222 private CPInfo[] pool;
jjg@46 223
jjg@46 224 public interface Visitor<R,P> {
jjg@46 225 R visitClass(CONSTANT_Class_info info, P p);
jjg@46 226 R visitDouble(CONSTANT_Double_info info, P p);
jjg@46 227 R visitFieldref(CONSTANT_Fieldref_info info, P p);
jjg@46 228 R visitFloat(CONSTANT_Float_info info, P p);
jjg@46 229 R visitInteger(CONSTANT_Integer_info info, P p);
jjg@46 230 R visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, P p);
jjg@46 231 R visitLong(CONSTANT_Long_info info, P p);
jjg@46 232 R visitNameAndType(CONSTANT_NameAndType_info info, P p);
jjg@46 233 R visitMethodref(CONSTANT_Methodref_info info, P p);
jjg@46 234 R visitString(CONSTANT_String_info info, P p);
jjg@46 235 R visitUtf8(CONSTANT_Utf8_info info, P p);
jjg@46 236 }
jjg@46 237
jjg@46 238 public static abstract class CPInfo {
jjg@46 239 CPInfo() {
jjg@46 240 this.cp = null;
jjg@46 241 }
jjg@46 242
jjg@46 243 CPInfo(ConstantPool cp) {
jjg@46 244 this.cp = cp;
jjg@46 245 }
jjg@46 246
jjg@46 247 public abstract int getTag();
jjg@46 248
jjg@46 249 public abstract <R,D> R accept(Visitor<R,D> visitor, D data);
jjg@46 250
jjg@46 251 protected final ConstantPool cp;
jjg@46 252 }
jjg@46 253
jjg@46 254 public static abstract class CPRefInfo extends CPInfo {
jjg@46 255 protected CPRefInfo(ConstantPool cp, ClassReader cr, int tag) throws IOException {
jjg@46 256 super(cp);
jjg@46 257 this.tag = tag;
jjg@46 258 class_index = cr.readUnsignedShort();
jjg@46 259 name_and_type_index = cr.readUnsignedShort();
jjg@46 260 }
jjg@46 261
jjg@46 262 protected CPRefInfo(ConstantPool cp, int tag, int class_index, int name_and_type_index) {
jjg@46 263 super(cp);
jjg@46 264 this.tag = tag;
jjg@46 265 this.class_index = class_index;
jjg@46 266 this.name_and_type_index = name_and_type_index;
jjg@46 267 }
jjg@46 268
jjg@46 269 public int getTag() {
jjg@46 270 return tag;
jjg@46 271 }
jjg@46 272
jjg@46 273 public CONSTANT_Class_info getClassInfo() throws ConstantPoolException {
jjg@46 274 return cp.getClassInfo(class_index);
jjg@46 275 }
jjg@46 276
jjg@46 277 public String getClassName() throws ConstantPoolException {
jjg@46 278 return cp.getClassInfo(class_index).getName();
jjg@46 279 }
jjg@46 280
jjg@46 281 public CONSTANT_NameAndType_info getNameAndTypeInfo() throws ConstantPoolException {
jjg@46 282 return cp.getNameAndTypeInfo(name_and_type_index);
jjg@46 283 }
jjg@46 284
jjg@46 285 public final int tag;
jjg@46 286 public final int class_index;
jjg@46 287 public final int name_and_type_index;
jjg@46 288 }
jjg@46 289
jjg@46 290 public static class CONSTANT_Class_info extends CPInfo {
jjg@46 291 CONSTANT_Class_info(ConstantPool cp, ClassReader cr) throws IOException {
jjg@46 292 super(cp);
jjg@46 293 name_index = cr.readUnsignedShort();
jjg@46 294 }
jjg@46 295
jjg@46 296 public CONSTANT_Class_info(ConstantPool cp, int name_index) {
jjg@46 297 super(cp);
jjg@46 298 this.name_index = name_index;
jjg@46 299 }
jjg@46 300
jjg@46 301 public int getTag() {
jjg@46 302 return CONSTANT_Class;
jjg@46 303 }
jjg@46 304
jjg@46 305 public String getName() throws ConstantPoolException {
jjg@46 306 return cp.getUTF8Value(name_index);
jjg@46 307 }
jjg@46 308
jjg@46 309 @Override
jjg@46 310 public String toString() {
jjg@46 311 return "CONSTANT_Class_info[name_index: " + name_index + "]";
jjg@46 312 }
jjg@46 313
jjg@46 314 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 315 return visitor.visitClass(this, data);
jjg@46 316 }
jjg@46 317
jjg@46 318 public final int name_index;
jjg@46 319 }
jjg@46 320
jjg@46 321 public static class CONSTANT_Double_info extends CPInfo {
jjg@46 322 CONSTANT_Double_info(ClassReader cr) throws IOException {
jjg@46 323 value = cr.readDouble();
jjg@46 324 }
jjg@46 325
jjg@46 326 public CONSTANT_Double_info(double value) {
jjg@46 327 this.value = value;
jjg@46 328 }
jjg@46 329
jjg@46 330 public int getTag() {
jjg@46 331 return CONSTANT_Double;
jjg@46 332 }
jjg@46 333
jjg@46 334 @Override
jjg@46 335 public String toString() {
jjg@46 336 return "CONSTANT_Double_info[value: " + value + "]";
jjg@46 337 }
jjg@46 338
jjg@46 339 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 340 return visitor.visitDouble(this, data);
jjg@46 341 }
jjg@46 342
jjg@46 343 public final double value;
jjg@46 344 }
jjg@46 345
jjg@46 346 public static class CONSTANT_Fieldref_info extends CPRefInfo {
jjg@46 347 CONSTANT_Fieldref_info(ConstantPool cp, ClassReader cr) throws IOException {
jjg@46 348 super(cp, cr, CONSTANT_Fieldref);
jjg@46 349 }
jjg@46 350
jjg@46 351 public CONSTANT_Fieldref_info(ConstantPool cp, int class_index, int name_and_type_index) {
jjg@46 352 super(cp, CONSTANT_Fieldref, class_index, name_and_type_index);
jjg@46 353 }
jjg@46 354
jjg@46 355 @Override
jjg@46 356 public String toString() {
jjg@46 357 return "CONSTANT_Fieldref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]";
jjg@46 358 }
jjg@46 359
jjg@46 360 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 361 return visitor.visitFieldref(this, data);
jjg@46 362 }
jjg@46 363 }
jjg@46 364
jjg@46 365 public static class CONSTANT_Float_info extends CPInfo {
jjg@46 366 CONSTANT_Float_info(ClassReader cr) throws IOException {
jjg@46 367 value = cr.readFloat();
jjg@46 368 }
jjg@46 369
jjg@46 370 public CONSTANT_Float_info(float value) {
jjg@46 371 this.value = value;
jjg@46 372 }
jjg@46 373
jjg@46 374 public int getTag() {
jjg@46 375 return CONSTANT_Float;
jjg@46 376 }
jjg@46 377
jjg@46 378 @Override
jjg@46 379 public String toString() {
jjg@46 380 return "CONSTANT_Float_info[value: " + value + "]";
jjg@46 381 }
jjg@46 382
jjg@46 383 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 384 return visitor.visitFloat(this, data);
jjg@46 385 }
jjg@46 386
jjg@46 387 public final float value;
jjg@46 388 }
jjg@46 389
jjg@46 390 public static class CONSTANT_Integer_info extends CPInfo {
jjg@46 391 CONSTANT_Integer_info(ClassReader cr) throws IOException {
jjg@46 392 value = cr.readInt();
jjg@46 393 }
jjg@46 394
jjg@46 395 public CONSTANT_Integer_info(int value) {
jjg@46 396 this.value = value;
jjg@46 397 }
jjg@46 398
jjg@46 399 public int getTag() {
jjg@46 400 return CONSTANT_Integer;
jjg@46 401 }
jjg@46 402
jjg@46 403 @Override
jjg@46 404 public String toString() {
jjg@46 405 return "CONSTANT_Integer_info[value: " + value + "]";
jjg@46 406 }
jjg@46 407
jjg@46 408 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 409 return visitor.visitInteger(this, data);
jjg@46 410 }
jjg@46 411
jjg@46 412 public final int value;
jjg@46 413 }
jjg@46 414
jjg@46 415 public static class CONSTANT_InterfaceMethodref_info extends CPRefInfo {
jjg@46 416 CONSTANT_InterfaceMethodref_info(ConstantPool cp, ClassReader cr) throws IOException {
jjg@46 417 super(cp, cr, CONSTANT_InterfaceMethodref);
jjg@46 418 }
jjg@46 419
jjg@46 420 public CONSTANT_InterfaceMethodref_info(ConstantPool cp, int class_index, int name_and_type_index) {
jjg@46 421 super(cp, CONSTANT_InterfaceMethodref, class_index, name_and_type_index);
jjg@46 422 }
jjg@46 423
jjg@46 424 @Override
jjg@46 425 public String toString() {
jjg@46 426 return "CONSTANT_InterfaceMethodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]";
jjg@46 427 }
jjg@46 428
jjg@46 429 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 430 return visitor.visitInterfaceMethodref(this, data);
jjg@46 431 }
jjg@46 432 }
jjg@46 433
jjg@46 434 public static class CONSTANT_Long_info extends CPInfo {
jjg@46 435 CONSTANT_Long_info(ClassReader cr) throws IOException {
jjg@46 436 value = cr.readLong();
jjg@46 437 }
jjg@46 438
jjg@46 439 public CONSTANT_Long_info(long value) {
jjg@46 440 this.value = value;
jjg@46 441 }
jjg@46 442
jjg@46 443 public int getTag() {
jjg@46 444 return CONSTANT_Long;
jjg@46 445 }
jjg@46 446
jjg@46 447 @Override
jjg@46 448 public String toString() {
jjg@46 449 return "CONSTANT_Long_info[value: " + value + "]";
jjg@46 450 }
jjg@46 451
jjg@46 452 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 453 return visitor.visitLong(this, data);
jjg@46 454 }
jjg@46 455
jjg@46 456 public final long value;
jjg@46 457 }
jjg@46 458
jjg@46 459 public static class CONSTANT_Methodref_info extends CPRefInfo {
jjg@46 460 CONSTANT_Methodref_info(ConstantPool cp, ClassReader cr) throws IOException {
jjg@46 461 super(cp, cr, CONSTANT_Methodref);
jjg@46 462 }
jjg@46 463
jjg@46 464 public CONSTANT_Methodref_info(ConstantPool cp, int class_index, int name_and_type_index) {
jjg@46 465 super(cp, CONSTANT_Methodref, class_index, name_and_type_index);
jjg@46 466 }
jjg@46 467
jjg@46 468 @Override
jjg@46 469 public String toString() {
jjg@46 470 return "CONSTANT_Methodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]";
jjg@46 471 }
jjg@46 472
jjg@46 473 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 474 return visitor.visitMethodref(this, data);
jjg@46 475 }
jjg@46 476 }
jjg@46 477
jjg@46 478 public static class CONSTANT_NameAndType_info extends CPInfo {
jjg@46 479 CONSTANT_NameAndType_info(ConstantPool cp, ClassReader cr) throws IOException {
jjg@46 480 super(cp);
jjg@46 481 name_index = cr.readUnsignedShort();
jjg@46 482 type_index = cr.readUnsignedShort();
jjg@46 483 }
jjg@46 484
jjg@46 485 public CONSTANT_NameAndType_info(ConstantPool cp, int name_index, int type_index) {
jjg@46 486 super(cp);
jjg@46 487 this.name_index = name_index;
jjg@46 488 this.type_index = type_index;
jjg@46 489 }
jjg@46 490
jjg@46 491 public int getTag() {
jjg@46 492 return CONSTANT_NameAndType;
jjg@46 493 }
jjg@46 494
jjg@46 495 public String getName() throws ConstantPoolException {
jjg@46 496 return cp.getUTF8Value(name_index);
jjg@46 497 }
jjg@46 498
jjg@46 499 public String getType() throws ConstantPoolException {
jjg@46 500 return cp.getUTF8Value(type_index);
jjg@46 501 }
jjg@46 502
jjg@46 503 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 504 return visitor.visitNameAndType(this, data);
jjg@46 505 }
jjg@46 506
jjg@46 507 public final int name_index;
jjg@46 508 public final int type_index;
jjg@46 509 }
jjg@46 510
jjg@46 511 public static class CONSTANT_String_info extends CPInfo {
jjg@46 512 CONSTANT_String_info(ClassReader cr) throws IOException {
jjg@46 513 string_index = cr.readUnsignedShort();
jjg@46 514 }
jjg@46 515
jjg@46 516 public CONSTANT_String_info(ConstantPool cp, int string_index) {
jjg@46 517 super(cp);
jjg@46 518 this.string_index = string_index;
jjg@46 519 }
jjg@46 520
jjg@46 521 public int getTag() {
jjg@46 522 return CONSTANT_String;
jjg@46 523 }
jjg@46 524
jjg@46 525 public String getString() throws ConstantPoolException {
jjg@46 526 return cp.getUTF8Value(string_index);
jjg@46 527 }
jjg@46 528
jjg@46 529 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 530 return visitor.visitString(this, data);
jjg@46 531 }
jjg@46 532
jjg@46 533 public final int string_index;
jjg@46 534 }
jjg@46 535
jjg@46 536 public static class CONSTANT_Utf8_info extends CPInfo {
jjg@46 537 CONSTANT_Utf8_info(ClassReader cr) throws IOException {
jjg@46 538 value = cr.readUTF();
jjg@46 539 }
jjg@46 540
jjg@46 541 public CONSTANT_Utf8_info(String value) {
jjg@46 542 this.value = value;
jjg@46 543 }
jjg@46 544
jjg@46 545 public int getTag() {
jjg@46 546 return CONSTANT_Utf8;
jjg@46 547 }
jjg@46 548
jjg@46 549 @Override
jjg@46 550 public String toString() {
jjg@46 551 return "CONSTANT_Utf8_info[value: " + value + "]";
jjg@46 552 }
jjg@46 553
jjg@46 554 public <R, D> R accept(Visitor<R, D> visitor, D data) {
jjg@46 555 return visitor.visitUtf8(this, data);
jjg@46 556 }
jjg@46 557
jjg@46 558 public final String value;
jjg@46 559 }
jjg@46 560
jjg@46 561
jjg@46 562 }

mercurial