package com.sun.org.apache.bcel.internal.util; import com.sun.org.apache.bcel.internal.classfile.ExceptionTable; import com.sun.org.apache.bcel.internal.classfile.Code; import com.sun.org.apache.bcel.internal.classfile.Attribute; import com.sun.org.apache.bcel.internal.classfile.ConstantValue; import com.sun.org.apache.bcel.internal.classfile.Utility; import java.io.IOException; import java.io.FileOutputStream; import com.sun.org.apache.bcel.internal.classfile.Field; import com.sun.org.apache.bcel.internal.classfile.Method; import java.io.PrintWriter; final class MethodHTML { private final String class_name; private final PrintWriter file; private final ConstantHTML constant_html; private final AttributeHTML attribute_html; MethodHTML(String dir, String class_name, Method[] methods, Field[] fields, ConstantHTML constant_html, AttributeHTML attribute_html) throws IOException { this.class_name = class_name; this.attribute_html = attribute_html; this.constant_html = constant_html; (this.file = new PrintWriter(new FileOutputStream(dir + class_name + "_methods.html"))).println(""); this.file.println(""); for (Field field : fields) { this.writeField(field); } this.file.println("
Access flagsTypeField name
"); this.file.println(""); for (int i = 0; i < methods.length; ++i) { this.writeMethod(methods[i], i); } this.file.println("
Access flagsReturn typeMethod nameArguments
"); this.file.close(); } private void writeField(Field field) throws IOException { String type = Utility.signatureToString(field.getSignature()); String name = field.getName(); String access = Utility.accessToString(field.getAccessFlags()); access = Utility.replace(access, " ", " "); this.file.print("" + access + "\n" + Class2HTML.referenceType(type) + "" + name + ""); Attribute[] attributes = field.getAttributes(); for (int i = 0; i < attributes.length; ++i) { this.attribute_html.writeAttribute(attributes[i], name + "@" + i); } int i = 0; while (i < attributes.length) { if (attributes[i].getTag() == 1) { String str = ((ConstantValue)attributes[i]).toString(); this.file.print("= " + str + "\n"); break; } ++i; } this.file.println(""); } private void writeMethod(Method method, int method_number) { String signature = method.getSignature(); String[] args = Utility.methodSignatureArgumentTypes(signature, false); String type = Utility.methodSignatureReturnType(signature, false); String name = method.getName(); String access = Utility.accessToString(method.getAccessFlags()); Attribute[] attributes = method.getAttributes(); access = Utility.replace(access, " ", " "); String html_name = Class2HTML.toHTML(name); this.file.print("" + access + ""); this.file.print("" + Class2HTML.referenceType(type) + "" + html_name + "\n("); for (int i = 0; i < args.length; ++i) { this.file.print(Class2HTML.referenceType(args[i])); if (i < args.length - 1) { this.file.print(", "); } } this.file.print(")"); for (int i = 0; i < attributes.length; ++i) { this.attribute_html.writeAttribute(attributes[i], "method" + method_number + "@" + i, method_number); byte tag = attributes[i].getTag(); if (tag == 3) { this.file.print("throws"); int[] exceptions = ((ExceptionTable)attributes[i]).getExceptionIndexTable(); for (int j = 0; j < exceptions.length; ++j) { this.file.print(this.constant_html.referenceConstant(exceptions[j])); if (j < exceptions.length - 1) { this.file.print(", "); } } this.file.println(""); } else if (tag == 2) { Attribute[] c_a = ((Code)attributes[i]).getAttributes(); for (int j = 0; j < c_a.length; ++j) { this.attribute_html.writeAttribute(c_a[j], "method" + method_number + "@" + i + "@" + j, method_number); } } } } }