Java Code Examples for org.apache.bcel.Const#ATTR_CODE

The following examples show how to use org.apache.bcel.Const#ATTR_CODE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Code.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * @param name_index Index pointing to the name <em>Code</em>
 * @param length Content length in bytes
 * @param maxStack Maximum size of stack
 * @param maxLocals Number of local variables
 * @param code Actual byte code
 * @param exceptionTable of handled exceptions
 * @param attributes Attributes of code: LineNumber or LocalVariable
 * @param constant_pool Array of constants
 */
public Code(final int name_index, final int length, final int maxStack, final int maxLocals, final byte[] code,
        final CodeException[] exceptionTable, final Attribute[] attributes, final ConstantPool constant_pool) {
    super(Const.ATTR_CODE, name_index, length, constant_pool);
    this.maxStack = maxStack;
    this.maxLocals = maxLocals;
    this.code = code != null ? code : new byte[0];
    this.exceptionTable = exceptionTable != null ? exceptionTable : new CodeException[0];
    this.attributes = attributes != null ? attributes : new Attribute[0];
    super.setLength(calculateLength()); // Adjust length
}
 
Example 2
Source File: MethodHTML.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
private void writeMethod( final Method method, final int method_number ) {
    // 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();
    String html_name;
    // Get method's access flags
    String access = Utility.accessToString(method.getAccessFlags());
    // Get the method's attributes, the Code Attribute in particular
    final Attribute[] attributes = method.getAttributes();
    /* HTML doesn't like names like <clinit> and spaces are places to break
     * lines. Both we don't want...
     */
    access = Utility.replace(access, " ", "&nbsp;");
    html_name = Class2HTML.toHTML(name);
    file.print("<TR VALIGN=TOP><TD><FONT COLOR=\"#FF0000\"><A NAME=method" + method_number
            + ">" + access + "</A></FONT></TD>");
    file.print("<TD>" + Class2HTML.referenceType(type) + "</TD><TD>" + "<A HREF=" + className
            + "_code.html#method" + method_number + " TARGET=Code>" + html_name
            + "</A></TD>\n<TD>(");
    for (int i = 0; i < args.length; i++) {
        file.print(Class2HTML.referenceType(args[i]));
        if (i < args.length - 1) {
            file.print(", ");
        }
    }
    file.print(")</TD></TR>");
    // Check for thrown exceptions
    for (int i = 0; i < attributes.length; i++) {
        attribute_html.writeAttribute(attributes[i], "method" + method_number + "@" + i,
                method_number);
        final byte tag = attributes[i].getTag();
        if (tag == Const.ATTR_EXCEPTIONS) {
            file.print("<TR VALIGN=TOP><TD COLSPAN=2></TD><TH ALIGN=LEFT>throws</TH><TD>");
            final int[] exceptions = ((ExceptionTable) attributes[i]).getExceptionIndexTable();
            for (int j = 0; j < exceptions.length; j++) {
                file.print(constantHtml.referenceConstant(exceptions[j]));
                if (j < exceptions.length - 1) {
                    file.print(", ");
                }
            }
            file.println("</TD></TR>");
        } else if (tag == Const.ATTR_CODE) {
            final Attribute[] c_a = ((Code) attributes[i]).getAttributes();
            for (int j = 0; j < c_a.length; j++) {
                attribute_html.writeAttribute(c_a[j], "method" + method_number + "@" + i + "@"
                        + j, method_number);
            }
        }
    }
}