package org.apache.bcel.util;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import org.apache.bcel.classfile.Attribute;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.ExceptionTable;
import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.classfile.Utility;
/* loaded from: org_apache_bcel_util.jar:org/apache/bcel/util/MethodHTML.class */
final class MethodHTML {
private final String className;
private final PrintWriter printWriter;
private final ConstantHTML constantHtml;
private final AttributeHTML attributeHtml;
/* JADX INFO: Access modifiers changed from: package-private */
public MethodHTML(String dir, String className, Method[] methods, Field[] fields, ConstantHTML constantHtml, AttributeHTML attributeHtml, Charset charset) throws FileNotFoundException, UnsupportedEncodingException {
this.className = className;
this.attributeHtml = attributeHtml;
this.constantHtml = constantHtml;
PrintWriter newPrintWriter = new PrintWriter(dir + className + "_methods.html", charset.name());
Throwable th = null;
try {
try {
this.printWriter = newPrintWriter;
this.printWriter.print("
");
this.printWriter.println("");
this.printWriter.println("Access flags | Type | Field name |
");
for (Field field : fields) {
writeField(field);
}
this.printWriter.println("
");
this.printWriter.println("Access flags | Return type | Method name | Arguments |
");
for (int i = 0; i < methods.length; i++) {
writeMethod(methods[i], i);
}
this.printWriter.println("
");
if (newPrintWriter != null) {
if (0 != 0) {
try {
newPrintWriter.close();
return;
} catch (Throwable th2) {
th.addSuppressed(th2);
return;
}
}
newPrintWriter.close();
}
} catch (Throwable th3) {
th = th3;
throw th3;
}
} catch (Throwable th4) {
if (newPrintWriter != null) {
if (th != null) {
try {
newPrintWriter.close();
} catch (Throwable th5) {
th.addSuppressed(th5);
}
} else {
newPrintWriter.close();
}
}
throw th4;
}
}
private void writeField(Field field) {
String type = Utility.signatureToString(field.getSignature());
String name = field.getName();
String access = Utility.accessToString(field.getAccessFlags());
this.printWriter.print("" + Utility.replace(access, " ", " ") + " | \n" + Class2HTML.referenceType(type) + " | " + name + " | ");
Attribute[] attributes = field.getAttributes();
for (int i = 0; i < attributes.length; i++) {
this.attributeHtml.writeAttribute(attributes[i], name + "@" + i);
}
int i2 = 0;
while (true) {
if (i2 >= attributes.length) {
break;
}
if (attributes[i2].getTag() != 1) {
i2++;
} else {
String str = attributes[i2].toString();
this.printWriter.print("= " + str + " | \n");
break;
}
}
this.printWriter.println("
");
}
private void writeMethod(Method method, int methodNumber) {
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());
ExceptionTable[] attributes = method.getAttributes();
String access2 = Utility.replace(access, " ", " ");
String htmlName = Class2HTML.toHTML(name);
this.printWriter.print("" + access2 + " | ");
this.printWriter.print("" + Class2HTML.referenceType(type) + " | " + htmlName + " | \n(");
for (int i = 0; i < args.length; i++) {
this.printWriter.print(Class2HTML.referenceType(args[i]));
if (i < args.length - 1) {
this.printWriter.print(", ");
}
}
this.printWriter.print(") |
");
for (int i2 = 0; i2 < attributes.length; i2++) {
this.attributeHtml.writeAttribute(attributes[i2], "method" + methodNumber + "@" + i2, methodNumber);
byte tag = attributes[i2].getTag();
if (tag == 3) {
this.printWriter.print(" | throws | ");
int[] exceptions = attributes[i2].getExceptionIndexTable();
for (int j = 0; j < exceptions.length; j++) {
this.printWriter.print(this.constantHtml.referenceConstant(exceptions[j]));
if (j < exceptions.length - 1) {
this.printWriter.print(", ");
}
}
this.printWriter.println(" |
");
} else if (tag == 2) {
Attribute[] attributeArray = ((Code) attributes[i2]).getAttributes();
for (int j2 = 0; j2 < attributeArray.length; j2++) {
this.attributeHtml.writeAttribute(attributeArray[j2], "method" + methodNumber + "@" + i2 + "@" + j2, methodNumber);
}
}
}
}
}