package com.sun.org.apache.bcel.internal.util; import com.sun.org.apache.bcel.internal.classfile.ConstantString; import com.sun.org.apache.bcel.internal.classfile.ConstantClass; import com.sun.org.apache.bcel.internal.classfile.ConstantFieldref; import com.sun.org.apache.bcel.internal.classfile.ConstantNameAndType; import com.sun.org.apache.bcel.internal.classfile.Utility; import com.sun.org.apache.bcel.internal.classfile.ConstantMethodref; import com.sun.org.apache.bcel.internal.classfile.ConstantInterfaceMethodref; import com.sun.org.apache.bcel.internal.Const; import java.io.IOException; import java.io.FileOutputStream; import com.sun.org.apache.bcel.internal.classfile.Method; import com.sun.org.apache.bcel.internal.classfile.Constant; import java.io.PrintWriter; import com.sun.org.apache.bcel.internal.classfile.ConstantPool; final class ConstantHTML { private final String class_name; private final String class_package; private final ConstantPool constant_pool; private final PrintWriter file; private final String[] constant_ref; private final Constant[] constants; private final Method[] methods; ConstantHTML(String dir, String class_name, String class_package, Method[] methods, ConstantPool constant_pool) throws IOException { this.class_name = class_name; this.class_package = class_package; this.constant_pool = constant_pool; this.methods = methods; this.constants = constant_pool.getConstantPool(); this.file = new PrintWriter(new FileOutputStream(dir + class_name + "_cp.html")); (this.constant_ref = new String[this.constants.length])[0] = "<unknown>"; this.file.println(""); for (int i = 1; i < this.constants.length; ++i) { if (i % 2 == 0) { this.file.print("\n"); } this.file.println("
"); } else { this.file.print("
"); } if (this.constants[i] != null) { this.writeConstant(i); } this.file.print("
"); this.file.close(); } String referenceConstant(int index) { return this.constant_ref[index]; } private void writeConstant(int index) { byte tag = this.constants[index].getTag(); this.file.println("

" + index + " " + Const.getConstantName((int)tag) + "

"); switch (tag) { case 10: case 11: { int class_index; int name_index; if (tag == 10) { ConstantMethodref c2 = (ConstantMethodref)this.constant_pool.getConstant(index, (byte)10); class_index = c2.getClassIndex(); name_index = c2.getNameAndTypeIndex(); } else { ConstantInterfaceMethodref c1 = (ConstantInterfaceMethodref)this.constant_pool.getConstant(index, (byte)11); class_index = c1.getClassIndex(); name_index = c1.getNameAndTypeIndex(); } String method_name = this.constant_pool.constantToString(name_index, (byte)12); String html_method_name = Class2HTML.toHTML(method_name); String method_class = this.constant_pool.constantToString(class_index, (byte)7); String short_method_class = Utility.compactClassName(method_class); short_method_class = Utility.compactClassName(short_method_class, this.class_package + ".", true); ConstantNameAndType c3 = (ConstantNameAndType)this.constant_pool.getConstant(name_index, (byte)12); String signature = this.constant_pool.constantToString(c3.getSignatureIndex(), (byte)1); String[] args = Utility.methodSignatureArgumentTypes(signature, false); String type = Utility.methodSignatureReturnType(signature, false); String ret_type = Class2HTML.referenceType(type); StringBuilder buf = new StringBuilder("("); for (int i = 0; i < args.length; ++i) { buf.append(Class2HTML.referenceType(args[i])); if (i < args.length - 1) { buf.append(", "); } } buf.append(")"); String arg_types = buf.toString(); String ref; if (method_class.equals(this.class_name)) { ref = "" + html_method_name + ""; } else { ref = "" + short_method_class + "." + html_method_name; } this.constant_ref[index] = ret_type + " " + short_method_class + "." + html_method_name + " " + arg_types; this.file.println("

" + ret_type + " " + ref + arg_types + " \n

"); break; } case 9: { ConstantFieldref c4 = (ConstantFieldref)this.constant_pool.getConstant(index, (byte)9); int class_index = c4.getClassIndex(); int name_index = c4.getNameAndTypeIndex(); String field_class = this.constant_pool.constantToString(class_index, (byte)7); String short_field_class = Utility.compactClassName(field_class); short_field_class = Utility.compactClassName(short_field_class, this.class_package + ".", true); String field_name = this.constant_pool.constantToString(name_index, (byte)12); String ref; if (field_class.equals(this.class_name)) { ref = "" + field_name + ""; } else { ref = "" + short_field_class + "." + field_name + "\n"; } this.constant_ref[index] = "" + short_field_class + "." + field_name + ""; this.file.println("

" + ref + "
\n

"); break; } case 7: { ConstantClass c5 = (ConstantClass)this.constant_pool.getConstant(index, (byte)7); int name_index = c5.getNameIndex(); String class_name2 = this.constant_pool.constantToString(index, tag); String short_class_name = Utility.compactClassName(class_name2); short_class_name = Utility.compactClassName(short_class_name, this.class_package + ".", true); String ref = "" + short_class_name + ""; this.constant_ref[index] = "" + short_class_name + ""; this.file.println("

" + ref + "

\n"); break; } case 8: { ConstantString c6 = (ConstantString)this.constant_pool.getConstant(index, (byte)8); int name_index = c6.getStringIndex(); String str = Class2HTML.toHTML(this.constant_pool.constantToString(index, tag)); this.file.println("

" + str + "

\n"); break; } case 12: { ConstantNameAndType c7 = (ConstantNameAndType)this.constant_pool.getConstant(index, (byte)12); int name_index = c7.getNameIndex(); int signature_index = c7.getSignatureIndex(); this.file.println("

" + Class2HTML.toHTML(this.constant_pool.constantToString(index, tag)) + "

\n"); break; } default: { this.file.println("

" + Class2HTML.toHTML(this.constant_pool.constantToString(index, tag)) + "\n"); break; } } } private int getMethodNumber(String str) { int i = 0; while (i < this.methods.length) { String cmp = this.methods[i].getName() + this.methods[i].getSignature(); if (cmp.equals(str)) { return i; } ++i; } return -1; } }