286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/Apackage com.sun.org.apache.bcel.internal.util;
286N/A
286N/A/* ====================================================================
286N/A * The Apache Software License, Version 1.1
286N/A *
286N/A * Copyright (c) 2001 The Apache Software Foundation. All rights
286N/A * reserved.
286N/A *
286N/A * Redistribution and use in source and binary forms, with or without
286N/A * modification, are permitted provided that the following conditions
286N/A * are met:
286N/A *
286N/A * 1. Redistributions of source code must retain the above copyright
286N/A * notice, this list of conditions and the following disclaimer.
286N/A *
286N/A * 2. Redistributions in binary form must reproduce the above copyright
286N/A * notice, this list of conditions and the following disclaimer in
286N/A * the documentation and/or other materials provided with the
286N/A * distribution.
286N/A *
286N/A * 3. The end-user documentation included with the redistribution,
286N/A * if any, must include the following acknowledgment:
286N/A * "This product includes software developed by the
286N/A * Apache Software Foundation (http://www.apache.org/)."
286N/A * Alternately, this acknowledgment may appear in the software itself,
286N/A * if and wherever such third-party acknowledgments normally appear.
286N/A *
286N/A * 4. The names "Apache" and "Apache Software Foundation" and
286N/A * "Apache BCEL" must not be used to endorse or promote products
286N/A * derived from this software without prior written permission. For
286N/A * written permission, please contact apache@apache.org.
286N/A *
286N/A * 5. Products derived from this software may not be called "Apache",
286N/A * "Apache BCEL", nor may "Apache" appear in their name, without
286N/A * prior written permission of the Apache Software Foundation.
286N/A *
286N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
286N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
286N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
286N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
286N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
286N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
286N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
286N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
286N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
286N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
286N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
286N/A * SUCH DAMAGE.
286N/A * ====================================================================
286N/A *
286N/A * This software consists of voluntary contributions made by many
286N/A * individuals on behalf of the Apache Software Foundation. For more
286N/A * information on the Apache Software Foundation, please see
286N/A * <http://www.apache.org/>.
286N/A */
286N/A
286N/Aimport com.sun.org.apache.bcel.internal.classfile.*;
286N/Aimport java.io.*;
286N/A
286N/A/**
286N/A * Convert methods and fields into HTML file.
286N/A *
286N/A * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
286N/A *
286N/A */
286N/Afinal class MethodHTML implements com.sun.org.apache.bcel.internal.Constants {
286N/A private String class_name; // name of current class
286N/A private PrintWriter file; // file to write to
286N/A private ConstantHTML constant_html;
286N/A private AttributeHTML attribute_html;
286N/A
286N/A MethodHTML(String dir, String class_name,
286N/A Method[] methods, Field[] fields,
286N/A ConstantHTML constant_html, AttributeHTML attribute_html) throws IOException
286N/A {
286N/A this.class_name = class_name;
286N/A this.attribute_html = attribute_html;
286N/A this.constant_html = constant_html;
286N/A
286N/A file = new PrintWriter(new FileOutputStream(dir + class_name + "_methods.html"));
286N/A
286N/A file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>");
286N/A file.println("<TR><TH ALIGN=LEFT>Access&nbsp;flags</TH><TH ALIGN=LEFT>Type</TH>" +
286N/A "<TH ALIGN=LEFT>Field&nbsp;name</TH></TR>");
286N/A for(int i=0; i < fields.length; i++)
286N/A writeField(fields[i]);
286N/A file.println("</TABLE>");
286N/A
286N/A file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Access&nbsp;flags</TH>" +
286N/A "<TH ALIGN=LEFT>Return&nbsp;type</TH><TH ALIGN=LEFT>Method&nbsp;name</TH>" +
286N/A "<TH ALIGN=LEFT>Arguments</TH></TR>");
286N/A for(int i=0; i < methods.length; i++)
286N/A writeMethod(methods[i], i);
286N/A
286N/A file.println("</TABLE></BODY></HTML>");
286N/A file.close();
286N/A }
286N/A
286N/A /**
286N/A * Print field of class.
286N/A *
286N/A * @param field field to print
286N/A * @exception java.io.IOException
286N/A */
286N/A private void writeField(Field field) throws IOException {
286N/A String type = Utility.signatureToString(field.getSignature());
286N/A String name = field.getName();
286N/A String access = Utility.accessToString(field.getAccessFlags());
286N/A Attribute[] attributes;
286N/A
286N/A access = Utility.replace(access, " ", "&nbsp;");
286N/A
286N/A file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>" +
286N/A Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" +
286N/A name + "</A></TD>");
286N/A
286N/A attributes = field.getAttributes();
286N/A
286N/A // Write them to the Attributes.html file with anchor "<name>[<i>]"
286N/A for(int i=0; i < attributes.length; i++)
286N/A attribute_html.writeAttribute(attributes[i], name + "@" + i);
286N/A
286N/A for(int i=0; i < attributes.length; i++) {
286N/A if(attributes[i].getTag() == ATTR_CONSTANT_VALUE) { // Default value
286N/A String str = ((ConstantValue)attributes[i]).toString();
286N/A
286N/A // Reference attribute in _attributes.html
286N/A file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" +
286N/A name + "@" + i + "\" TARGET=\"Attributes\">" + str + "</TD>\n");
286N/A break;
286N/A }
286N/A }
286N/A
286N/A file.println("</TR>");
286N/A }
286N/A
286N/A private final void writeMethod(Method method, int method_number) throws IOException {
286N/A // Get raw signature
286N/A String signature = method.getSignature();
286N/A // Get array of strings containing the argument types
286N/A String[] args = Utility.methodSignatureArgumentTypes(signature, false);
286N/A // Get return type string
286N/A String type = Utility.methodSignatureReturnType(signature, false);
286N/A // Get method name
286N/A String name = method.getName(), html_name;
286N/A // Get method's access flags
286N/A String access = Utility.accessToString(method.getAccessFlags());
286N/A // Get the method's attributes, the Code Attribute in particular
286N/A Attribute[] attributes = method.getAttributes();
286N/A
286N/A /* HTML doesn't like names like <clinit> and spaces are places to break
286N/A * lines. Both we don't want...
286N/A */
286N/A access = Utility.replace(access, " ", "&nbsp;");
286N/A html_name = Class2HTML.toHTML(name);
286N/A
286N/A file.print("<TR VALIGN=TOP><TD><FONT COLOR=\"#FF0000\"><A NAME=method" + method_number + ">" +
286N/A access + "</A></FONT></TD>");
286N/A
286N/A file.print("<TD>" + Class2HTML.referenceType(type) + "</TD><TD>" +
286N/A "<A HREF=" + class_name + "_code.html#method" + method_number +
286N/A " TARGET=Code>" + html_name + "</A></TD>\n<TD>(");
286N/A
286N/A for(int i=0; i < args.length; i++) {
286N/A file.print(Class2HTML.referenceType(args[i]));
286N/A if(i < args.length - 1)
286N/A file.print(", ");
286N/A }
286N/A
286N/A file.print(")</TD></TR>");
286N/A
286N/A // Check for thrown exceptions
286N/A for(int i=0; i < attributes.length; i++) {
286N/A attribute_html.writeAttribute(attributes[i], "method" + method_number + "@" + i,
286N/A method_number);
286N/A
286N/A byte tag = attributes[i].getTag();
286N/A if(tag == ATTR_EXCEPTIONS) {
286N/A file.print("<TR VALIGN=TOP><TD COLSPAN=2></TD><TH ALIGN=LEFT>throws</TH><TD>");
286N/A int[] exceptions = ((ExceptionTable)attributes[i]).getExceptionIndexTable();
286N/A
286N/A for(int j=0; j < exceptions.length; j++) {
286N/A file.print(constant_html.referenceConstant(exceptions[j]));
286N/A
286N/A if(j < exceptions.length - 1)
286N/A file.print(", ");
286N/A }
286N/A file.println("</TD></TR>");
286N/A } else if(tag == ATTR_CODE) {
286N/A Attribute[] c_a = ((Code)attributes[i]).getAttributes();
286N/A
286N/A for(int j=0; j < c_a.length; j++)
286N/A attribute_html.writeAttribute(c_a[j], "method" + method_number + "@" + i + "@" + j,
286N/A method_number);
286N/A }
286N/A }
286N/A }
286N/A}