132 println("Constant pool:"); |
132 println("Constant pool:"); |
133 indent(+1); |
133 indent(+1); |
134 int width = String.valueOf(constant_pool.size()).length() + 1; |
134 int width = String.valueOf(constant_pool.size()).length() + 1; |
135 int cpx = 1; |
135 int cpx = 1; |
136 while (cpx < constant_pool.size()) { |
136 while (cpx < constant_pool.size()) { |
137 print(String.format("const %" + width + "s", ("#" + cpx))); |
137 print(String.format("%" + width + "s", ("#" + cpx))); |
138 try { |
138 try { |
139 CPInfo cpInfo = constant_pool.get(cpx); |
139 CPInfo cpInfo = constant_pool.get(cpx); |
140 print(String.format(" = %-15s ", tagName(cpInfo.getTag()))); |
140 print(String.format(" = %-18s ", cpTagName(cpInfo))); |
141 cpx += cpInfo.accept(v, null); |
141 cpx += cpInfo.accept(v, null); |
142 } catch (ConstantPool.InvalidIndex ex) { |
142 } catch (ConstantPool.InvalidIndex ex) { |
143 // should not happen |
143 // should not happen |
144 } |
144 } |
145 } |
145 } |
176 } |
176 } |
177 } |
177 } |
178 print(tagName(tag) + " " + stringValue(cpInfo)); |
178 print(tagName(tag) + " " + stringValue(cpInfo)); |
179 } |
179 } |
180 |
180 |
|
181 String cpTagName(CPInfo cpInfo) { |
|
182 String n = cpInfo.getClass().getSimpleName(); |
|
183 return n.replace("CONSTANT_", "").replace("_info", ""); |
|
184 } |
|
185 |
181 String tagName(int tag) { |
186 String tagName(int tag) { |
182 switch (tag) { |
187 switch (tag) { |
183 case CONSTANT_Utf8: |
188 case CONSTANT_Utf8: |
184 return "Asciz"; |
189 return "Utf8"; |
185 case CONSTANT_Integer: |
190 case CONSTANT_Integer: |
186 return "int"; |
191 return "int"; |
187 case CONSTANT_Float: |
192 case CONSTANT_Float: |
188 return "float"; |
193 return "float"; |
189 case CONSTANT_Long: |
194 case CONSTANT_Long: |
201 case CONSTANT_InterfaceMethodref: |
206 case CONSTANT_InterfaceMethodref: |
202 return "InterfaceMethod"; |
207 return "InterfaceMethod"; |
203 case CONSTANT_NameAndType: |
208 case CONSTANT_NameAndType: |
204 return "NameAndType"; |
209 return "NameAndType"; |
205 default: |
210 default: |
206 return "unknown tag"; |
211 return "(unknown tag)"; |
207 } |
212 } |
208 } |
213 } |
209 |
214 |
210 String stringValue(int constant_pool_index) { |
215 String stringValue(int constant_pool_index) { |
211 ClassFile classFile = classWriter.getClassFile(); |
216 ClassFile classFile = classWriter.getClassFile(); |