Java Code Examples for com.sun.org.apache.bcel.internal.classfile.Field#getName()

The following examples show how to use com.sun.org.apache.bcel.internal.classfile.Field#getName() . 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 vote down vote up
/**
 * Instantiate from existing field.
 *
 * @param field Field object
 * @param cp constant pool (must contain the same entries as the field's constant pool)
 */
public FieldGen(final Field field, final ConstantPoolGen cp) {
    this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp);
    final Attribute[] attrs = field.getAttributes();
    for (final Attribute attr : attrs) {
        if (attr instanceof ConstantValue) {
            setValue(((ConstantValue) attr).getConstantValueIndex());
        } else if (attr instanceof Annotations) {
            final Annotations runtimeAnnotations = (Annotations)attr;
            final AnnotationEntry[] annotationEntries = runtimeAnnotations.getAnnotationEntries();
            for (final AnnotationEntry element : annotationEntries) {
                addAnnotationEntry(new AnnotationEntryGen(element,cp,false));
            }
        } else {
            addAttribute(attr);
        }
    }
}
 
Example 2
Source File: MethodHTML.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * 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>");
}