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 . |
Modifier and Type | Method and Description |
---|---|
(package private) static int |
computeAnnotationsSize(AnnotationWriter lastRuntimeVisibleAnnotation,
AnnotationWriter lastRuntimeInvisibleAnnotation,
AnnotationWriter lastRuntimeVisibleTypeAnnotation,
AnnotationWriter lastRuntimeInvisibleTypeAnnotation)
Returns the size of the Runtime[In]Visible[Type]Annotations attributes containing the given
annotations and all their predecessors (see
previousAnnotation . |
(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) static AnnotationWriter |
create(SymbolTable symbolTable,
int typeRef,
TypePath typePath,
java.lang.String descriptor,
AnnotationWriter previousAnnotation)
Creates a new
AnnotationWriter using named values. |
(package private) static AnnotationWriter |
create(SymbolTable symbolTable,
java.lang.String descriptor,
AnnotationWriter previousAnnotation)
Creates a new
AnnotationWriter using named values. |
(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 |
putAnnotations(SymbolTable symbolTable,
AnnotationWriter lastRuntimeVisibleAnnotation,
AnnotationWriter lastRuntimeInvisibleAnnotation,
AnnotationWriter lastRuntimeVisibleTypeAnnotation,
AnnotationWriter lastRuntimeInvisibleTypeAnnotation,
ByteVector output)
Puts the Runtime[In]Visible[Type]Annotations attributes containing the given annotations and
all their 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).static AnnotationWriter create(SymbolTable symbolTable, java.lang.String descriptor, AnnotationWriter previousAnnotation)
AnnotationWriter
using named values.symbolTable
- where the constants used in this AnnotationWriter must be stored.descriptor
- the class descriptor of the annotation class.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
for the given annotation descriptor.static AnnotationWriter create(SymbolTable symbolTable, int typeRef, TypePath typePath, java.lang.String descriptor, AnnotationWriter previousAnnotation)
AnnotationWriter
using named values.symbolTable
- where the constants used in this AnnotationWriter must be stored.typeRef
- a reference to the annotated type. The sort of this type reference must be
TypeReference.CLASS_TYPE_PARAMETER
, TypeReference.CLASS_TYPE_PARAMETER_BOUND
or TypeReference.CLASS_EXTENDS
. See
TypeReference
.typePath
- the path to the annotated type argument, wildcard bound, array element type, or
static inner type within 'typeRef'. May be null if the annotation targets
'typeRef' as a whole.descriptor
- the class descriptor of the annotation class.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
for the given type annotation reference and descriptor.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.static int computeAnnotationsSize(AnnotationWriter lastRuntimeVisibleAnnotation, AnnotationWriter lastRuntimeInvisibleAnnotation, AnnotationWriter lastRuntimeVisibleTypeAnnotation, AnnotationWriter lastRuntimeInvisibleTypeAnnotation)
previousAnnotation
. Also adds the
attribute names to the constant pool of the class (if not null).lastRuntimeVisibleAnnotation
- The last runtime visible annotation of a field, method or
class. The previous ones can be accessed with the previousAnnotation
field. May be
null.lastRuntimeInvisibleAnnotation
- The last runtime invisible annotation of this a field,
method or class. The previous ones can be accessed with the previousAnnotation
field. May be null.lastRuntimeVisibleTypeAnnotation
- The last runtime visible type annotation of this a
field, method or class. The previous ones can be accessed with the previousAnnotation
field. May be null.lastRuntimeInvisibleTypeAnnotation
- The last runtime invisible type annotation of a
field, method or class field. The previous ones can be accessed with the previousAnnotation
field. May be 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 void putAnnotations(SymbolTable symbolTable, AnnotationWriter lastRuntimeVisibleAnnotation, AnnotationWriter lastRuntimeInvisibleAnnotation, AnnotationWriter lastRuntimeVisibleTypeAnnotation, AnnotationWriter lastRuntimeInvisibleTypeAnnotation, ByteVector output)
previousAnnotation
in the given ByteVector.
Annotations are put in the same order they have been visited.symbolTable
- where the constants used in the AnnotationWriter instances are stored.lastRuntimeVisibleAnnotation
- The last runtime visible annotation of a field, method or
class. The previous ones can be accessed with the previousAnnotation
field. May be
null.lastRuntimeInvisibleAnnotation
- The last runtime invisible annotation of this a field,
method or class. The previous ones can be accessed with the previousAnnotation
field. May be null.lastRuntimeVisibleTypeAnnotation
- The last runtime visible type annotation of this a
field, method or class. The previous ones can be accessed with the previousAnnotation
field. May be null.lastRuntimeInvisibleTypeAnnotation
- The last runtime invisible type annotation of a
field, method or class field. The previous ones can be accessed with the previousAnnotation
field. May be null.output
- where the attributes 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.