Class Annotation


  • public class Annotation
    extends Object
    A parsed annotation: its type descriptor index and element-value pairs.
    • Constructor Detail

      • Annotation

        public Annotation​(ConstPool constPool,
                          int typeIndex,
                          int numElementValuePairs,
                          List<ElementValuePair> elementValuePairs)
        Creates an annotation.
        Parameters:
        constPool - the pool used to resolve indices
        typeIndex - constant-pool index of the annotation type descriptor Utf8
        numElementValuePairs - the declared pair count
        elementValuePairs - the element-value pairs
    • Method Detail

      • getTypeIndex

        public int getTypeIndex()
        Returns:
        the type index
      • getNumElementValuePairs

        public int getNumElementValuePairs()
        Returns:
        the num element value pairs
      • getElementValuePairs

        public List<ElementValuePair> getElementValuePairs()
        Returns:
        the element value pairs
      • readAnnotation

        public static Annotation readAnnotation​(ClassFile classFile,
                                                ConstPool constPool)
        Reads an annotation structure from the class file.
        Parameters:
        classFile - the class file to read from
        constPool - the constant pool
        Returns:
        the parsed annotation
      • write

        public void write​(DataOutputStream dos)
                   throws IOException
        Writes this annotation to the output stream.
        Parameters:
        dos - the output stream
        Throws:
        IOException - if an I/O error occurs
      • getLength

        public int getLength()
        Calculates the total length of this annotation in bytes.
        Returns:
        the length in bytes