Package org.apache.bcel.classfile
Class Attribute
- java.lang.Object
-
- org.apache.bcel.classfile.Attribute
-
- All Implemented Interfaces:
java.lang.Cloneable,Node
- 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
public abstract class Attribute extends java.lang.Object implements java.lang.Cloneable, Node
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]; }
-
-
Field Summary
Fields Modifier and Type Field Description protected ConstantPoolconstant_poolDeprecated.(since 6.0) will be made private; do not access directly, use getter/setter.private static booleandebugstatic Attribute[]EMPTY_ARRAYEmpty array.protected intlengthDeprecated.(since 6.0) (since 6.0) will be made private; do not access directly, use getter/setter.protected intname_indexDeprecated.(since 6.0) will be made private; do not access directly, use getter/setter.private static java.util.Map<java.lang.String,java.lang.Object>READERSprotected bytetagDeprecated.(since 6.0) will be made private; do not access directly, use getter/setter.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAttribute(byte tag, int nameIndex, int length, ConstantPool constantPool)Constructs an instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract voidaccept(Visitor v)Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class.static voidaddAttributeReader(java.lang.String name, AttributeReader attributeReader)Deprecated.(6.0) UseaddAttributeReader(String, UnknownAttributeReader)instead.static voidaddAttributeReader(java.lang.String name, UnknownAttributeReader unknownAttributeReader)Add an Attribute reader capable of parsing (user-defined) attributes named "name".java.lang.Objectclone()Use copy() if you want to have a deep copy(), that is, with all references copied correctly.abstract Attributecopy(ConstantPool constantPool)Creates a deep copy of this attribute.voiddump(java.io.DataOutputStream file)Dumps attribute to file stream in binary format.ConstantPoolgetConstantPool()Gets the constant pool used by this object.intgetLength()Gets the length of attribute field in bytes.java.lang.StringgetName()Gets the name of attribute.intgetNameIndex()Gets the name index in constant pool of attribute name.bytegetTag()Gets the tag of attribute, that is, its type.protected static voidprintln(java.lang.String msg)Prints a message to stderr if debug mode is enabled.static AttributereadAttribute(java.io.DataInput dataInput, ConstantPool constantPool)Class method reads one attribute from the input data stream.static AttributereadAttribute(java.io.DataInputStream dataInputStream, ConstantPool constantPool)Class method reads one attribute from the input data stream.static voidremoveAttributeReader(java.lang.String name)Remove attribute readervoidsetConstantPool(ConstantPool constantPool)Sets the constant pool to be used for this object.voidsetLength(int length)Sets the length in bytes.voidsetNameIndex(int nameIndex)Sets the name index of attribute.java.lang.StringtoString()
-
-
-
Field Detail
-
debug
private static final boolean debug
-
READERS
private static final java.util.Map<java.lang.String,java.lang.Object> READERS
-
EMPTY_ARRAY
public static final Attribute[] EMPTY_ARRAY
Empty array.- Since:
- 6.6.0
-
name_index
@Deprecated protected int name_index
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter.
-
length
@Deprecated protected int length
Deprecated.(since 6.0) (since 6.0) will be made private; do not access directly, use getter/setter.
-
tag
@Deprecated protected byte tag
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter.
-
constant_pool
@Deprecated protected ConstantPool constant_pool
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter.
-
-
Constructor Detail
-
Attribute
protected Attribute(byte tag, int nameIndex, int length, ConstantPool constantPool)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 Detail
-
addAttributeReader
@Deprecated public static void addAttributeReader(java.lang.String name, AttributeReader attributeReader)Deprecated.(6.0) UseaddAttributeReader(String, UnknownAttributeReader)instead.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 file.attributeReader- the reader object.
-
addAttributeReader
public static void addAttributeReader(java.lang.String name, UnknownAttributeReader unknownAttributeReader)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 file.unknownAttributeReader- the reader object.
-
println
protected static void println(java.lang.String msg)
Prints a message to stderr if debug mode is enabled.- Parameters:
msg- the message to print.
-
readAttribute
public static Attribute readAttribute(java.io.DataInput dataInput, ConstantPool constantPool) throws java.io.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.
-
readAttribute
public static Attribute readAttribute(java.io.DataInputStream dataInputStream, ConstantPool constantPool) throws java.io.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.
-
removeAttributeReader
public static void removeAttributeReader(java.lang.String name)
Remove attribute reader- Parameters:
name- the name of the attribute as stored in the class file.
-
accept
public abstract void accept(Visitor v)
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
public java.lang.Object clone()
Use copy() if you want to have a deep copy(), that is, with all references copied correctly.- Overrides:
clonein classjava.lang.Object- Returns:
- shallow copy of this attribute.
-
copy
public abstract Attribute copy(ConstantPool constantPool)
Creates a deep copy of this attribute.- Parameters:
constantPool- constant pool to save.- Returns:
- deep copy of this attribute.
-
dump
public void dump(java.io.DataOutputStream file) throws java.io.IOExceptionDumps attribute to file stream in binary format.- Parameters:
file- Output file stream.- Throws:
java.io.IOException- if an I/O error occurs.
-
getConstantPool
public final ConstantPool getConstantPool()
Gets the constant pool used by this object.- Returns:
- Constant pool used by this object.
- See Also:
ConstantPool
-
getLength
public final int getLength()
Gets the length of attribute field in bytes.- Returns:
- Length of attribute field in bytes.
-
getName
public java.lang.String getName()
Gets the name of attribute.- Returns:
- Name of attribute.
- Since:
- 6.0
-
getNameIndex
public final int getNameIndex()
Gets the name index in constant pool of attribute name.- Returns:
- Name index in constant pool of attribute name.
-
getTag
public final byte getTag()
Gets the tag of attribute, that is, its type.- Returns:
- Tag of attribute, that is, its type. Value may not be altered, thus there is no setTag() method.
-
setConstantPool
public final void setConstantPool(ConstantPool constantPool)
Sets the constant pool to be used for this object.- Parameters:
constantPool- Constant pool to be used for this object.- See Also:
ConstantPool
-
setLength
public final void setLength(int length)
Sets the length in bytes.- Parameters:
length- length in bytes.
-
setNameIndex
public final void setNameIndex(int nameIndex)
Sets the name index of attribute.- Parameters:
nameIndex- of attribute.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- attribute name.
-
-