|
1 /* |
|
2 * reserved comment block |
|
3 * DO NOT REMOVE OR ALTER! |
|
4 */ |
|
5 package com.sun.org.apache.bcel.internal.util; |
|
6 |
|
7 /* ==================================================================== |
|
8 * The Apache Software License, Version 1.1 |
|
9 * |
|
10 * Copyright (c) 2001 The Apache Software Foundation. All rights |
|
11 * reserved. |
|
12 * |
|
13 * Redistribution and use in source and binary forms, with or without |
|
14 * modification, are permitted provided that the following conditions |
|
15 * are met: |
|
16 * |
|
17 * 1. Redistributions of source code must retain the above copyright |
|
18 * notice, this list of conditions and the following disclaimer. |
|
19 * |
|
20 * 2. Redistributions in binary form must reproduce the above copyright |
|
21 * notice, this list of conditions and the following disclaimer in |
|
22 * the documentation and/or other materials provided with the |
|
23 * distribution. |
|
24 * |
|
25 * 3. The end-user documentation included with the redistribution, |
|
26 * if any, must include the following acknowledgment: |
|
27 * "This product includes software developed by the |
|
28 * Apache Software Foundation (http://www.apache.org/)." |
|
29 * Alternately, this acknowledgment may appear in the software itself, |
|
30 * if and wherever such third-party acknowledgments normally appear. |
|
31 * |
|
32 * 4. The names "Apache" and "Apache Software Foundation" and |
|
33 * "Apache BCEL" must not be used to endorse or promote products |
|
34 * derived from this software without prior written permission. For |
|
35 * written permission, please contact apache@apache.org. |
|
36 * |
|
37 * 5. Products derived from this software may not be called "Apache", |
|
38 * "Apache BCEL", nor may "Apache" appear in their name, without |
|
39 * prior written permission of the Apache Software Foundation. |
|
40 * |
|
41 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
|
42 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
|
43 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
44 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR |
|
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
48 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
49 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
50 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
|
51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
52 * SUCH DAMAGE. |
|
53 * ==================================================================== |
|
54 * |
|
55 * This software consists of voluntary contributions made by many |
|
56 * individuals on behalf of the Apache Software Foundation. For more |
|
57 * information on the Apache Software Foundation, please see |
|
58 * <http://www.apache.org/>. |
|
59 */ |
|
60 |
|
61 import com.sun.org.apache.bcel.internal.classfile.*; |
|
62 import java.io.*; |
|
63 |
|
64 /** |
|
65 * Convert methods and fields into HTML file. |
|
66 * |
|
67 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> |
|
68 * |
|
69 */ |
|
70 final class MethodHTML implements com.sun.org.apache.bcel.internal.Constants { |
|
71 private String class_name; // name of current class |
|
72 private PrintWriter file; // file to write to |
|
73 private ConstantHTML constant_html; |
|
74 private AttributeHTML attribute_html; |
|
75 |
|
76 MethodHTML(String dir, String class_name, |
|
77 Method[] methods, Field[] fields, |
|
78 ConstantHTML constant_html, AttributeHTML attribute_html) throws IOException |
|
79 { |
|
80 this.class_name = class_name; |
|
81 this.attribute_html = attribute_html; |
|
82 this.constant_html = constant_html; |
|
83 |
|
84 file = new PrintWriter(new FileOutputStream(dir + class_name + "_methods.html")); |
|
85 |
|
86 file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>"); |
|
87 file.println("<TR><TH ALIGN=LEFT>Access flags</TH><TH ALIGN=LEFT>Type</TH>" + |
|
88 "<TH ALIGN=LEFT>Field name</TH></TR>"); |
|
89 for(int i=0; i < fields.length; i++) |
|
90 writeField(fields[i]); |
|
91 file.println("</TABLE>"); |
|
92 |
|
93 file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Access flags</TH>" + |
|
94 "<TH ALIGN=LEFT>Return type</TH><TH ALIGN=LEFT>Method name</TH>" + |
|
95 "<TH ALIGN=LEFT>Arguments</TH></TR>"); |
|
96 for(int i=0; i < methods.length; i++) |
|
97 writeMethod(methods[i], i); |
|
98 |
|
99 file.println("</TABLE></BODY></HTML>"); |
|
100 file.close(); |
|
101 } |
|
102 |
|
103 /** |
|
104 * Print field of class. |
|
105 * |
|
106 * @param field field to print |
|
107 * @exception java.io.IOException |
|
108 */ |
|
109 private void writeField(Field field) throws IOException { |
|
110 String type = Utility.signatureToString(field.getSignature()); |
|
111 String name = field.getName(); |
|
112 String access = Utility.accessToString(field.getAccessFlags()); |
|
113 Attribute[] attributes; |
|
114 |
|
115 access = Utility.replace(access, " ", " "); |
|
116 |
|
117 file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>" + |
|
118 Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" + |
|
119 name + "</A></TD>"); |
|
120 |
|
121 attributes = field.getAttributes(); |
|
122 |
|
123 // Write them to the Attributes.html file with anchor "<name>[<i>]" |
|
124 for(int i=0; i < attributes.length; i++) |
|
125 attribute_html.writeAttribute(attributes[i], name + "@" + i); |
|
126 |
|
127 for(int i=0; i < attributes.length; i++) { |
|
128 if(attributes[i].getTag() == ATTR_CONSTANT_VALUE) { // Default value |
|
129 String str = ((ConstantValue)attributes[i]).toString(); |
|
130 |
|
131 // Reference attribute in _attributes.html |
|
132 file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" + |
|
133 name + "@" + i + "\" TARGET=\"Attributes\">" + str + "</TD>\n"); |
|
134 break; |
|
135 } |
|
136 } |
|
137 |
|
138 file.println("</TR>"); |
|
139 } |
|
140 |
|
141 private final void writeMethod(Method method, int method_number) throws IOException { |
|
142 // Get raw signature |
|
143 String signature = method.getSignature(); |
|
144 // Get array of strings containing the argument types |
|
145 String[] args = Utility.methodSignatureArgumentTypes(signature, false); |
|
146 // Get return type string |
|
147 String type = Utility.methodSignatureReturnType(signature, false); |
|
148 // Get method name |
|
149 String name = method.getName(), html_name; |
|
150 // Get method's access flags |
|
151 String access = Utility.accessToString(method.getAccessFlags()); |
|
152 // Get the method's attributes, the Code Attribute in particular |
|
153 Attribute[] attributes = method.getAttributes(); |
|
154 |
|
155 /* HTML doesn't like names like <clinit> and spaces are places to break |
|
156 * lines. Both we don't want... |
|
157 */ |
|
158 access = Utility.replace(access, " ", " "); |
|
159 html_name = Class2HTML.toHTML(name); |
|
160 |
|
161 file.print("<TR VALIGN=TOP><TD><FONT COLOR=\"#FF0000\"><A NAME=method" + method_number + ">" + |
|
162 access + "</A></FONT></TD>"); |
|
163 |
|
164 file.print("<TD>" + Class2HTML.referenceType(type) + "</TD><TD>" + |
|
165 "<A HREF=" + class_name + "_code.html#method" + method_number + |
|
166 " TARGET=Code>" + html_name + "</A></TD>\n<TD>("); |
|
167 |
|
168 for(int i=0; i < args.length; i++) { |
|
169 file.print(Class2HTML.referenceType(args[i])); |
|
170 if(i < args.length - 1) |
|
171 file.print(", "); |
|
172 } |
|
173 |
|
174 file.print(")</TD></TR>"); |
|
175 |
|
176 // Check for thrown exceptions |
|
177 for(int i=0; i < attributes.length; i++) { |
|
178 attribute_html.writeAttribute(attributes[i], "method" + method_number + "@" + i, |
|
179 method_number); |
|
180 |
|
181 byte tag = attributes[i].getTag(); |
|
182 if(tag == ATTR_EXCEPTIONS) { |
|
183 file.print("<TR VALIGN=TOP><TD COLSPAN=2></TD><TH ALIGN=LEFT>throws</TH><TD>"); |
|
184 int[] exceptions = ((ExceptionTable)attributes[i]).getExceptionIndexTable(); |
|
185 |
|
186 for(int j=0; j < exceptions.length; j++) { |
|
187 file.print(constant_html.referenceConstant(exceptions[j])); |
|
188 |
|
189 if(j < exceptions.length - 1) |
|
190 file.print(", "); |
|
191 } |
|
192 file.println("</TD></TR>"); |
|
193 } else if(tag == ATTR_CODE) { |
|
194 Attribute[] c_a = ((Code)attributes[i]).getAttributes(); |
|
195 |
|
196 for(int j=0; j < c_a.length; j++) |
|
197 attribute_html.writeAttribute(c_a[j], "method" + method_number + "@" + i + "@" + j, |
|
198 method_number); |
|
199 } |
|
200 } |
|
201 } |
|
202 } |