FileDocCategorySizeDatePackage
Attribute_info.javaAPI DocAndroid 1.5 API7707Wed May 06 22:41:16 BST 2009com.vladium.jcd.cls.attribute

Attribute_info

public abstract class Attribute_info extends Object implements Cloneable, com.vladium.jcd.compiler.IClassFormatOutput
Abstract base for all XXXAttribute_info structures. It also works in conjunction with {@link GenericAttribute_info} class to process all unrecognized attributes.

Attributes are used in the {@link com.vladium.jcd.cls.ClassDef}, {@link com.vladium.jcd.cls.Field_info}, {@link com.vladium.jcd.cls.Method_info}, and {@link CodeAttribute_info} structures of the .class file format. All attributes have the following general format:

attribute_info {
u2 attribute_name_index;
u4 attribute_length;
u1 info[attribute_length];
}
For all attributes, the attribute_name_index must be a valid unsigned 16-bit index into the constant pool of the class. The constant pool entry at attribute_name_index must be a {@link com.vladium.jcd.cls.constant.CONSTANT_Utf8_info} string representing the name of the attribute. The value of the attribute_length item indicates the length of the subsequent information in bytes. The length does not include the initial six bytes that contain the attribute_name_index and attribute_length items.
see
GenericAttribute_info
author
(C) 2001, Vlad Roubtsov

Fields Summary
public static final String
ATTRIBUTE_CODE
public static final String
ATTRIBUTE_CONSTANT_VALUE
public static final String
ATTRIBUTE_LINE_NUMBER_TABLE
public static final String
ATTRIBUTE_EXCEPTIONS
public static final String
ATTRIBUTE_SYNTHETIC
public static final String
ATTRIBUTE_BRIDGE
public static final String
ATTRIBUTE_SOURCEFILE
public static final String
ATTRIBUTE_INNERCLASSES
public int
m_name_index
Constant pool index for {@link com.vladium.jcd.cls.constant.CONSTANT_Utf8_info} string representing the name of this attribute [always positive].
protected long
m_attribute_length
Constructors Summary
protected Attribute_info(int attribute_name_index, long attribute_length)

        m_name_index = attribute_name_index;
        m_attribute_length = attribute_length;
    
Methods Summary
public abstract voidaccept(IAttributeVisitor visitor, java.lang.Object ctx)

public java.lang.Objectclone()
Chains to super.clone() and removes CloneNotSupportedException from the method signature.

        try
        {
            return super.clone ();
        }
        catch (CloneNotSupportedException e)
        {
            throw new InternalError (e.toString ());
        }
    
public java.lang.StringgetName(com.vladium.jcd.cls.ClassDef cls)
Returns the name for this attribute within the constant pool context of 'cls' class definition.

param
cls class that contains this attribute
return
attribute name

    
                                   
         
    
        return ((CONSTANT_Utf8_info) cls.getConstants ().get (m_name_index)).m_value;
    
public abstract longlength()
Returns the total length of this attribute when converted to .class format [including the 6-byte header]

public static com.vladium.jcd.cls.attribute.Attribute_infonew_Attribute_info(com.vladium.jcd.cls.IConstantCollection constants, com.vladium.jcd.lib.UDataInputStream bytes)
Parses out a single Attribute_info element out of .class data in 'bytes'.

param
constants constant pool for the parent class [may not be null; not validated]
param
bytes input .class data stream [may not be null; not validated]
return
a single parsed attribute
throws
IOException on input errors

        final int attribute_name_index = bytes.readU2 ();
        final long attribute_length = bytes.readU4 ();
        
        final CONSTANT_Utf8_info attribute_name = (CONSTANT_Utf8_info) constants.get (attribute_name_index);
        final String name = attribute_name.m_value;
                
        if (ATTRIBUTE_CODE.equals (name))
        {
            return new CodeAttribute_info (constants, attribute_name_index, attribute_length, bytes);
        }
        else if (ATTRIBUTE_CONSTANT_VALUE.equals (name))
        {
            return new ConstantValueAttribute_info (attribute_name_index, attribute_length, bytes);
        }
        else if (ATTRIBUTE_EXCEPTIONS.equals (name))
        {
            return new ExceptionsAttribute_info (attribute_name_index, attribute_length, bytes);
        }
        else if (ATTRIBUTE_INNERCLASSES.equals (name))
        {
            return new InnerClassesAttribute_info (attribute_name_index, attribute_length, bytes);
        }
        else if (ATTRIBUTE_SYNTHETIC.equals (name))
        {
            return new SyntheticAttribute_info (attribute_name_index, attribute_length);
        }
        else if (ATTRIBUTE_BRIDGE.equals (name))
        {
            return new BridgeAttribute_info (attribute_name_index, attribute_length);
        }
        else if (ATTRIBUTE_LINE_NUMBER_TABLE.equals (name))
        {
            return new LineNumberTableAttribute_info (attribute_name_index, attribute_length, bytes);
        }
        else if (ATTRIBUTE_SOURCEFILE.equals (name))
        {
            return new SourceFileAttribute_info (attribute_name_index, attribute_length, bytes);
        }
        else
        {
            // default:
            return new GenericAttribute_info (attribute_name_index, attribute_length, bytes);
        }
    
public abstract java.lang.StringtoString()

public voidwriteInClassFormat(com.vladium.jcd.lib.UDataOutputStream out)

   
        out.writeU2 (m_name_index);
        out.writeU4 (length () - 6); // don't use m_attribute_length