Class Attribute

    • Constructor Detail

      • Attribute

        public Attribute​(String name,
                         MemberEntry parent,
                         int nameIndex,
                         int length)
        Creates an attribute attached to a field or method.
        Parameters:
        name - the attribute name
        parent - the member the attribute belongs to
        nameIndex - constant-pool index of the name Utf8
        length - the attribute length in bytes
      • Attribute

        public Attribute​(String name,
                         ClassFile hostClass,
                         int nameIndex,
                         int length)
        Creates a class-level attribute.
        Parameters:
        name - the attribute name
        hostClass - the class the attribute belongs to
        nameIndex - constant-pool index of the name Utf8
        length - the attribute length in bytes
    • Method Detail

      • read

        public abstract void read​(ClassFile classFile,
                                  int length)
        Reads the attribute data from the class file.
        Parameters:
        classFile - The ClassFile utility to read data.
        length - The length of the attribute.
      • get

        public static Attribute get​(ClassFile classFile,
                                    ConstPool constPool,
                                    MemberEntry parent)
        Factory method to instantiate the appropriate Attribute subclass based on the attribute name.
        Parameters:
        classFile - The ClassFile utility to read data.
        constPool - The constant pool for resolving attribute names.
        parent - The parent MemberEntry (e.g., FieldEntry, MethodEntry).
        Returns:
        An instance of the appropriate Attribute subclass.
      • write

        public void write​(DataOutputStream dos)
                   throws IOException
        Writes the attribute to the output stream.
        Parameters:
        dos - The output stream to write to
        Throws:
        IOException - If an I/O error occurs
      • updateLength

        public abstract void updateLength()
        Recomputes the attribute length field from the current in-memory content.