1 package com.sun.org.apache.bcel.internal.util; 2 3 56 57 import com.sun.org.apache.bcel.internal.classfile.*; 58 import java.io.*; 59 60 67 final class AttributeHTML implements com.sun.org.apache.bcel.internal.Constants { 68 private String class_name; private PrintWriter file; private int attr_count = 0; 71 private ConstantHTML constant_html; 72 private ConstantPool constant_pool; 73 74 AttributeHTML(String dir, String class_name, ConstantPool constant_pool, 75 ConstantHTML constant_html) throws IOException 76 { 77 this.class_name = class_name; 78 this.constant_pool = constant_pool; 79 this.constant_html = constant_html; 80 81 file = new PrintWriter(new FileOutputStream(dir + class_name + "_attributes.html")); 82 file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>"); 83 } 84 85 private final String codeLink(int link, int method_number) { 86 return "<A HREF=\"" + class_name + "_code.html#code" + 87 method_number + "@" + link + "\" TARGET=Code>" + 88 link + "</A>"; 89 } 90 91 final void close() { 92 file.println("</TABLE></BODY></HTML>"); 93 file.close(); 94 } 95 96 final void writeAttribute(Attribute attribute, String anchor) throws IOException { 97 writeAttribute(attribute, anchor, 0); 98 } 99 100 final void writeAttribute(Attribute attribute, String anchor, int method_number) throws IOException { 101 byte tag = attribute.getTag(); 102 int index; 103 104 if(tag == ATTR_UNKNOWN) return; 106 107 attr_count++; 109 if(attr_count % 2 == 0) 110 file.print("<TR BGCOLOR=\"#C0C0C0\"><TD>"); 111 else 112 file.print("<TR BGCOLOR=\"#A0A0A0\"><TD>"); 113 114 file.println("<H4><A NAME=\"" + anchor + "\">" + attr_count + " " + ATTRIBUTE_NAMES[tag] + "</A></H4>"); 115 116 118 switch(tag) { 119 case ATTR_CODE: 120 Code c = (Code)attribute; 121 Attribute[] attributes = c.getAttributes(); 122 123 file.print("<UL><LI>Maximum stack size = " + c.getMaxStack() + 125 "</LI>\n<LI>Number of local variables = " + 126 c.getMaxLocals() + "</LI>\n<LI><A HREF=\"" + class_name + 127 "_code.html#method" + method_number + "\" TARGET=Code>Byte code</A></LI></UL>\n"); 128 129 CodeException[] ce = c.getExceptionTable(); 131 int len = ce.length; 132 133 if(len > 0) { 134 file.print("<P><B>Exceptions handled</B><UL>"); 135 136 for(int i=0; i < len; i++) { 137 int catch_type = ce[i].getCatchType(); 139 file.print("<LI>"); 140 141 if(catch_type != 0) 142 file.print(constant_html.referenceConstant(catch_type)); else 144 file.print("Any Exception"); 145 146 file.print("<BR>(Ranging from lines " + codeLink(ce[i].getStartPC(), method_number) + 147 " to " + codeLink(ce[i].getEndPC(), method_number) + ", handled at line " + 148 codeLink(ce[i].getHandlerPC(), method_number) + ")</LI>"); 149 } 150 file.print("</UL>"); 151 } 152 break; 153 154 case ATTR_CONSTANT_VALUE: 155 index = ((ConstantValue)attribute).getConstantValueIndex(); 156 157 file.print("<UL><LI><A HREF=\"" + class_name + "_cp.html#cp" + index + 159 "\" TARGET=\"ConstantPool\">Constant value index(" + index +")</A></UL>\n"); 160 break; 161 162 case ATTR_SOURCE_FILE: 163 index = ((SourceFile)attribute).getSourceFileIndex(); 164 165 file.print("<UL><LI><A HREF=\"" + class_name + "_cp.html#cp" + index + 167 "\" TARGET=\"ConstantPool\">Source file index(" + index +")</A></UL>\n"); 168 break; 169 170 case ATTR_EXCEPTIONS: 171 int[] indices = ((ExceptionTable)attribute).getExceptionIndexTable(); 173 174 file.print("<UL>"); 175 176 for(int i=0; i < indices.length; i++) 177 file.print("<LI><A HREF=\"" + class_name + "_cp.html#cp" + indices[i] + 178 "\" TARGET=\"ConstantPool\">Exception class index(" + indices[i] + ")</A>\n"); 179 180 file.print("</UL>\n"); 181 break; 182 183 case ATTR_LINE_NUMBER_TABLE: 184 LineNumber[] line_numbers =((LineNumberTable)attribute).getLineNumberTable(); 185 186 file.print("<P>"); 188 189 for(int i=0; i < line_numbers.length; i++) { 190 file.print("(" + line_numbers[i].getStartPC() + ", " + line_numbers[i].getLineNumber() + ")"); 191 192 if(i < line_numbers.length - 1) 193 file.print(", "); } 195 break; 196 197 case ATTR_LOCAL_VARIABLE_TABLE: 198 LocalVariable[] vars = ((LocalVariableTable)attribute).getLocalVariableTable(); 199 200 file.print("<UL>"); 202 203 for(int i=0; i < vars.length; i++) { 204 index = vars[i].getSignatureIndex(); 205 String signature = ((ConstantUtf8)constant_pool.getConstant(index, CONSTANT_Utf8)).getBytes(); 206 signature = Utility.signatureToString(signature, false); 207 int start = vars[i].getStartPC(); 208 int end = (start + vars[i].getLength()); 209 210 file.println("<LI>" + Class2HTML.referenceType(signature) + 211 " <B>" + vars[i].getName() + "</B> in slot %" + vars[i].getIndex() + 212 "<BR>Valid from lines " + 213 "<A HREF=\"" + class_name + "_code.html#code" + method_number + "@" + start + "\" TARGET=Code>" + 214 start + "</A> to " + 215 "<A HREF=\"" + class_name + "_code.html#code" + method_number + "@" + end + "\" TARGET=Code>" + 216 end + "</A></LI>"); 217 } 218 file.print("</UL>\n"); 219 220 break; 221 222 case ATTR_INNER_CLASSES: 223 InnerClass[] classes = ((InnerClasses)attribute).getInnerClasses(); 224 225 file.print("<UL>"); 227 228 for(int i=0; i < classes.length; i++) { 229 String name, access; 230 231 index = classes[i].getInnerNameIndex(); 232 if(index > 0) 233 name =((ConstantUtf8)constant_pool.getConstant(index, CONSTANT_Utf8)).getBytes(); 234 else 235 name = "<anonymous>"; 236 237 access = Utility.accessToString(classes[i].getInnerAccessFlags()); 238 239 file.print("<LI><FONT COLOR=\"#FF0000\">" + access + "</FONT> "+ 240 constant_html.referenceConstant(classes[i].getInnerClassIndex()) + 241 " in class " + 242 constant_html.referenceConstant(classes[i].getOuterClassIndex()) + 243 " named " + name + "</LI>\n"); 244 } 245 246 file.print("</UL>\n"); 247 break; 248 249 default: file.print("<P>" + attribute.toString()); 251 } 252 253 file.println("</TD></TR>"); 254 file.flush(); 255 } 256 } 257 | Popular Tags |