1
3 package jminusminus;
4
5 import java.io.IOException;
6 import java.util.ArrayList;
7
8
15
16 abstract class CLMemberInfo {
17
18
22
23 public int accessFlags;
24
25
26 public int nameIndex;
27
28
29 public int descriptorIndex;
30
31
32 public int attributesCount;
33
34
35 public ArrayList<CLAttributeInfo> attributes;
36
37
51
52 protected CLMemberInfo(int accessFlags, int nameIndex, int descriptorIndex,
53 int attributesCount, ArrayList<CLAttributeInfo> attributes) {
54 this.accessFlags = accessFlags;
55 this.nameIndex = nameIndex;
56 this.descriptorIndex = descriptorIndex;
57 this.attributesCount = attributesCount;
58 this.attributes = attributes;
59 }
60
61
67
68 public void write(CLOutputStream out) throws IOException {
69 out.writeShort(accessFlags);
70 out.writeShort(nameIndex);
71 out.writeShort(descriptorIndex);
72 out.writeShort(attributesCount);
73 for (int i = 0; i < attributes.size(); i++) {
74 CLAttributeInfo attributeInfo = attributes.get(i);
75 attributeInfo.write(out);
76 }
77 }
78
79
86
87 public void writeToStdOut(PrettyPrinter p) {
88 p.indentRight();
89 p.printf("Acces Flags: %s\n", CLFile
90 .fieldAccessFlagsToString(accessFlags));
91 p.printf("Name Index: %d\n", nameIndex);
92 p.printf("Descriptor Index: %d\n", descriptorIndex);
93 p.println();
94 p.printf("// Attributes (%d Items)\n", attributesCount);
95 for (int i = 0; i < attributes.size(); i++) {
96 CLAttributeInfo attributeInfo = attributes.get(i);
97 attributeInfo.writeToStdOut(p);
98 }
99 p.indentLeft();
100 }
101
102 }
103
104
107
108 class CLFieldInfo extends CLMemberInfo {
109
110
124
125 public CLFieldInfo(int accessFlags, int nameIndex, int descriptorIndex,
126 int attributesCount, ArrayList<CLAttributeInfo> attributes) {
127 super(accessFlags, nameIndex, descriptorIndex, attributesCount,
128 attributes);
129 }
130
131
134
135 public void writeToStdOut(PrettyPrinter p) {
136 p.printf("Field {\n");
137 super.writeToStdOut(p);
138 p.printf("}\n");
139 }
140
141 }
142
143
146
147 class CLMethodInfo extends CLMemberInfo {
148
149
163
164 public CLMethodInfo(int accessFlags, int nameIndex, int descriptorIndex,
165 int attributesCount, ArrayList<CLAttributeInfo> attributes) {
166 super(accessFlags, nameIndex, descriptorIndex, attributesCount,
167 attributes);
168 }
169
170
173
174 public void writeToStdOut(PrettyPrinter p) {
175 p.printf("Method {\n");
176 super.writeToStdOut(p);
177 p.printf("}\n");
178 }
179
180 }
181