package com.sun.org.apache.bcel.internal.util;
import com.sun.org.apache.bcel.internal.classfile.InnerClass;
import com.sun.org.apache.bcel.internal.classfile.LocalVariable;
import com.sun.org.apache.bcel.internal.classfile.LineNumber;
import com.sun.org.apache.bcel.internal.classfile.CodeException;
import com.sun.org.apache.bcel.internal.classfile.InnerClasses;
import com.sun.org.apache.bcel.internal.classfile.Utility;
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8;
import com.sun.org.apache.bcel.internal.classfile.LocalVariableTable;
import com.sun.org.apache.bcel.internal.classfile.LineNumberTable;
import com.sun.org.apache.bcel.internal.classfile.ExceptionTable;
import com.sun.org.apache.bcel.internal.classfile.SourceFile;
import com.sun.org.apache.bcel.internal.classfile.ConstantValue;
import com.sun.org.apache.bcel.internal.classfile.Code;
import com.sun.org.apache.bcel.internal.Const;
import com.sun.org.apache.bcel.internal.classfile.Attribute;
import java.io.IOException;
import java.io.FileOutputStream;
import com.sun.org.apache.bcel.internal.classfile.ConstantPool;
import java.io.PrintWriter;
final class AttributeHTML
{
private final String class_name;
private final PrintWriter file;
private int attr_count;
private final ConstantHTML constant_html;
private final ConstantPool constant_pool;
AttributeHTML(String dir, String class_name, ConstantPool constant_pool, ConstantHTML constant_html) throws IOException {
this.attr_count = 0;
this.class_name = class_name;
this.constant_pool = constant_pool;
this.constant_html = constant_html;
(this.file = new PrintWriter(new FileOutputStream(dir + class_name + "_attributes.html"))).println("
");
}
private String codeLink(int link, int method_number) {
return "" + link + "";
}
final void close() {
this.file.println("
");
this.file.close();
}
final void writeAttribute(Attribute attribute, String anchor) {
this.writeAttribute(attribute, anchor, 0);
}
final void writeAttribute(Attribute attribute, String anchor, int method_number) {
byte tag = attribute.getTag();
if (tag == -1) {
return;
}
++this.attr_count;
if (this.attr_count % 2 == 0) {
this.file.print("");
}
else {
this.file.print(" |
");
}
this.file.println("");
switch (tag) {
case 2: {
Code c = (Code)attribute;
this.file.print("- Maximum stack size = " + c.getMaxStack() + "
\n- Number of local variables = " + c.getMaxLocals() + "
\n- Byte code
\n");
CodeException[] ce = c.getExceptionTable();
int len = ce.length;
if (len > 0) {
this.file.print("Exceptions handled ");
for (CodeException cex : ce) {
int catch_type = cex.getCatchType();
this.file.print("- ");
if (catch_type != 0) {
this.file.print(this.constant_html.referenceConstant(catch_type));
}
else {
this.file.print("Any Exception");
}
this.file.print("
(Ranging from lines " + this.codeLink(cex.getStartPC(), method_number) + " to " + this.codeLink(cex.getEndPC(), method_number) + ", handled at line " + this.codeLink(cex.getHandlerPC(), method_number) + ") ");
}
this.file.print(" ");
break;
}
break;
}
case 1: {
int index = ((ConstantValue)attribute).getConstantValueIndex();
this.file.print("\n");
break;
}
case 0: {
int index = ((SourceFile)attribute).getSourceFileIndex();
this.file.print("\n");
break;
}
case 3: {
int[] indices = ((ExceptionTable)attribute).getExceptionIndexTable();
this.file.print("\n");
break;
}
case 4: {
LineNumber[] line_numbers = ((LineNumberTable)attribute).getLineNumberTable();
this.file.print("");
for (int i = 0; i < line_numbers.length; ++i) {
this.file.print("(" + line_numbers[i].getStartPC() + ", " + line_numbers[i].getLineNumber() + ")");
if (i < line_numbers.length - 1) {
this.file.print(", ");
}
}
break;
}
case 5: {
LocalVariable[] vars = ((LocalVariableTable)attribute).getLocalVariableTable();
this.file.print(" ");
for (LocalVariable var : vars) {
int index = var.getSignatureIndex();
String signature = ((ConstantUtf8)this.constant_pool.getConstant(index, (byte)1)).getBytes();
signature = Utility.signatureToString(signature, false);
int start = var.getStartPC();
int end = start + var.getLength();
this.file.println("- " + Class2HTML.referenceType(signature) + " " + var.getName() + " in slot %" + var.getIndex() + "
Valid from lines " + start + " to " + end + " ");
}
this.file.print(" \n");
break;
}
case 6: {
InnerClass[] classes = ((InnerClasses)attribute).getInnerClasses();
this.file.print("");
for (InnerClass classe : classes) {
int index = classe.getInnerNameIndex();
String name;
if (index > 0) {
name = ((ConstantUtf8)this.constant_pool.getConstant(index, (byte)1)).getBytes();
}
else {
name = "<anonymous>";
}
String access = Utility.accessToString(classe.getInnerAccessFlags());
this.file.print("- " + access + " " + this.constant_html.referenceConstant(classe.getInnerClassIndex()) + " in class " + this.constant_html.referenceConstant(classe.getOuterClassIndex()) + " named " + name + "
\n");
}
this.file.print(" \n");
break;
}
default: {
this.file.print("" + attribute);
break;
}
}
this.file.println(" |
");
this.file.flush();
return;
}
}