01: // Copyright (c) 1998 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.bytecode;
05:
06: public class InnerClassesAttr extends Attribute {
07: short count;
08: short[] data;
09:
10: /** Add a new InnerClassesAttr to a ClassType. */
11: public InnerClassesAttr(ClassType cl) {
12: super ("InnerClasses");
13: addToFrontOf(cl);
14: }
15:
16: public InnerClassesAttr(short[] data, ClassType cl) {
17: this (cl);
18: count = (short) (data.length >> 2);
19: this .data = data;
20: }
21:
22: /** Return the length of the attribute in bytes.
23: * Does not include the 6-byte header (for the name_index and the length).*/
24: public int getLength() {
25: return 2 + 8 * count;
26: }
27:
28: /** Write out the contents of the Attribute.
29: * Does not write the 6-byte attribute header. */
30: public void write(java.io.DataOutputStream dstr)
31: throws java.io.IOException {
32: dstr.writeShort(count);
33: for (int i = 0; i < count; i++) {
34: dstr.writeShort(data[2 * i]); // inner_class_info_index
35: dstr.writeShort(data[2 * i + 1]); // outer_class_info_index
36: dstr.writeShort(data[2 * i + 2]); // inner_name_index
37: dstr.writeShort(data[2 * i + 3]); // inner_class_access_flags
38: }
39: }
40:
41: public void print(ClassTypeWriter dst) {
42: ClassType ctype = (ClassType) container;
43: ConstantPool constants = ctype.getConstants();
44: dst.print("Attribute \"");
45: dst.print(getName());
46: dst.print("\", length:");
47: dst.print(getLength());
48: dst.print(", count: ");
49: dst.println(count);
50: for (int i = 0; i < count; i++) {
51: dst.print(" ");
52: int index;
53: index = data[4 * i] & 0xFFFF; // inner_class_info_index
54: CpoolEntry centry = constants.getForced(index,
55: ConstantPool.CLASS);
56: dst.print(((CpoolClass) centry).getStringName());
57: dst.print("; ");
58:
59: index = data[4 * i + 1] & 0xFFFF; // outer_class_info_index
60: if (index != 0) {
61: dst.print("Member of ");
62: centry = constants.getForced(index, ConstantPool.CLASS);
63: dst.print(((CpoolClass) centry).getStringName());
64: }
65: dst.print("; ");
66:
67: index = data[4 * i + 2] & 0xFFFF; // inner_name_index
68: if (index != 0) {
69: centry = constants.getForced(index, ConstantPool.UTF8);
70: dst.print(((CpoolUtf8) centry).string);
71: } else
72: dst.print("(Anonymous)");
73: dst.print(";");
74:
75: dst.print(Access.toString(data[4 * i + 3] & 0xFFFF));
76: dst.println();
77: }
78: }
79: }
|