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.Const; import org.apache.bcel.classfile.Constant; import org.apache.bcel.classfile.ConstantClass; import org.apache.bcel.classfile.ConstantFieldref; import org.apache.bcel.classfile.ConstantInterfaceMethodref; import org.apache.bcel.classfile.ConstantMethodref; import org.apache.bcel.classfile.ConstantNameAndType; import org.apache.bcel.classfile.ConstantPool; import org.apache.bcel.classfile.ConstantString; import org.apache.bcel.classfile.Method; import org.apache.bcel.classfile.Utility; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: org_apache_bcel_util.jar:org/apache/bcel/util/ConstantHTML.class */ public final class ConstantHTML { private final String className; private final String classPackage; private final ConstantPool constantPool; private final PrintWriter printWriter; private final String[] constantRef; private final Constant[] constants; private final Method[] methods; /* JADX INFO: Access modifiers changed from: package-private */ public ConstantHTML(String dir, String className, String classPackage, Method[] methods, ConstantPool constantPool, Charset charset) throws FileNotFoundException, UnsupportedEncodingException { this.className = className; this.classPackage = classPackage; this.constantPool = constantPool; this.methods = methods; this.constants = constantPool.getConstantPool(); PrintWriter newPrintWriter = new PrintWriter(dir + className + "_cp.html", charset.name()); Throwable th = null; try { try { this.printWriter = newPrintWriter; this.constantRef = new String[this.constants.length]; this.constantRef[0] = "<unknown>"; this.printWriter.print(""); this.printWriter.println(""); for (int i = 1; i < this.constants.length; i++) { if (i % 2 == 0) { this.printWriter.print("\n"); } this.printWriter.println("
"); } else { this.printWriter.print("
"); } if (this.constants[i] != null) { writeConstant(i); } this.printWriter.print("
"); 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 int getMethodNumber(String str) { for (int i = 0; i < this.methods.length; i++) { String cmp = this.methods[i].getName() + this.methods[i].getSignature(); if (cmp.equals(str)) { return i; } } return -1; } /* JADX INFO: Access modifiers changed from: package-private */ public String referenceConstant(int index) { return this.constantRef[index]; } private void writeConstant(int index) { String ref; int classIndex; int nameIndex; String ref2; byte tag = this.constants[index].getTag(); this.printWriter.println("

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

"); switch (tag) { case 7: ConstantClass c4 = this.constantPool.getConstant(index, (byte) 7, ConstantClass.class); int nameIndex2 = c4.getNameIndex(); String className2 = this.constantPool.constantToString(index, tag); String shortClassName = Utility.compactClassName(Utility.compactClassName(className2), this.classPackage + ".", true); String ref3 = "" + shortClassName + ""; this.constantRef[index] = "" + shortClassName + ""; this.printWriter.println("

" + ref3 + "

\n"); return; case 8: ConstantString c5 = this.constantPool.getConstant(index, (byte) 8, ConstantString.class); int nameIndex3 = c5.getStringIndex(); String str = Class2HTML.toHTML(this.constantPool.constantToString(index, tag)); this.printWriter.println("

" + str + "

\n"); return; case 9: ConstantFieldref c3 = this.constantPool.getConstant(index, (byte) 9, ConstantFieldref.class); int classIndex2 = c3.getClassIndex(); int nameIndex4 = c3.getNameAndTypeIndex(); String fieldClass = this.constantPool.constantToString(classIndex2, (byte) 7); String shortFieldClass = Utility.compactClassName(Utility.compactClassName(fieldClass), this.classPackage + ".", true); String fieldName = this.constantPool.constantToString(nameIndex4, (byte) 12); if (fieldClass.equals(this.className)) { ref = "" + fieldName + ""; } else { ref = "" + shortFieldClass + "." + fieldName + "\n"; } this.constantRef[index] = "" + shortFieldClass + "." + fieldName + ""; this.printWriter.println("

" + ref + "
\n

"); return; case 10: case 11: if (tag == 10) { ConstantMethodref c = this.constantPool.getConstant(index, (byte) 10, ConstantMethodref.class); classIndex = c.getClassIndex(); nameIndex = c.getNameAndTypeIndex(); } else { ConstantInterfaceMethodref c1 = this.constantPool.getConstant(index, (byte) 11, ConstantInterfaceMethodref.class); classIndex = c1.getClassIndex(); nameIndex = c1.getNameAndTypeIndex(); } String methodName = this.constantPool.constantToString(nameIndex, (byte) 12); String htmlMethodName = Class2HTML.toHTML(methodName); String methodClass = this.constantPool.constantToString(classIndex, (byte) 7); String shortMethodClass = Utility.compactClassName(Utility.compactClassName(methodClass), this.classPackage + ".", true); ConstantNameAndType c2 = this.constantPool.getConstant(nameIndex, (byte) 12, ConstantNameAndType.class); String signature = this.constantPool.constantToString(c2.getSignatureIndex(), (byte) 1); String[] args = Utility.methodSignatureArgumentTypes(signature, false); String type = Utility.methodSignatureReturnType(signature, false); String retType = 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 argTypes = buf.toString(); if (methodClass.equals(this.className)) { ref2 = "" + htmlMethodName + ""; } else { ref2 = "" + shortMethodClass + "." + htmlMethodName; } this.constantRef[index] = retType + " " + shortMethodClass + "." + htmlMethodName + " " + argTypes; this.printWriter.println("

" + retType + " " + ref2 + argTypes + " \n

"); return; case 12: ConstantNameAndType c6 = this.constantPool.getConstant(index, (byte) 12, ConstantNameAndType.class); int nameIndex5 = c6.getNameIndex(); int signatureIndex = c6.getSignatureIndex(); this.printWriter.println("

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

\n"); return; default: this.printWriter.println("

" + Class2HTML.toHTML(this.constantPool.constantToString(index, tag)) + "\n"); return; } } }