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 MethodHTML implements com.sun.org.apache.bcel.internal.Constants { 68 private String class_name; private PrintWriter file; private ConstantHTML constant_html; 71 private AttributeHTML attribute_html; 72 73 MethodHTML(String dir, String class_name, 74 Method[] methods, Field[] fields, 75 ConstantHTML constant_html, AttributeHTML attribute_html) throws IOException 76 { 77 this.class_name = class_name; 78 this.attribute_html = attribute_html; 79 this.constant_html = constant_html; 80 81 file = new PrintWriter(new FileOutputStream(dir + class_name + "_methods.html")); 82 83 file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>"); 84 file.println("<TR><TH ALIGN=LEFT>Access flags</TH><TH ALIGN=LEFT>Type</TH>" + 85 "<TH ALIGN=LEFT>Field name</TH></TR>"); 86 for(int i=0; i < fields.length; i++) 87 writeField(fields[i]); 88 file.println("</TABLE>"); 89 90 file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Access flags</TH>" + 91 "<TH ALIGN=LEFT>Return type</TH><TH ALIGN=LEFT>Method name</TH>" + 92 "<TH ALIGN=LEFT>Arguments</TH></TR>"); 93 for(int i=0; i < methods.length; i++) 94 writeMethod(methods[i], i); 95 96 file.println("</TABLE></BODY></HTML>"); 97 file.close(); 98 } 99 100 106 private void writeField(Field field) throws IOException { 107 String type = Utility.signatureToString(field.getSignature()); 108 String name = field.getName(); 109 String access = Utility.accessToString(field.getAccessFlags()); 110 Attribute[] attributes; 111 112 access = Utility.replace(access, " ", " "); 113 114 file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>" + 115 Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" + 116 name + "</A></TD>"); 117 118 attributes = field.getAttributes(); 119 120 for(int i=0; i < attributes.length; i++) 122 attribute_html.writeAttribute(attributes[i], name + "@" + i); 123 124 for(int i=0; i < attributes.length; i++) { 125 if(attributes[i].getTag() == ATTR_CONSTANT_VALUE) { String str = ((ConstantValue)attributes[i]).toString(); 127 128 file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" + 130 name + "@" + i + "\" TARGET=\"Attributes\">" + str + "</TD>\n"); 131 break; 132 } 133 } 134 135 file.println("</TR>"); 136 } 137 138 private final void writeMethod(Method method, int method_number) throws IOException { 139 String signature = method.getSignature(); 141 String [] args = Utility.methodSignatureArgumentTypes(signature, false); 143 String type = Utility.methodSignatureReturnType(signature, false); 145 String name = method.getName(), html_name; 147 String access = Utility.accessToString(method.getAccessFlags()); 149 Attribute[] attributes = method.getAttributes(); 151 152 155 access = Utility.replace(access, " ", " "); 156 html_name = Class2HTML.toHTML(name); 157 158 file.print("<TR VALIGN=TOP><TD><FONT COLOR=\"#FF0000\"><A NAME=method" + method_number + ">" + 159 access + "</A></FONT></TD>"); 160 161 file.print("<TD>" + Class2HTML.referenceType(type) + "</TD><TD>" + 162 "<A HREF=" + class_name + "_code.html#method" + method_number + 163 " TARGET=Code>" + html_name + "</A></TD>\n<TD>("); 164 165 for(int i=0; i < args.length; i++) { 166 file.print(Class2HTML.referenceType(args[i])); 167 if(i < args.length - 1) 168 file.print(", "); 169 } 170 171 file.print(")</TD></TR>"); 172 173 for(int i=0; i < attributes.length; i++) { 175 attribute_html.writeAttribute(attributes[i], "method" + method_number + "@" + i, 176 method_number); 177 178 byte tag = attributes[i].getTag(); 179 if(tag == ATTR_EXCEPTIONS) { 180 file.print("<TR VALIGN=TOP><TD COLSPAN=2></TD><TH ALIGN=LEFT>throws</TH><TD>"); 181 int[] exceptions = ((ExceptionTable)attributes[i]).getExceptionIndexTable(); 182 183 for(int j=0; j < exceptions.length; j++) { 184 file.print(constant_html.referenceConstant(exceptions[j])); 185 186 if(j < exceptions.length - 1) 187 file.print(", "); 188 } 189 file.println("</TD></TR>"); 190 } else if(tag == ATTR_CODE) { 191 Attribute[] c_a = ((Code)attributes[i]).getAttributes(); 192 193 for(int j=0; j < c_a.length; j++) 194 attribute_html.writeAttribute(c_a[j], "method" + method_number + "@" + i + "@" + j, 195 method_number); 196 } 197 } 198 } 199 } 200 | Popular Tags |