Java Code Examples for com.sun.org.apache.bcel.internal.classfile.Utility#accessToString()
The following examples show how to use
com.sun.org.apache.bcel.internal.classfile.Utility#accessToString() .
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: FieldGen.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Return string representation close to declaration format, * `public static final short MAX = 100', e.g.. * * @return String representation of field */ @Override public final String toString() { String name; String signature; String access; // Short cuts to constant pool access = Utility.accessToString(super.getAccessFlags()); access = access.isEmpty() ? "" : (access + " "); signature = super.getType().toString(); name = getName(); final StringBuilder buf = new StringBuilder(32); // CHECKSTYLE IGNORE MagicNumber buf.append(access).append(signature).append(" ").append(name); final String value = getInitValue(); if (value != null) { buf.append(" = ").append(value); } return buf.toString(); }
Example 2
Source File: MethodGen.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Return string representation close to declaration format, * `public static void main(String[]) throws IOException', e.g. * * @return String representation of the method. */ @Override public final String toString() { final String access = Utility.accessToString(super.getAccessFlags()); String signature = Type.getMethodSignature(super.getType(), arg_types); signature = Utility.methodSignatureToString(signature, super.getName(), access, true, getLocalVariableTable(super.getConstantPool())); final StringBuilder buf = new StringBuilder(signature); for (final Attribute a : getAttributes()) { if (!((a instanceof Code) || (a instanceof ExceptionTable))) { buf.append(" [").append(a).append("]"); } } if (throws_vec.size() > 0) { for (final String throwsDescriptor : throws_vec) { buf.append("\n\t\tthrows ").append(throwsDescriptor); } } return buf.toString(); }
Example 3
Source File: MethodHTML.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * Print field of class. * * @param field field to print * @throws java.io.IOException */ private void writeField( final Field field ) throws IOException { final String type = Utility.signatureToString(field.getSignature()); final String name = field.getName(); String access = Utility.accessToString(field.getAccessFlags()); Attribute[] attributes; access = Utility.replace(access, " ", " "); file.print("<TR><TD><FONT COLOR=\"#FF0000\">" + access + "</FONT></TD>\n<TD>" + Class2HTML.referenceType(type) + "</TD><TD><A NAME=\"field" + name + "\">" + name + "</A></TD>"); attributes = field.getAttributes(); // Write them to the Attributes.html file with anchor "<name>[<i>]" for (int i = 0; i < attributes.length; i++) { attribute_html.writeAttribute(attributes[i], name + "@" + i); } for (int i = 0; i < attributes.length; i++) { if (attributes[i].getTag() == Const.ATTR_CONSTANT_VALUE) { // Default value final String str = ((ConstantValue) attributes[i]).toString(); // Reference attribute in _attributes.html file.print("<TD>= <A HREF=\"" + class_name + "_attributes.html#" + name + "@" + i + "\" TARGET=\"Attributes\">" + str + "</TD>\n"); break; } } file.println("</TR>"); }
Example 4
Source File: MethodHTML.java From Bytecoder with Apache License 2.0 | 4 votes |
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, " ", " "); 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=" + class_name + "_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(constant_html.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); } } } }