com.vladium.jcd.cls.attribute
Class Attribute_info

java.lang.Object
  extended by com.vladium.jcd.cls.attribute.Attribute_info
All Implemented Interfaces:
IClassFormatOutput, java.lang.Cloneable
Direct Known Subclasses:
BridgeAttribute_info, CodeAttribute_info, ConstantValueAttribute_info, ExceptionsAttribute_info, GenericAttribute_info, InnerClassesAttribute_info, LineNumberTableAttribute_info, SourceFileAttribute_info, SyntheticAttribute_info

public abstract class Attribute_info
extends java.lang.Object
implements java.lang.Cloneable, IClassFormatOutput

Abstract base for all XXXAttribute_info structures. It also works in conjunction with GenericAttribute_info class to process all unrecognized attributes.

Attributes are used in the ClassDef, Field_info, Method_info, and 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 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.

Author:
(C) 2001, Vlad Roubtsov
See Also:
GenericAttribute_info

Field Summary
static java.lang.String ATTRIBUTE_BRIDGE
           
static java.lang.String ATTRIBUTE_CODE
           
static java.lang.String ATTRIBUTE_CONSTANT_VALUE
           
static java.lang.String ATTRIBUTE_EXCEPTIONS
           
static java.lang.String ATTRIBUTE_INNERCLASSES
           
static java.lang.String ATTRIBUTE_LINE_NUMBER_TABLE
           
static java.lang.String ATTRIBUTE_SOURCEFILE
           
static java.lang.String ATTRIBUTE_SYNTHETIC
           
protected  long m_attribute_length
           
 int m_name_index
          Constant pool index for CONSTANT_Utf8_info string representing the name of this attribute [always positive].
 
Constructor Summary
protected Attribute_info(int attribute_name_index, long attribute_length)
           
 
Method Summary
abstract  void accept(IAttributeVisitor visitor, java.lang.Object ctx)
           
 java.lang.Object clone()
          Chains to super.clone() and removes CloneNotSupportedException from the method signature.
 java.lang.String getName(ClassDef cls)
          Returns the name for this attribute within the constant pool context of 'cls' class definition.
abstract  long length()
          Returns the total length of this attribute when converted to .class format [including the 6-byte header]
static Attribute_info new_Attribute_info(IConstantCollection constants, UDataInputStream bytes)
          Parses out a single Attribute_info element out of .class data in 'bytes'.
abstract  java.lang.String toString()
           
 void writeInClassFormat(UDataOutputStream out)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ATTRIBUTE_CODE

public static final java.lang.String ATTRIBUTE_CODE
See Also:
Constant Field Values

ATTRIBUTE_CONSTANT_VALUE

public static final java.lang.String ATTRIBUTE_CONSTANT_VALUE
See Also:
Constant Field Values

ATTRIBUTE_LINE_NUMBER_TABLE

public static final java.lang.String ATTRIBUTE_LINE_NUMBER_TABLE
See Also:
Constant Field Values

ATTRIBUTE_EXCEPTIONS

public static final java.lang.String ATTRIBUTE_EXCEPTIONS
See Also:
Constant Field Values

ATTRIBUTE_SYNTHETIC

public static final java.lang.String ATTRIBUTE_SYNTHETIC
See Also:
Constant Field Values

ATTRIBUTE_BRIDGE

public static final java.lang.String ATTRIBUTE_BRIDGE
See Also:
Constant Field Values

ATTRIBUTE_SOURCEFILE

public static final java.lang.String ATTRIBUTE_SOURCEFILE
See Also:
Constant Field Values

ATTRIBUTE_INNERCLASSES

public static final java.lang.String ATTRIBUTE_INNERCLASSES
See Also:
Constant Field Values

m_name_index

public int m_name_index
Constant pool index for CONSTANT_Utf8_info string representing the name of this attribute [always positive].


m_attribute_length

protected long m_attribute_length
Constructor Detail

Attribute_info

protected Attribute_info(int attribute_name_index,
                         long attribute_length)
Method Detail

getName

public java.lang.String getName(ClassDef cls)
Returns the name for this attribute within the constant pool context of 'cls' class definition.

Parameters:
cls - class that contains this attribute
Returns:
attribute name

length

public abstract long length()
Returns the total length of this attribute when converted to .class format [including the 6-byte header]


accept

public abstract void accept(IAttributeVisitor visitor,
                            java.lang.Object ctx)

toString

public abstract java.lang.String toString()
Overrides:
toString in class java.lang.Object

new_Attribute_info

public static Attribute_info new_Attribute_info(IConstantCollection constants,
                                                UDataInputStream bytes)
                                         throws java.io.IOException
Parses out a single Attribute_info element out of .class data in 'bytes'.

Parameters:
constants - constant pool for the parent class [may not be null; not validated]
bytes - input .class data stream [may not be null; not validated]
Returns:
a single parsed attribute
Throws:
java.io.IOException - on input errors

clone

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

Overrides:
clone in class java.lang.Object

writeInClassFormat

public void writeInClassFormat(UDataOutputStream out)
                        throws java.io.IOException
Specified by:
writeInClassFormat in interface IClassFormatOutput
Throws:
java.io.IOException