View Javadoc
1 package org.apache.bcel.util; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache BCEL" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache BCEL", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 import org.apache.bcel.classfile.*; 58 import java.io.*; 59 60 /*** 61 * Convert methods and fields into HTML file. 62 * 63 * @version $Id: MethodHTML.java,v 1.1.1.1 2001/10/29 20:00:31 jvanzyl Exp $ 64 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 65 * 66 */ 67 final class MethodHTML implements org.apache.bcel.Constants { 68 private String class_name; // name of current class 69 private PrintWriter file; // file to write to 70 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 /*** 101 * Print field of class. 102 * 103 * @param field field to print 104 * @exception java.io.IOException 105 */ 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 // Write them to the Attributes.html file with anchor "<name>[<i>]" 121 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) { // Default value 126 String str = ((ConstantValue)attributes[i]).toString(); 127 128 // Reference attribute in _attributes.html 129 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 // Get raw signature 140 String signature = method.getSignature(); 141 // Get array of strings containing the argument types 142 String[] args = Utility.methodSignatureArgumentTypes(signature, false); 143 // Get return type string 144 String type = Utility.methodSignatureReturnType(signature, false); 145 // Get method name 146 String name = method.getName(), html_name; 147 // Get method's access flags 148 String access = Utility.accessToString(method.getAccessFlags()); 149 // Get the method's attributes, the Code Attribute in particular 150 Attribute[] attributes = method.getAttributes(); 151 152 /* HTML doesn't like names like <clinit> and spaces are places to break 153 * lines. Both we don't want... 154 */ 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 // Check for thrown exceptions 174 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 }

This page was automatically generated by Maven