Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

MethodHTML.java

00001 package de.fub.bytecode.util;
00002 
00003 import de.fub.bytecode.classfile.*;
00004 import java.io.*;
00005 
00006 /**
00007  * Convert methods and fields into HTML file.
00008  *
00009  * @version $Id: MethodHTML.java,v 1.1.1.1 2002/01/24 03:41:42 pserver Exp $
00010  * @author  <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
00011  * 
00012  */
00013 final class MethodHTML implements de.fub.bytecode.Constants {
00014   private String    class_name;     // name of current class
00015   private PrintWriter   file;           // file to write to
00016   private ConstantHTML  constant_html;
00017   private AttributeHTML attribute_html;
00018 
00019   MethodHTML(String dir, String class_name,
00020          Method[] methods, Field[] fields,
00021          ConstantHTML constant_html, AttributeHTML attribute_html) throws IOException
00022   {
00023     this.class_name     = class_name;
00024     this.attribute_html = attribute_html;
00025     this.constant_html  = constant_html;
00026 
00027     file = new PrintWriter(new FileOutputStream(dir + class_name + "_methods.html"));
00028 
00029     file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>");
00030     file.println("<TR><TH ALIGN=LEFT>Access&nbsp;flags</TH><TH ALIGN=LEFT>Type</TH>" +
00031          "<TH ALIGN=LEFT>Field&nbsp;name</TH></TR>");
00032     for(int i=0; i < fields.length; i++)
00033       writeField(fields[i]);
00034     file.println("</TABLE>");
00035     
00036     file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Access&nbsp;flags</TH>" +
00037          "<TH ALIGN=LEFT>Return&nbsp;type</TH><TH ALIGN=LEFT>Method&nbsp;name</TH>" +
00038          "<TH ALIGN=LEFT>Arguments</TH></TR>");
00039     for(int i=0; i < methods.length; i++)
00040       writeMethod(methods[i], i);
00041     
00042     file.println("</TABLE></BODY></HTML>");
00043     file.close();
00044   }  
00045   /**
00046    * Print field of class.
00047    *
00048    * @param field field to print
00049    * @exception java.io.IOException
00050    */
00051   private void writeField(Field field) throws IOException {
00052     String       type   = Utility.signatureToString(field.getSignature());
00053     String       name   = field.getName();
00054     String       access = Utility.accessToString(field.getAccessFlags());
00055     Attribute[]  attributes;
00056 
00057     access = Utility.replace(access, " ", "&nbsp;");
00058 
00059     file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>" +
00060            Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" +
00061            name + "</A></TD>");
00062                     
00063     attributes = field.getAttributes();
00064 
00065     // Write them to the Attributes.html file with anchor "<name>[<i>]"
00066     for(int i=0; i < attributes.length; i++)
00067       attribute_html.writeAttribute(attributes[i], name + "@" + i);
00068 
00069     for(int i=0; i < attributes.length; i++) {
00070       if(attributes[i].getTag() == ATTR_CONSTANT_VALUE) { // Default value
00071     String str = ((ConstantValue)attributes[i]).toString();
00072 
00073     // Reference attribute in _attributes.html
00074     file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" +
00075            name + "@" + i + "\" TARGET=\"Attributes\">" + str + "</TD>\n");
00076     break;
00077       }
00078     }
00079     
00080     file.println("</TR>");
00081   }  
00082   private final void writeMethod(Method method, int method_number) throws IOException {
00083     // Get raw signature
00084     String       signature  = method.getSignature();
00085     // Get array of strings containing the argument types 
00086     String[]     args       = Utility.methodSignatureArgumentTypes(signature, false);
00087     // Get return type string
00088     String       type       = Utility.methodSignatureReturnType(signature, false);
00089     // Get method name
00090     String       name       = method.getName(), html_name;
00091     // Get method's access flags
00092     String       access     = Utility.accessToString(method.getAccessFlags());
00093     // Get the method's attributes, the Code Attribute in particular
00094     Attribute[]  attributes = method.getAttributes();
00095 
00096     /* HTML doesn't like names like <clinit> and spaces are places to break
00097      * lines. Both we don't want...
00098      */
00099     access  = Utility.replace(access, " ", "&nbsp;");
00100     html_name   = Class2HTML.toHTML(name);
00101 
00102     file.print("<TR VALIGN=TOP><TD><FONT COLOR=\"#FF0000\"><A NAME=method" + method_number + ">" +
00103            access + "</A></FONT></TD>");
00104 
00105     file.print("<TD>" + Class2HTML.referenceType(type) + "</TD><TD>" +
00106            "<A HREF=" + class_name + "_code.html#method" + method_number +
00107            " TARGET=Code>" + html_name + "</A></TD>\n<TD>(");
00108 
00109     for(int i=0; i < args.length; i++) {
00110       file.print(Class2HTML.referenceType(args[i]));
00111       if(i < args.length - 1)
00112     file.print(", ");
00113     }
00114 
00115     file.print(")</TD></TR>");
00116 
00117     // Check for thrown exceptions
00118     for(int i=0; i < attributes.length; i++) {
00119       attribute_html.writeAttribute(attributes[i], "method" + method_number + "@" + i,
00120                     method_number); 
00121 
00122       byte tag = attributes[i].getTag();
00123       if(tag == ATTR_EXCEPTIONS) {
00124     file.print("<TR VALIGN=TOP><TD COLSPAN=2></TD><TH ALIGN=LEFT>throws</TH><TD>");
00125     int[] exceptions = ((ExceptionTable)attributes[i]).getExceptionIndexTable();
00126     
00127     for(int j=0; j < exceptions.length; j++) {
00128       file.print(constant_html.referenceConstant(exceptions[j]));
00129       
00130       if(j < exceptions.length - 1)
00131         file.print(", ");
00132     }
00133     file.println("</TD></TR>");
00134       } else if(tag == ATTR_CODE) {
00135     Attribute[] c_a = ((Code)attributes[i]).getAttributes();
00136 
00137     for(int j=0; j < c_a.length; j++)
00138       attribute_html.writeAttribute(c_a[j], "method" + method_number + "@" + i + "@" + j,
00139                     method_number); 
00140       }
00141     }
00142   }  
00143 }

Generated at Thu Feb 7 06:50:25 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001