package org.apache.bcel.util; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.Set; import org.apache.bcel.Constants; import org.apache.bcel.classfile.Attribute; import org.apache.bcel.classfile.ClassParser; import org.apache.bcel.classfile.ConstantPool; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; import org.apache.bcel.classfile.Utility; /* loaded from: org_apache_bcel_util.jar:org/apache/bcel/util/Class2HTML.class */ public class Class2HTML implements Constants { private static String classPackage; private static String className; private static ConstantPool constantPool; private static final Set basicTypes = new HashSet(); private final JavaClass javaClass; private final String dir; static { basicTypes.add("int"); basicTypes.add("short"); basicTypes.add("boolean"); basicTypes.add("void"); basicTypes.add("char"); basicTypes.add("byte"); basicTypes.add("long"); basicTypes.add("double"); basicTypes.add("float"); } public static void main(String[] argv) throws IOException { ClassParser classParser; String[] fileName = new String[argv.length]; int files = 0; String zipFile = null; char sep = File.separatorChar; String dir = "." + sep; int i = 0; while (i < argv.length) { if (argv[i].charAt(0) == '-') { if (argv[i].equals("-d")) { i++; dir = argv[i]; if (!dir.endsWith("" + sep)) { dir = dir + sep; } File store = new File(dir); if (!store.isDirectory()) { boolean created = store.mkdirs(); if (!created && !store.isDirectory()) { System.out.println("Tried to create the directory " + dir + " but failed"); } } } else if (argv[i].equals("-zip")) { i++; zipFile = argv[i]; } else { System.out.println("Unknown option " + argv[i]); } } else { int i2 = files; files++; fileName[i2] = argv[i]; } i++; } if (files == 0) { System.err.println("Class2HTML: No input files specified."); return; } for (int i3 = 0; i3 < files; i3++) { System.out.print("Processing " + fileName[i3] + "..."); if (zipFile == null) { classParser = new ClassParser(fileName[i3]); } else { classParser = new ClassParser(zipFile, fileName[i3]); } ClassParser parser = classParser; JavaClass javaClass = parser.parse(); new Class2HTML(javaClass, dir); System.out.println("Done."); } } /* JADX INFO: Access modifiers changed from: package-private */ public static String referenceClass(int index) { String str = constantPool.getConstantString(index, (byte) 7); return "" + Utility.compactClassName(Utility.compactClassName(str), classPackage + ".", true) + ""; } /* JADX INFO: Access modifiers changed from: package-private */ public static String referenceType(String type) { String shortType = Utility.compactClassName(type); String shortType2 = Utility.compactClassName(shortType, classPackage + ".", true); int index = type.indexOf(91); String baseType = type; if (index > -1) { baseType = type.substring(0, index); } if (basicTypes.contains(baseType)) { return "" + type + ""; } return "" + shortType2 + ""; } /* JADX INFO: Access modifiers changed from: package-private */ public static String toHTML(String str) { StringBuilder buf = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); switch (ch) { case '\n': buf.append("\\n"); break; case '\r': buf.append("\\r"); break; case '<': buf.append("<"); break; case '>': buf.append(">"); break; default: buf.append(ch); break; } } return buf.toString(); } public Class2HTML(JavaClass javaClass, String dir) throws IOException { this(javaClass, dir, StandardCharsets.UTF_8); } private Class2HTML(JavaClass javaClass, String dir, Charset charset) throws IOException { Method[] methods = javaClass.getMethods(); this.javaClass = javaClass; this.dir = dir; className = javaClass.getClassName(); constantPool = javaClass.getConstantPool(); int index = className.lastIndexOf(46); if (index > -1) { classPackage = className.substring(0, index); } else { classPackage = ""; } ConstantHTML constantHtml = new ConstantHTML(dir, className, classPackage, methods, constantPool, charset); AttributeHTML attributeHtml = new AttributeHTML(dir, className, constantPool, constantHtml, charset); Throwable th = null; try { try { new MethodHTML(dir, className, methods, javaClass.getFields(), constantHtml, attributeHtml, charset); writeMainHTML(attributeHtml, charset); new CodeHTML(dir, className, methods, constantPool, constantHtml, charset); if (attributeHtml != null) { if (0 != 0) { try { attributeHtml.close(); return; } catch (Throwable th2) { th.addSuppressed(th2); return; } } attributeHtml.close(); } } catch (Throwable th3) { th = th3; throw th3; } } catch (Throwable th4) { if (attributeHtml != null) { if (th != null) { try { attributeHtml.close(); } catch (Throwable th5) { th.addSuppressed(th5); } } else { attributeHtml.close(); } } throw th4; } } private void writeMainHTML(AttributeHTML attributeHtml, Charset charset) throws FileNotFoundException, UnsupportedEncodingException { PrintWriter file = new PrintWriter(this.dir + className + ".html", charset.name()); Throwable th = null; try { file.println("\nDocumentation for " + className + "\n\n\n\n\n\n\n\n\n"); if (file != null) { if (0 != 0) { try { file.close(); } catch (Throwable th2) { th.addSuppressed(th2); } } else { file.close(); } } Attribute[] attributes = this.javaClass.getAttributes(); for (int i = 0; i < attributes.length; i++) { attributeHtml.writeAttribute(attributes[i], "class" + i); } } catch (Throwable th3) { if (file != null) { if (0 != 0) { try { file.close(); } catch (Throwable th4) { th.addSuppressed(th4); } } else { file.close(); } } throw th3; } } }