final class AnnotationWriter extends AnnotationVisitor
AnnotationVisitor
that generates a corresponding 'annotation' or 'type_annotation'
structure, as defined in the Java Virtual Machine Specification (JVMS). AnnotationWriter
instances can be chained in a doubly linked list, from which Runtime[In]Visible[Type]Annotations
attributes can be generated with the putAnnotations(int, org.springframework.asm.ByteVector)
method. Similarly, arrays of such
lists can be used to generate Runtime[In]VisibleParameterAnnotations attributes.Modifier and Type | Field and Description |
---|---|
private ByteVector |
annotation
The 'annotation' or 'type_annotation' JVMS structure corresponding to the annotation values
visited so far.
|
private AnnotationWriter |
nextAnnotation
The next AnnotationWriter.
|
private int |
numElementValuePairs
The number of element value pairs visited so far.
|
private int |
numElementValuePairsOffset
The offset in
annotation where numElementValuePairs must be stored (or -1 for
the case of AnnotationDefault attributes). |
private AnnotationWriter |
previousAnnotation
The previous AnnotationWriter.
|
private SymbolTable |
symbolTable
Where the constants used in this AnnotationWriter must be stored.
|
private boolean |
useNamedValues
Whether values are named or not.
|
api, av
Constructor and Description |
---|
AnnotationWriter(SymbolTable symbolTable,
boolean useNamedValues,
ByteVector annotation,
AnnotationWriter previousAnnotation)
Constructs a new
AnnotationWriter . |
AnnotationWriter(SymbolTable symbolTable,
ByteVector annotation,
AnnotationWriter previousAnnotation)
Constructs a new
AnnotationWriter using named values. |
Modifier and Type | Method and Description |
---|---|
(package private) int |
computeAnnotationsSize(java.lang.String attributeName)
Returns the size of a Runtime[In]Visible[Type]Annotations attribute containing this annotation
and all its predecessors (see
previousAnnotation . |
(package private) static int |
computeParameterAnnotationsSize(java.lang.String attributeName,
AnnotationWriter[] annotationWriters,
int annotableParameterCount)
Returns the size of a Runtime[In]VisibleParameterAnnotations attribute containing all the
annotation lists from the given AnnotationWriter sub-array.
|
(package private) void |
putAnnotations(int attributeNameIndex,
ByteVector output)
Puts a Runtime[In]Visible[Type]Annotations attribute containing this annotations and all its
predecessors (see
previousAnnotation in the given ByteVector. |
(package private) static void |
putParameterAnnotations(int attributeNameIndex,
AnnotationWriter[] annotationWriters,
int annotableParameterCount,
ByteVector output)
Puts a Runtime[In]VisibleParameterAnnotations attribute containing all the annotation lists
from the given AnnotationWriter sub-array in the given ByteVector.
|
void |
visit(java.lang.String name,
java.lang.Object value)
Visits a primitive value of the annotation.
|
AnnotationVisitor |
visitAnnotation(java.lang.String name,
java.lang.String descriptor)
Visits a nested annotation value of the annotation.
|
AnnotationVisitor |
visitArray(java.lang.String name)
Visits an array value of the annotation.
|
void |
visitEnd()
Visits the end of the annotation.
|
void |
visitEnum(java.lang.String name,
java.lang.String descriptor,
java.lang.String value)
Visits an enumeration value of the annotation.
|
private final SymbolTable symbolTable
private final boolean useNamedValues
private final ByteVector annotation
visitEnd()
). The element_value_pairs array is filled incrementally in the various visit()
methods.
Note: as an exception to the above rules, for AnnotationDefault attributes (which contain a
single element_value by definition), this ByteVector is initially empty when passed to the
constructor, and numElementValuePairsOffset
is set to -1.
private final int numElementValuePairsOffset
annotation
where numElementValuePairs
must be stored (or -1 for
the case of AnnotationDefault attributes).private int numElementValuePairs
private final AnnotationWriter previousAnnotation
private AnnotationWriter nextAnnotation
AnnotationWriter(SymbolTable symbolTable, boolean useNamedValues, ByteVector annotation, AnnotationWriter previousAnnotation)
AnnotationWriter
.symbolTable
- where the constants used in this AnnotationWriter must be stored.useNamedValues
- whether values are named or not. AnnotationDefault and annotation arrays
use unnamed values.annotation
- where the 'annotation' or 'type_annotation' JVMS structure corresponding to
the visited content must be stored. This ByteVector must already contain all the fields of
the structure except the last one (the element_value_pairs array).previousAnnotation
- the previously visited annotation of the
Runtime[In]Visible[Type]Annotations attribute to which this annotation belongs, or null in
other cases (e.g. nested or array annotations).AnnotationWriter(SymbolTable symbolTable, ByteVector annotation, AnnotationWriter previousAnnotation)
AnnotationWriter
using named values.symbolTable
- where the constants used in this AnnotationWriter must be stored.annotation
- where the 'annotation' or 'type_annotation' JVMS structure corresponding to
the visited content must be stored. This ByteVector must already contain all the fields of
the structure except the last one (the element_value_pairs array).previousAnnotation
- the previously visited annotation of the
Runtime[In]Visible[Type]Annotations attribute to which this annotation belongs, or null in
other cases (e.g. nested or array annotations).public void visit(java.lang.String name, java.lang.Object value)
AnnotationVisitor
visit
in class AnnotationVisitor
name
- the value name.value
- the actual value, whose type must be Byte
, Boolean
, Character
, Short
, Integer
, Long
, Float
, Double
,
String
or Type
of Type.OBJECT
or Type.ARRAY
sort. This
value can also be an array of byte, boolean, short, char, int, long, float or double values
(this is equivalent to using AnnotationVisitor.visitArray(java.lang.String)
and visiting each array element in turn,
but is more convenient).public void visitEnum(java.lang.String name, java.lang.String descriptor, java.lang.String value)
AnnotationVisitor
visitEnum
in class AnnotationVisitor
name
- the value name.descriptor
- the class descriptor of the enumeration class.value
- the actual enumeration value.public AnnotationVisitor visitAnnotation(java.lang.String name, java.lang.String descriptor)
AnnotationVisitor
visitAnnotation
in class AnnotationVisitor
name
- the value name.descriptor
- the class descriptor of the nested annotation class.public AnnotationVisitor visitArray(java.lang.String name)
AnnotationVisitor
visit
. This is what ClassReader
does.visitArray
in class AnnotationVisitor
name
- the value name.public void visitEnd()
AnnotationVisitor
visitEnd
in class AnnotationVisitor
int computeAnnotationsSize(java.lang.String attributeName)
previousAnnotation
. Also adds the attribute name
to the constant pool of the class (if not null).attributeName
- one of "Runtime[In]Visible[Type]Annotations", or null.void putAnnotations(int attributeNameIndex, ByteVector output)
previousAnnotation
in the given ByteVector. Annotations are
put in the same order they have been visited.attributeNameIndex
- the constant pool index of the attribute name (one of
"Runtime[In]Visible[Type]Annotations").output
- where the attribute must be put.static int computeParameterAnnotationsSize(java.lang.String attributeName, AnnotationWriter[] annotationWriters, int annotableParameterCount)
attributeName
- one of "Runtime[In]VisibleParameterAnnotations".annotationWriters
- an array of AnnotationWriter lists (designated by their last
element).annotableParameterCount
- the number of elements in annotationWriters to take into account
(elements [0..annotableParameterCount[ are taken into account).static void putParameterAnnotations(int attributeNameIndex, AnnotationWriter[] annotationWriters, int annotableParameterCount, ByteVector output)
attributeNameIndex
- constant pool index of the attribute name (one of
Runtime[In]VisibleParameterAnnotations).annotationWriters
- an array of AnnotationWriter lists (designated by their last
element).annotableParameterCount
- the number of elements in annotationWriters to put (elements
[0..annotableParameterCount[ are put).output
- where the attribute must be put.