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_NameAndType entry in the constant pool. */
09:
10: public class CpoolNameAndType extends CpoolEntry {
11: CpoolUtf8 name;
12: CpoolUtf8 type;
13:
14: CpoolNameAndType() {
15: }
16:
17: CpoolNameAndType(ConstantPool cpool, int hash, CpoolUtf8 n,
18: CpoolUtf8 t) {
19: super (cpool, hash);
20: name = n;
21: type = t;
22: }
23:
24: public int getTag() {
25: return ConstantPool.NAME_AND_TYPE;
26: }
27:
28: public final CpoolUtf8 getName() {
29: return name;
30: }
31:
32: public final CpoolUtf8 getType() {
33: return type;
34: }
35:
36: final static int hashCode(CpoolUtf8 name, CpoolUtf8 type) {
37: return name.hashCode() ^ type.hashCode();
38: }
39:
40: public int hashCode() {
41: if (hash == 0)
42: hash = hashCode(name, type);
43: return hash;
44: }
45:
46: void write(DataOutputStream dstr) throws java.io.IOException {
47: dstr.writeByte(ConstantPool.NAME_AND_TYPE);
48: dstr.writeShort(name.index);
49: dstr.writeShort(type.index);
50: }
51:
52: public void print(ClassTypeWriter dst, int verbosity) {
53: if (verbosity == 1)
54: dst.print("NameAndType ");
55: else if (verbosity > 1) {
56: dst.print("NameAndType name: ");
57: dst.printOptionalIndex(name);
58: }
59: dst.printName(name.string);
60: if (verbosity <= 1)
61: dst.print(' ');
62: else {
63: dst.print(", signature: ");
64: dst.printOptionalIndex(type);
65: }
66: dst.printSignature(type.string);
67: }
68: }
|