Package org.apache.bcel.classfile
Class Attribute
java.lang.Object
org.apache.bcel.classfile.Attribute
- Direct Known Subclasses:
AnnotationDefault
,Annotations
,BootstrapMethods
,Code
,ConstantValue
,Deprecated
,EnclosingMethod
,ExceptionTable
,InnerClasses
,LineNumberTable
,LocalVariableTable
,LocalVariableTypeTable
,MethodParameters
,Module
,ModuleMainClass
,ModulePackages
,NestHost
,NestMembers
,ParameterAnnotations
,PMGClass
,Record
,Signature
,SourceFile
,StackMap
,Synthetic
,Unknown
Abstract super class for Attribute objects. Currently the ConstantValue, SourceFile, Code, Exceptiontable,
LineNumberTable, LocalVariableTable, InnerClasses and Synthetic attributes are supported. The Unknown attribute
stands for non-standard-attributes.
attribute_info { u2 attribute_name_index; u4 attribute_length; u1 info[attribute_length]; }
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected ConstantPool
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setterstatic final Attribute[]
Empty array.protected int
Deprecated.(since 6.0) (since 6.0) will be made private; do not access directly, use getter/setterprotected int
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setterprotected byte
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter -
Constructor Summary
ModifierConstructorDescriptionprotected
Attribute
(byte tag, int nameIndex, int length, ConstantPool constantPool) Constructs an instance. -
Method Summary
Modifier and TypeMethodDescriptionabstract void
Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class.static void
addAttributeReader
(String name, AttributeReader attributeReader) Deprecated.(6.0) UseaddAttributeReader(String, UnknownAttributeReader)
insteadstatic void
addAttributeReader
(String name, UnknownAttributeReader unknownAttributeReader) Add an Attribute reader capable of parsing (user-defined) attributes named "name".clone()
Use copy() if you want to have a deep copy(), i.e., with all references copied correctly.abstract Attribute
copy
(ConstantPool constantPool) void
dump
(DataOutputStream file) Dumps attribute to file stream in binary format.final ConstantPool
final int
getName()
final int
final byte
getTag()
protected static void
static Attribute
readAttribute
(DataInput dataInput, ConstantPool constantPool) Class method reads one attribute from the input data stream.static Attribute
readAttribute
(DataInputStream dataInputStream, ConstantPool constantPool) Class method reads one attribute from the input data stream.static void
removeAttributeReader
(String name) Remove attribute readerfinal void
setConstantPool
(ConstantPool constantPool) final void
setLength
(int length) final void
setNameIndex
(int nameIndex) toString()
-
Field Details
-
EMPTY_ARRAY
Empty array.- Since:
- 6.6.0
-
name_index
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter -
length
Deprecated.(since 6.0) (since 6.0) will be made private; do not access directly, use getter/setter -
tag
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter -
constant_pool
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter
-
-
Constructor Details
-
Attribute
Constructs an instance.attribute_info { u2 attribute_name_index; u4 attribute_length; u1 info[attribute_length]; }
- Parameters:
tag
- tag.nameIndex
- u2 name index.length
- u4 length.constantPool
- constant pool.
-
-
Method Details
-
addAttributeReader
Deprecated.(6.0) UseaddAttributeReader(String, UnknownAttributeReader)
insteadAdd an Attribute reader capable of parsing (user-defined) attributes named "name". You should not add readers for the standard attributes such as "LineNumberTable", because those are handled internally.- Parameters:
name
- the name of the attribute as stored in the class fileattributeReader
- the reader object
-
addAttributeReader
Add an Attribute reader capable of parsing (user-defined) attributes named "name". You should not add readers for the standard attributes such as "LineNumberTable", because those are handled internally.- Parameters:
name
- the name of the attribute as stored in the class fileunknownAttributeReader
- the reader object
-
println
-
readAttribute
public static Attribute readAttribute(DataInput dataInput, ConstantPool constantPool) throws IOException Class method reads one attribute from the input data stream. This method must not be accessible from the outside. It is called by the Field and Method constructor methods.- Parameters:
dataInput
- Input streamconstantPool
- Array of constants- Returns:
- Attribute
- Throws:
IOException
- if an I/O error occurs.- Since:
- 6.0
- See Also:
-
readAttribute
public static Attribute readAttribute(DataInputStream dataInputStream, ConstantPool constantPool) throws IOException Class method reads one attribute from the input data stream. This method must not be accessible from the outside. It is called by the Field and Method constructor methods.- Parameters:
dataInputStream
- Input streamconstantPool
- Array of constants- Returns:
- Attribute
- Throws:
IOException
- if an I/O error occurs.- See Also:
-
removeAttributeReader
Remove attribute reader- Parameters:
name
- the name of the attribute as stored in the class file
-
accept
Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects. -
clone
Use copy() if you want to have a deep copy(), i.e., with all references copied correctly. -
copy
- Parameters:
constantPool
- constant pool to save.- Returns:
- deep copy of this attribute.
-
dump
Dumps attribute to file stream in binary format.- Parameters:
file
- Output file stream- Throws:
IOException
- if an I/O error occurs.
-
getConstantPool
- Returns:
- Constant pool used by this object.
- See Also:
-
getLength
- Returns:
- Length of attribute field in bytes.
-
getName
- Returns:
- Name of attribute
- Since:
- 6.0
-
getNameIndex
- Returns:
- Name index in constant pool of attribute name.
-
getTag
- Returns:
- Tag of attribute, i.e., its type. Value may not be altered, thus there is no setTag() method.
-
setConstantPool
- Parameters:
constantPool
- Constant pool to be used for this object.- See Also:
-
setLength
- Parameters:
length
- length in bytes.
-
setNameIndex
- Parameters:
nameIndex
- of attribute.
-
toString
-