Search in sources :

Example 1 with ConstantValue_attribute

use of com.sun.tools.classfile.ConstantValue_attribute in project ceylon-compiler by ceylon.

the class ClassWriter method writeField.

protected void writeField(Field f) {
    if (!options.checkAccess(f.access_flags))
        return;
    AccessFlags flags = f.access_flags;
    writeModifiers(flags.getFieldModifiers());
    Signature_attribute sigAttr = getSignature(f.attributes);
    if (sigAttr == null)
        print(getJavaFieldType(f.descriptor));
    else {
        try {
            Type t = sigAttr.getParsedSignature().getType(constant_pool);
            print(getJavaName(t.toString()));
        } catch (ConstantPoolException e) {
            // report error?
            // fall back on non-generic descriptor
            print(getJavaFieldType(f.descriptor));
        }
    }
    print(" ");
    print(getFieldName(f));
    if (options.showConstants && !options.compat) {
        // BUG 4111861 print static final field contents
        Attribute a = f.attributes.get(Attribute.ConstantValue);
        if (a instanceof ConstantValue_attribute) {
            print(" = ");
            ConstantValue_attribute cv = (ConstantValue_attribute) a;
            print(getConstantValue(f.descriptor, cv.constantvalue_index));
        }
    }
    print(";");
    println();
    indent(+1);
    if (options.showInternalSignatures)
        println("Signature: " + getValue(f.descriptor));
    if (options.verbose && !options.compat)
        writeList("flags: ", flags.getFieldFlags(), NEWLINE);
    if (options.showAllAttrs) {
        for (Attribute attr : f.attributes) attrWriter.write(f, attr, constant_pool);
        println();
    }
    indent(-1);
    if (options.showDisassembled || options.showLineAndLocalVariableTables)
        println();
}
Also used : Type(com.sun.tools.classfile.Type) ArrayType(com.sun.tools.classfile.Type.ArrayType) ClassType(com.sun.tools.classfile.Type.ClassType) MethodType(com.sun.tools.classfile.Type.MethodType) WildcardType(com.sun.tools.classfile.Type.WildcardType) TypeParamType(com.sun.tools.classfile.Type.TypeParamType) SimpleType(com.sun.tools.classfile.Type.SimpleType) ClassSigType(com.sun.tools.classfile.Type.ClassSigType) ConstantValue_attribute(com.sun.tools.classfile.ConstantValue_attribute) Attribute(com.sun.tools.classfile.Attribute) ConstantPoolException(com.sun.tools.classfile.ConstantPoolException) Signature_attribute(com.sun.tools.classfile.Signature_attribute) AccessFlags(com.sun.tools.classfile.AccessFlags)

Aggregations

AccessFlags (com.sun.tools.classfile.AccessFlags)1 Attribute (com.sun.tools.classfile.Attribute)1 ConstantPoolException (com.sun.tools.classfile.ConstantPoolException)1 ConstantValue_attribute (com.sun.tools.classfile.ConstantValue_attribute)1 Signature_attribute (com.sun.tools.classfile.Signature_attribute)1 Type (com.sun.tools.classfile.Type)1 ArrayType (com.sun.tools.classfile.Type.ArrayType)1 ClassSigType (com.sun.tools.classfile.Type.ClassSigType)1 ClassType (com.sun.tools.classfile.Type.ClassType)1 MethodType (com.sun.tools.classfile.Type.MethodType)1 SimpleType (com.sun.tools.classfile.Type.SimpleType)1 TypeParamType (com.sun.tools.classfile.Type.TypeParamType)1 WildcardType (com.sun.tools.classfile.Type.WildcardType)1