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_String entry in the constant pool. */
09:
10: public class CpoolString extends CpoolEntry {
11: CpoolUtf8 str;
12:
13: CpoolString() {
14: }
15:
16: CpoolString(ConstantPool cpool, int hash, CpoolUtf8 str) {
17: super (cpool, hash);
18: this .str = str;
19: }
20:
21: public int getTag() {
22: return ConstantPool.STRING;
23: }
24:
25: public final CpoolUtf8 getString() {
26: return str;
27: }
28:
29: final static int hashCode(CpoolUtf8 str) {
30: return str.hashCode() ^ 0xF30F;
31: }
32:
33: public int hashCode() {
34: if (hash == 0)
35: hash = hashCode(str);
36: return hash;
37: }
38:
39: void write(DataOutputStream dstr) throws java.io.IOException {
40: dstr.writeByte(ConstantPool.STRING);
41: dstr.writeShort(str.index);
42: }
43:
44: public void print(ClassTypeWriter dst, int verbosity) {
45: if (verbosity > 0) {
46: dst.print("String ");
47: if (verbosity == 2)
48: dst.printOptionalIndex(str);
49: }
50: dst.printConstantTersely(str.index, 1);
51: }
52: }
|