in src/main/java/org/apache/bcel/util/CodeHTML.java [476:559]
private void writeMethod(final Method method, final int methodNumber) throws IOException {
// Get raw signature
final String signature = method.getSignature();
// Get array of strings containing the argument types
final String[] args = Utility.methodSignatureArgumentTypes(signature, false);
// Get return type string
final String type = Utility.methodSignatureReturnType(signature, false);
// Get method name
final String name = method.getName();
final String htmlName = Class2HTML.toHTML(name);
// Get method's access flags
String access = Utility.accessToString(method.getAccessFlags());
access = Utility.replace(access, " ", " ");
// Get the method's attributes, the Code Attribute in particular
final Attribute[] attributes = method.getAttributes();
printWriter.print("<P><B><FONT COLOR=\"#FF0000\">" + access + "</FONT> " + "<A NAME=method" + methodNumber + ">" + Class2HTML.referenceType(type)
+ "</A> <A HREF=\"" + className + "_methods.html#method" + methodNumber + "\" TARGET=Methods>" + htmlName + "</A>(");
for (int i = 0; i < args.length; i++) {
printWriter.print(Class2HTML.referenceType(args[i]));
if (i < args.length - 1) {
printWriter.print(", ");
}
}
printWriter.println(")</B></P>");
Code c = null;
byte[] code = null;
if (attributes.length > 0) {
printWriter.print("<H4>Attributes</H4><UL>\n");
for (int i = 0; i < attributes.length; i++) {
byte tag = attributes[i].getTag();
if (tag != Const.ATTR_UNKNOWN) {
printWriter.print("<LI><A HREF=\"" + className + "_attributes.html#method" + methodNumber + "@" + i + "\" TARGET=Attributes>"
+ Const.getAttributeName(tag) + "</A></LI>\n");
} else {
printWriter.print("<LI>" + attributes[i] + "</LI>");
}
if (tag == Const.ATTR_CODE) {
c = (Code) attributes[i];
final Attribute[] attributes2 = c.getAttributes();
code = c.getCode();
printWriter.print("<UL>");
for (int j = 0; j < attributes2.length; j++) {
tag = attributes2[j].getTag();
printWriter.print("<LI><A HREF=\"" + className + "_attributes.html#" + "method" + methodNumber + "@" + i + "@" + j
+ "\" TARGET=Attributes>" + Const.getAttributeName(tag) + "</A></LI>\n");
}
printWriter.print("</UL>");
}
}
printWriter.println("</UL>");
}
if (code != null) { // No code, an abstract method, e.g.
// System.out.println(name + "\n" + Utility.codeToString(code, constantPool, 0, -1));
// Print the byte code
try (ByteSequence stream = new ByteSequence(code)) {
stream.mark(stream.available());
findGotos(stream, c);
stream.reset();
printWriter.println("<TABLE BORDER=0><TR><TH ALIGN=LEFT>Byte<BR>offset</TH>" + "<TH ALIGN=LEFT>Instruction</TH><TH ALIGN=LEFT>Argument</TH>");
while (stream.available() > 0) {
final int offset = stream.getIndex();
final String str = codeToHTML(stream, methodNumber);
String anchor = "";
/*
* Set an anchor mark if this line is targetted by a goto, jsr, etc. Defining an anchor for every line is very
* inefficient!
*/
if (gotoSet.get(offset)) {
anchor = "<A NAME=code" + methodNumber + "@" + offset + "></A>";
}
String anchor2;
if (stream.getIndex() == code.length) {
anchor2 = "<A NAME=code" + methodNumber + "@" + code.length + ">" + offset + "</A>";
} else {
anchor2 = "" + offset;
}
printWriter.println("<TR VALIGN=TOP><TD>" + anchor2 + "</TD><TD>" + anchor + str + "</TR>");
}
}
// Mark last line, may be targetted from Attributes window
printWriter.println("<TR><TD> </A></TD></TR>");
printWriter.println("</TABLE>");
}
}