01: // Copyright (c) 1997 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.bytecode;
05:
06: import java.io.*;
07:
08: /** A CONSTANT_Class entry in the constant pool. */
09:
10: public class CpoolClass extends CpoolEntry {
11: CpoolUtf8 name;
12:
13: CpoolClass() {
14: }
15:
16: CpoolClass(ConstantPool cpool, int hash, CpoolUtf8 n) {
17: super (cpool, hash);
18: name = n;
19: }
20:
21: public int getTag() {
22: return ConstantPool.CLASS;
23: }
24:
25: public final CpoolUtf8 getName() {
26: return name;
27: }
28:
29: /** Get name of the class as a String. */
30: public final String getStringName() {
31: return name.string;
32: }
33:
34: /** Get corresponding ObjectType (ClassType or ArrayType). */
35: public final ObjectType getClassType() {
36: String name = this .name.string;
37: if (name.charAt(0) == '[')
38: return (ObjectType) Type.signatureToType(name);
39: else
40: return ClassType.make(name.replace('/', '.'));
41: }
42:
43: final static int hashCode(CpoolUtf8 name) {
44: return name.hashCode() ^ 0xF0F;
45: }
46:
47: public int hashCode() {
48: if (hash == 0)
49: hash = hashCode(name);
50: return hash;
51: }
52:
53: void write(DataOutputStream dstr) throws java.io.IOException {
54: dstr.writeByte(ConstantPool.CLASS);
55: dstr.writeShort(name.index);
56: }
57:
58: public void print(ClassTypeWriter dst, int verbosity) {
59: if (verbosity == 1)
60: dst.print("Class ");
61: else if (verbosity > 1) {
62: dst.print("Class name: ");
63: dst.printOptionalIndex(name);
64: }
65: dst.print(name.string.replace('/', '.'));
66: }
67: }
|