org.objectweb.asm.attrs
Class Annotation

java.lang.Object
  extended byorg.objectweb.asm.attrs.Annotation

public class Annotation
extends Object

Annotation data contains an annotated type and its array of the member-value pairs. Structure is in the following format:

   annotation {
     u2 type_index;
     u2 num_member_value_pairs;
     {
       u2 member_name_index;
       member_value value;
     } member_value_pairs[num_member_value_pairs];
   }
 
The items of the annotation structure are as follows:
type_index
The value of the type_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Class_info structure representing the annotation interface corresponding to the annotation represented by this annotation structure.
num_member_value_pairs
The value of the num_member_value_pairs item gives the number of member-value pairs in the annotation represented by this annotation structure. Note that a maximum of 65535 member-value pairs may be contained in a single annotation.
member_value_pairs
Each value of the member_value_pairs table represents a single member-value pair in the annotation represented by this annotation structure. Each member_value_pairs entry contains the following two items:
member_name_index
The value of the member_name_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure representing the name of the annotation type member corresponding to this member_value_pairs entry.
value
The value item represents the value in the member-value pair represented by this member_value_pairs entry.

Author:
Eugene Kuleshov
See Also:
JSR 175 : A Metadata Facility for the Java Programming Language

Field Summary
 List memberValues
           
 String type
           
 
Constructor Summary
Annotation()
           
 
Method Summary
 void add(String name, Object value)
           
 int read(ClassReader cr, int off, char[] buf)
          Reads annotation data structures.
static int readAnnotations(List annotations, ClassReader cr, int off, char[] buf)
          Utility method to read List of annotations.
static void readParameterAnnotations(List parameters, ClassReader cr, int off, char[] buf)
          Utility method to read List of parameters annotations.
static String stringAnnotations(List annotations)
          Returns annotation values in the format described in JSR-175 for Java source code.
static String stringParameterAnnotations(List parameters)
          Returns parameter annotation values in the format described in JSR-175 for Java source code.
 String toString()
          Returns value in the format described in JSR-175 for Java source code.
 void write(ByteVector bv, ClassWriter cw)
          Writes annotation data structures.
static ByteVector writeAnnotations(ByteVector bv, List annotations, ClassWriter cw)
          Utility method to write List of annotations.
static ByteVector writeParametersAnnotations(ByteVector bv, List parameters, ClassWriter cw)
          Utility method to write List of parameters annotations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

public String type

memberValues

public List memberValues
Constructor Detail

Annotation

public Annotation()
Method Detail

add

public void add(String name,
                Object value)

read

public int read(ClassReader cr,
                int off,
                char[] buf)
Reads annotation data structures.

Parameters:
cr - the class that contains the attribute to be read.
off - index of the first byte of the data structure.
buf - buffer to be used to call readUTF8, readClass or readConst.
Returns:
offset position in bytecode after reading annotation

write

public void write(ByteVector bv,
                  ClassWriter cw)
Writes annotation data structures.

Parameters:
bv - the byte array form to store data structures.
cw - the class to which this attribute must be added. This parameter can be used to add to the constant pool of this class the items that corresponds to this attribute.

readAnnotations

public static int readAnnotations(List annotations,
                                  ClassReader cr,
                                  int off,
                                  char[] buf)
Utility method to read List of annotations. Each element of annotations List will have Annotation instance.

Parameters:
annotations - the List to store parameters annotations.
cr - the class that contains the attribute to be read.
off - index of the first byte of the data structure.
buf - buffer to be used to call readUTF8, readClass or readConst.
Returns:
offset position in bytecode after reading annotations

readParameterAnnotations

public static void readParameterAnnotations(List parameters,
                                            ClassReader cr,
                                            int off,
                                            char[] buf)
Utility method to read List of parameters annotations.

Parameters:
parameters - the List to store parameters annotations. Each element of the parameters List will have List of Annotation instances.
cr - the class that contains the attribute to be read.
off - index of the first byte of the data structure.
buf - buffer to be used to call readUTF8, readClass or readConst.

writeAnnotations

public static ByteVector writeAnnotations(ByteVector bv,
                                          List annotations,
                                          ClassWriter cw)
Utility method to write List of annotations.

Parameters:
bv - the byte array form to store data structures.
annotations - the List of annotations to write. Elements should be instances of the Annotation class.
cw - the class to which this attribute must be added. This parameter can be used to add to the constant pool of this class the items that corresponds to this attribute.
Returns:
the byte array form with saved annotations.

writeParametersAnnotations

public static ByteVector writeParametersAnnotations(ByteVector bv,
                                                    List parameters,
                                                    ClassWriter cw)
Utility method to write List of parameters annotations.

Parameters:
bv - the byte array form to store data structures.
parameters - the List of parametars to write. Elements should be instances of the List that contains instances of the Annotation class.
cw - the class to which this attribute must be added. This parameter can be used to add to the constant pool of this class the items that corresponds to this attribute.
Returns:
the byte array form with saved annotations.

stringAnnotations

public static String stringAnnotations(List annotations)
Returns annotation values in the format described in JSR-175 for Java source code.


stringParameterAnnotations

public static String stringParameterAnnotations(List parameters)
Returns parameter annotation values in the format described in JSR-175 for Java source code.


toString

public String toString()
Returns value in the format described in JSR-175 for Java source code.