author | joehw |
Mon, 17 Apr 2017 16:24:10 -0700 | |
changeset 44797 | 8b3b3b911b8a |
parent 25868 | 686eef1e7a79 |
child 46174 | 5611d2529b49 |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
/* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* the License. You may obtain a copy of the License at |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
14 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
15 |
* Unless required by applicable law or agreed to in writing, software |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
16 |
* distributed under the License is distributed on an "AS IS" BASIS, |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
18 |
* See the License for the specific language governing permissions and |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
19 |
* limitations under the License. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
20 |
*/ |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
21 |
|
6 | 22 |
package com.sun.org.apache.bcel.internal.util; |
23 |
||
24 |
||
25 |
import com.sun.org.apache.bcel.internal.classfile.*; |
|
26 |
import java.io.*; |
|
27 |
||
28 |
/** |
|
29 |
* Convert methods and fields into HTML file. |
|
30 |
* |
|
31 |
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> |
|
32 |
* |
|
33 |
*/ |
|
34 |
final class MethodHTML implements com.sun.org.apache.bcel.internal.Constants { |
|
35 |
private String class_name; // name of current class |
|
36 |
private PrintWriter file; // file to write to |
|
37 |
private ConstantHTML constant_html; |
|
38 |
private AttributeHTML attribute_html; |
|
39 |
||
40 |
MethodHTML(String dir, String class_name, |
|
41 |
Method[] methods, Field[] fields, |
|
42 |
ConstantHTML constant_html, AttributeHTML attribute_html) throws IOException |
|
43 |
{ |
|
44 |
this.class_name = class_name; |
|
45 |
this.attribute_html = attribute_html; |
|
46 |
this.constant_html = constant_html; |
|
47 |
||
48 |
file = new PrintWriter(new FileOutputStream(dir + class_name + "_methods.html")); |
|
49 |
||
50 |
file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>"); |
|
51 |
file.println("<TR><TH ALIGN=LEFT>Access flags</TH><TH ALIGN=LEFT>Type</TH>" + |
|
52 |
"<TH ALIGN=LEFT>Field name</TH></TR>"); |
|
53 |
for(int i=0; i < fields.length; i++) |
|
54 |
writeField(fields[i]); |
|
55 |
file.println("</TABLE>"); |
|
56 |
||
57 |
file.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Access flags</TH>" + |
|
58 |
"<TH ALIGN=LEFT>Return type</TH><TH ALIGN=LEFT>Method name</TH>" + |
|
59 |
"<TH ALIGN=LEFT>Arguments</TH></TR>"); |
|
60 |
for(int i=0; i < methods.length; i++) |
|
61 |
writeMethod(methods[i], i); |
|
62 |
||
63 |
file.println("</TABLE></BODY></HTML>"); |
|
64 |
file.close(); |
|
65 |
} |
|
66 |
||
67 |
/** |
|
68 |
* Print field of class. |
|
69 |
* |
|
70 |
* @param field field to print |
|
71 |
* @exception java.io.IOException |
|
72 |
*/ |
|
73 |
private void writeField(Field field) throws IOException { |
|
74 |
String type = Utility.signatureToString(field.getSignature()); |
|
75 |
String name = field.getName(); |
|
76 |
String access = Utility.accessToString(field.getAccessFlags()); |
|
77 |
Attribute[] attributes; |
|
78 |
||
79 |
access = Utility.replace(access, " ", " "); |
|
80 |
||
81 |
file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>" + |
|
82 |
Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" + |
|
83 |
name + "</A></TD>"); |
|
84 |
||
85 |
attributes = field.getAttributes(); |
|
86 |
||
87 |
// Write them to the Attributes.html file with anchor "<name>[<i>]" |
|
88 |
for(int i=0; i < attributes.length; i++) |
|
89 |
attribute_html.writeAttribute(attributes[i], name + "@" + i); |
|
90 |
||
91 |
for(int i=0; i < attributes.length; i++) { |
|
92 |
if(attributes[i].getTag() == ATTR_CONSTANT_VALUE) { // Default value |
|
93 |
String str = ((ConstantValue)attributes[i]).toString(); |
|
94 |
||
95 |
// Reference attribute in _attributes.html |
|
96 |
file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" + |
|
97 |
name + "@" + i + "\" TARGET=\"Attributes\">" + str + "</TD>\n"); |
|
98 |
break; |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
file.println("</TR>"); |
|
103 |
} |
|
104 |
||
105 |
private final void writeMethod(Method method, int method_number) throws IOException { |
|
106 |
// Get raw signature |
|
107 |
String signature = method.getSignature(); |
|
108 |
// Get array of strings containing the argument types |
|
109 |
String[] args = Utility.methodSignatureArgumentTypes(signature, false); |
|
110 |
// Get return type string |
|
111 |
String type = Utility.methodSignatureReturnType(signature, false); |
|
112 |
// Get method name |
|
113 |
String name = method.getName(), html_name; |
|
114 |
// Get method's access flags |
|
115 |
String access = Utility.accessToString(method.getAccessFlags()); |
|
116 |
// Get the method's attributes, the Code Attribute in particular |
|
117 |
Attribute[] attributes = method.getAttributes(); |
|
118 |
||
119 |
/* HTML doesn't like names like <clinit> and spaces are places to break |
|
120 |
* lines. Both we don't want... |
|
121 |
*/ |
|
122 |
access = Utility.replace(access, " ", " "); |
|
123 |
html_name = Class2HTML.toHTML(name); |
|
124 |
||
125 |
file.print("<TR VALIGN=TOP><TD><FONT COLOR=\"#FF0000\"><A NAME=method" + method_number + ">" + |
|
126 |
access + "</A></FONT></TD>"); |
|
127 |
||
128 |
file.print("<TD>" + Class2HTML.referenceType(type) + "</TD><TD>" + |
|
129 |
"<A HREF=" + class_name + "_code.html#method" + method_number + |
|
130 |
" TARGET=Code>" + html_name + "</A></TD>\n<TD>("); |
|
131 |
||
132 |
for(int i=0; i < args.length; i++) { |
|
133 |
file.print(Class2HTML.referenceType(args[i])); |
|
134 |
if(i < args.length - 1) |
|
135 |
file.print(", "); |
|
136 |
} |
|
137 |
||
138 |
file.print(")</TD></TR>"); |
|
139 |
||
140 |
// Check for thrown exceptions |
|
141 |
for(int i=0; i < attributes.length; i++) { |
|
142 |
attribute_html.writeAttribute(attributes[i], "method" + method_number + "@" + i, |
|
143 |
method_number); |
|
144 |
||
145 |
byte tag = attributes[i].getTag(); |
|
146 |
if(tag == ATTR_EXCEPTIONS) { |
|
147 |
file.print("<TR VALIGN=TOP><TD COLSPAN=2></TD><TH ALIGN=LEFT>throws</TH><TD>"); |
|
148 |
int[] exceptions = ((ExceptionTable)attributes[i]).getExceptionIndexTable(); |
|
149 |
||
150 |
for(int j=0; j < exceptions.length; j++) { |
|
151 |
file.print(constant_html.referenceConstant(exceptions[j])); |
|
152 |
||
153 |
if(j < exceptions.length - 1) |
|
154 |
file.print(", "); |
|
155 |
} |
|
156 |
file.println("</TD></TR>"); |
|
157 |
} else if(tag == ATTR_CODE) { |
|
158 |
Attribute[] c_a = ((Code)attributes[i]).getAttributes(); |
|
159 |
||
160 |
for(int j=0; j < c_a.length; j++) |
|
161 |
attribute_html.writeAttribute(c_a[j], "method" + method_number + "@" + i + "@" + j, |
|
162 |
method_number); |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 |
} |