org.apache.bcel.classfile

## Class Attribute

- java.lang.Object
- - org.apache.bcel.classfile.Attribute

- All Implemented Interfaces:
    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, Signature, SourceFile, StackMap, Synthetic, Unknown

      public abstract class Attribute
      extends Object
      implements 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.
  See Also:
    `ConstantValue`, `SourceFile`, `Code`, `Unknown`, `ExceptionTable`, `LineNumberTable`, `LocalVariableTable`, `InnerClasses`, `Synthetic`, `Deprecated`, `Signature`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ConstantPool` | `constant_pool` Deprecated. (since 6.0) will be made private; do not access directly, use getter/setter
    `static Attribute[]` | `EMPTY_ARRAY` Empty array.
    `protected int` | `length` Deprecated. (since 6.0) (since 6.0) will be made private; do not access directly, use getter/setter
    `protected int` | `name_index` Deprecated. (since 6.0) will be made private; do not access directly, use getter/setter
    `protected byte` | `tag` Deprecated. (since 6.0) will be made private; do not access directly, use getter/setter

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `Attribute(byte tag, int nameIndex, int length, ConstantPool constantPool)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.
    `static void` | `addAttributeReader(String name, AttributeReader attributeReader)` Deprecated. (6.0) Use `addAttributeReader(String, UnknownAttributeReader)` instead
    `static void` | `addAttributeReader(String name, UnknownAttributeReader unknownAttributeReader)` Add an Attribute reader capable of parsing (user-defined) attributes named "name".
    `Object` | `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)` Dump attribute to file stream in binary format.
    `ConstantPool` | `getConstantPool()`
    `int` | `getLength()`
    `String` | `getName()`
    `int` | `getNameIndex()`
    `byte` | `getTag()`
    `protected static void` | `println(String msg)`
    `static Attribute` | `readAttribute(DataInput file, ConstantPool constantPool)` Class method reads one attribute from the input data stream.
    `static Attribute` | `readAttribute(DataInputStream file, ConstantPool constantPool)` Class method reads one attribute from the input data stream.
    `static void` | `removeAttributeReader(String name)` Remove attribute reader
    `void` | `setConstantPool(ConstantPool constantPool)`
    `void` | `setLength(int length)`
    `void` | `setNameIndex(int nameIndex)`
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### 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)

  - ### Method Detail

    - #### addAttributeReader

          @Deprecated
          public static void addAttributeReader(String name,
                                                            AttributeReader attributeReader)

      Deprecated. (6.0) Use `addAttributeReader(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(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(String msg)

    - #### readAttribute

          public static Attribute readAttribute(DataInput file,
                                                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:
        `file` - Input stream
        `constantPool` - Array of constants
      Returns:
        Attribute
      Throws:
        `IOException` - if an I/O error occurs.
      Since:
        6.0
      See Also:
        `Field`, `Method`

    - #### readAttribute

          public static Attribute readAttribute(DataInputStream file,
                                                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:
        `file` - Input stream
        `constantPool` - Array of constants
      Returns:
        Attribute
      Throws:
        `IOException` - if an I/O error occurs.
      See Also:
        `Field`, `Method`

    - #### removeAttributeReader

          public static void removeAttributeReader(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.
      Specified by:
        `accept` in interface `Node`
      Parameters:
        `v` - Visitor object

    - #### clone

          public Object clone()

      Use copy() if you want to have a deep copy(), i.e., with all references copied correctly.
      Overrides:
        `clone` in class `Object`
      Returns:
        shallow copy of this attribute

    - #### copy

          public abstract Attribute copy(ConstantPool constantPool)

      Returns:
        deep copy of this attribute

    - #### dump

          public void dump(DataOutputStream file)
                    throws IOException

      Dump attribute to file stream in binary format.
      Parameters:
        `file` - Output file stream
      Throws:
        `IOException` - if an I/O error occurs.

    - #### getConstantPool

          public final ConstantPool getConstantPool()

      Returns:
        Constant pool used by this object.
      See Also:
        `ConstantPool`

    - #### getLength

          public final int getLength()

      Returns:
        Length of attribute field in bytes.

    - #### getName

          public String getName()

      Returns:
        Name of attribute
      Since:
        6.0

    - #### getNameIndex

          public final int getNameIndex()

      Returns:
        Name index in constant pool of attribute name.

    - #### getTag

          public final byte getTag()

      Returns:
        Tag of attribute, i.e., its type. Value may not be altered, thus there is no setTag() method.

    - #### setConstantPool

          public final void setConstantPool(ConstantPool constantPool)

      Parameters:
        `constantPool` - Constant pool to be used for this object.
      See Also:
        `ConstantPool`

    - #### setLength

          public final void setLength(int length)

      Parameters:
        `length` - length in bytes.

    - #### setNameIndex

          public final void setNameIndex(int nameIndex)

      Parameters:
        `nameIndex` - of attribute.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`
      Returns:
        attribute name.

Copyright © 2004–2022 The Apache Software Foundation. All rights reserved.