Top Description Fields Constructors Methods
org.easymock.asm

pack-priv final Class AnnotationWriter

extends AnnotationVisitor
Class Inheritance

An 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 method. Similarly, arrays of such lists can be used to generate Runtime[In]VisibleParameterAnnotations attributes.
Authors
Eric Bruneton, Eugene Kuleshov
See Also
JVMS 4.7.16, JVMS 4.7.20

Field Summary

Modifier and TypeField and Description
private final 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 final int
numElementValuePairsOffset

The offset in annotation where numElementValuePairs must be stored (or -1 for the case of AnnotationDefault attributes).

private final AnnotationWriter
previousAnnotation

The previous AnnotationWriter.

private final SymbolTable
symbolTable

Where the constants used in this AnnotationWriter must be stored.

private final boolean
useNamedValues

Whether values are named or not.

Inherited from org.easymock.asm.AnnotationVisitor:
apiav

Constructor Summary

AccessConstructor and Description
pack-priv
AnnotationWriter(final SymbolTable
where the constants used in this AnnotationWriter must be stored.
symbolTable
,
final boolean
whether values are named or not. AnnotationDefault and annotation arrays use unnamed values.
useNamedValues
,
final ByteVector
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).
annotation
,
final AnnotationWriter
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).
previousAnnotation
)

Constructs a new AnnotationWriter.

Method Summary

Modifier and TypeMethod and Description
pack-priv int

Returns:

the size in bytes of a Runtime[In]Visible[Type]Annotations attribute containing this annotation and all its predecessors. This includes the size of the attribute_name_index and attribute_length fields.
computeAnnotationsSize
(final String
one of "Runtime[In]Visible[Type]Annotations", or null.
attributeName
)

Returns the size of a Runtime[In]Visible[Type]Annotations attribute containing this annotation and all its predecessors (see previousAnnotation.

pack-priv static int

Returns:

the size in bytes of a Runtime[In]Visible[Type]Annotations attribute containing the given annotations and all their predecessors. This includes the size of the attribute_name_index and attribute_length fields.
computeAnnotationsSize
(final AnnotationWriter
The last runtime visible annotation of a field, method or class. The previous ones can be accessed with the previousAnnotation field. May be null.
lastRuntimeVisibleAnnotation
,
final AnnotationWriter
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.
lastRuntimeInvisibleAnnotation
,
final AnnotationWriter
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.
lastRuntimeVisibleTypeAnnotation
,
final AnnotationWriter
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.
lastRuntimeInvisibleTypeAnnotation
)

Returns the size of the Runtime[In]Visible[Type]Annotations attributes containing the given annotations and all their predecessors (see previousAnnotation.

pack-priv static int

Returns:

the size in bytes of a Runtime[In]VisibleParameterAnnotations attribute corresponding to the given sub-array of AnnotationWriter lists. This includes the size of the attribute_name_index and attribute_length fields.
computeParameterAnnotationsSize
(final String
one of "Runtime[In]VisibleParameterAnnotations".
attributeName
,
final AnnotationWriter[]
an array of AnnotationWriter lists (designated by their last element).
annotationWriters
,
final int
the number of elements in annotationWriters to take into account (elements [0..annotableParameterCount[ are taken into account).
annotableParameterCount
)

Returns the size of a Runtime[In]VisibleParameterAnnotations attribute containing all the annotation lists from the given AnnotationWriter sub-array.

pack-priv static AnnotationWriter

Returns:

a new AnnotationWriter for the given annotation descriptor.
create
(final SymbolTable
where the constants used in this AnnotationWriter must be stored.
symbolTable
,
final String
the class descriptor of the annotation class.
descriptor
,
final AnnotationWriter
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).
previousAnnotation
)

Creates a new AnnotationWriter using named values.

pack-priv static AnnotationWriter

Returns:

a new AnnotationWriter for the given type annotation reference and descriptor.
create
(final SymbolTable
where the constants used in this AnnotationWriter must be stored.
symbolTable
,
final int
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.
typeRef
,
final 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.
typePath
,
final String
the class descriptor of the annotation class.
descriptor
,
final AnnotationWriter
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).
previousAnnotation
)

Creates a new AnnotationWriter using named values.

pack-priv void
putAnnotations(final int
the constant pool index of the attribute name (one of "Runtime[In]Visible[Type]Annotations").
attributeNameIndex
,
final ByteVector
where the attribute must be put.
output
)

Puts a Runtime[In]Visible[Type]Annotations attribute containing this annotations and all its predecessors (see previousAnnotation in the given ByteVector.

pack-priv static void
putAnnotations(final SymbolTable
where the constants used in the AnnotationWriter instances are stored.
symbolTable
,
final AnnotationWriter
The last runtime visible annotation of a field, method or class. The previous ones can be accessed with the previousAnnotation field. May be null.
lastRuntimeVisibleAnnotation
,
final AnnotationWriter
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.
lastRuntimeInvisibleAnnotation
,
final AnnotationWriter
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.
lastRuntimeVisibleTypeAnnotation
,
final AnnotationWriter
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.
lastRuntimeInvisibleTypeAnnotation
,
final ByteVector
where the attributes must be put.
output
)

Puts the Runtime[In]Visible[Type]Annotations attributes containing the given annotations and all their predecessors (see previousAnnotation in the given ByteVector.

pack-priv static void
putParameterAnnotations(final int
constant pool index of the attribute name (one of Runtime[In]VisibleParameterAnnotations).
attributeNameIndex
,
final AnnotationWriter[]
an array of AnnotationWriter lists (designated by their last element).
annotationWriters
,
final int
the number of elements in annotationWriters to put (elements [0..annotableParameterCount[ are put).
annotableParameterCount
,
final ByteVector
where the attribute must be put.
output
)

Puts a Runtime[In]VisibleParameterAnnotations attribute containing all the annotation lists from the given AnnotationWriter sub-array in the given ByteVector.

public void
visit(final String
the value name.
name
,
final Object
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 visitArray and visiting each array element in turn, but is more convenient).
value
)

Overrides org.easymock.asm.AnnotationVisitor.visit.

Visits a primitive value of the annotation.
public AnnotationVisitor
visitAnnotation(final String
the value name.
name
,
final String
the class descriptor of the nested annotation class.
descriptor
)

Overrides org.easymock.asm.AnnotationVisitor.visitAnnotation.

Visits a nested annotation value of the annotation.
public AnnotationVisitor
visitArray(final String
the value name.
name
)

Overrides org.easymock.asm.AnnotationVisitor.visitArray.

Visits an array value of the annotation.
public void
visitEnd()

Overrides org.easymock.asm.AnnotationVisitor.visitEnd.

Visits the end of the annotation.
public void
visitEnum(final String
the value name.
name
,
final String
the class descriptor of the enumeration class.
descriptor
,
final String
the actual enumeration value.
value
)

Overrides org.easymock.asm.AnnotationVisitor.visitEnum.

Visits an enumeration value of the annotation.
Inherited from org.easymock.asm.AnnotationVisitor:
getDelegate

Field Detail

annotationback to summary
private final ByteVector annotation

The 'annotation' or 'type_annotation' JVMS structure corresponding to the annotation values visited so far. All the fields of these structures, except the last one - the element_value_pairs array, must be set before this ByteVector is passed to the constructor (num_element_value_pairs can be set to 0, it is reset to the correct value in 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.

nextAnnotationback to summary
private AnnotationWriter nextAnnotation

The next AnnotationWriter. This field is used to store the list of annotations of a Runtime[In]Visible[Type]Annotations attribute. It is unused for nested or array annotations (annotation values of annotation type), or for AnnotationDefault attributes.

numElementValuePairsback to summary
private int numElementValuePairs

The number of element value pairs visited so far.

numElementValuePairsOffsetback to summary
private final int numElementValuePairsOffset

The offset in annotation where numElementValuePairs must be stored (or -1 for the case of AnnotationDefault attributes).

previousAnnotationback to summary
private final AnnotationWriter previousAnnotation

The previous AnnotationWriter. This field is used to store the list of annotations of a Runtime[In]Visible[Type]Annotations attribute. It is unused for nested or array annotations (annotation values of annotation type), or for AnnotationDefault attributes.

symbolTableback to summary
private final SymbolTable symbolTable

Where the constants used in this AnnotationWriter must be stored.

useNamedValuesback to summary
private final boolean useNamedValues

Whether values are named or not. AnnotationWriter instances used for annotation default and annotation arrays use unnamed values (i.e. they generate an 'element_value' structure for each value, instead of an element_name_index followed by an element_value).

Constructor Detail

AnnotationWriterback to summary
pack-priv AnnotationWriter(final SymbolTable symbolTable, final boolean useNamedValues, final ByteVector annotation, final AnnotationWriter previousAnnotation)

Constructs a new AnnotationWriter.

Parameters
symbolTable:SymbolTable

where the constants used in this AnnotationWriter must be stored.

useNamedValues:boolean

whether values are named or not. AnnotationDefault and annotation arrays use unnamed values.

annotation:ByteVector

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:AnnotationWriter

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).

Method Detail

computeAnnotationsSizeback to summary
pack-priv int computeAnnotationsSize(final String attributeName)

Returns the size of a Runtime[In]Visible[Type]Annotations attribute containing this annotation and all its predecessors (see previousAnnotation. Also adds the attribute name to the constant pool of the class (if not null).

Parameters
attributeName:String

one of "Runtime[In]Visible[Type]Annotations", or null.

Returns:int

the size in bytes of a Runtime[In]Visible[Type]Annotations attribute containing this annotation and all its predecessors. This includes the size of the attribute_name_index and attribute_length fields.

computeAnnotationsSizeback to summary
pack-priv static int computeAnnotationsSize(final AnnotationWriter lastRuntimeVisibleAnnotation, final AnnotationWriter lastRuntimeInvisibleAnnotation, final AnnotationWriter lastRuntimeVisibleTypeAnnotation, final AnnotationWriter lastRuntimeInvisibleTypeAnnotation)

Returns the size of the Runtime[In]Visible[Type]Annotations attributes containing the given annotations and all their predecessors (see previousAnnotation. Also adds the attribute names to the constant pool of the class (if not null).

Parameters
lastRuntimeVisibleAnnotation:AnnotationWriter

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:AnnotationWriter

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:AnnotationWriter

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:AnnotationWriter

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.

Returns:int

the size in bytes of a Runtime[In]Visible[Type]Annotations attribute containing the given annotations and all their predecessors. This includes the size of the attribute_name_index and attribute_length fields.

computeParameterAnnotationsSizeback to summary
pack-priv static int computeParameterAnnotationsSize(final String attributeName, final AnnotationWriter[] annotationWriters, final int annotableParameterCount)

Returns the size of a Runtime[In]VisibleParameterAnnotations attribute containing all the annotation lists from the given AnnotationWriter sub-array. Also adds the attribute name to the constant pool of the class.

Parameters
attributeName:String

one of "Runtime[In]VisibleParameterAnnotations".

annotationWriters:AnnotationWriter[]

an array of AnnotationWriter lists (designated by their last element).

annotableParameterCount:int

the number of elements in annotationWriters to take into account (elements [0..annotableParameterCount[ are taken into account).

Returns:int

the size in bytes of a Runtime[In]VisibleParameterAnnotations attribute corresponding to the given sub-array of AnnotationWriter lists. This includes the size of the attribute_name_index and attribute_length fields.

createback to summary
pack-priv static AnnotationWriter create(final SymbolTable symbolTable, final String descriptor, final AnnotationWriter previousAnnotation)

Creates a new AnnotationWriter using named values.

Parameters
symbolTable:SymbolTable

where the constants used in this AnnotationWriter must be stored.

descriptor:String

the class descriptor of the annotation class.

previousAnnotation:AnnotationWriter

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).

Returns:AnnotationWriter

a new AnnotationWriter for the given annotation descriptor.

createback to summary
pack-priv static AnnotationWriter create(final SymbolTable symbolTable, final int typeRef, final TypePath typePath, final String descriptor, final AnnotationWriter previousAnnotation)

Creates a new AnnotationWriter using named values.

Parameters
symbolTable:SymbolTable

where the constants used in this AnnotationWriter must be stored.

typeRef:int

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: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:String

the class descriptor of the annotation class.

previousAnnotation:AnnotationWriter

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).

Returns:AnnotationWriter

a new AnnotationWriter for the given type annotation reference and descriptor.

putAnnotationsback to summary
pack-priv void putAnnotations(final int attributeNameIndex, final ByteVector output)

Puts a Runtime[In]Visible[Type]Annotations attribute containing this annotations and all its predecessors (see previousAnnotation in the given ByteVector. Annotations are put in the same order they have been visited.

Parameters
attributeNameIndex:int

the constant pool index of the attribute name (one of "Runtime[In]Visible[Type]Annotations").

output:ByteVector

where the attribute must be put.

putAnnotationsback to summary
pack-priv static void putAnnotations(final SymbolTable symbolTable, final AnnotationWriter lastRuntimeVisibleAnnotation, final AnnotationWriter lastRuntimeInvisibleAnnotation, final AnnotationWriter lastRuntimeVisibleTypeAnnotation, final AnnotationWriter lastRuntimeInvisibleTypeAnnotation, final ByteVector output)

Puts the Runtime[In]Visible[Type]Annotations attributes containing the given annotations and all their predecessors (see previousAnnotation in the given ByteVector. Annotations are put in the same order they have been visited.

Parameters
symbolTable:SymbolTable

where the constants used in the AnnotationWriter instances are stored.

lastRuntimeVisibleAnnotation:AnnotationWriter

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:AnnotationWriter

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:AnnotationWriter

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:AnnotationWriter

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:ByteVector

where the attributes must be put.

putParameterAnnotationsback to summary
pack-priv static void putParameterAnnotations(final int attributeNameIndex, final AnnotationWriter[] annotationWriters, final int annotableParameterCount, final ByteVector output)

Puts a Runtime[In]VisibleParameterAnnotations attribute containing all the annotation lists from the given AnnotationWriter sub-array in the given ByteVector.

Parameters
attributeNameIndex:int

constant pool index of the attribute name (one of Runtime[In]VisibleParameterAnnotations).

annotationWriters:AnnotationWriter[]

an array of AnnotationWriter lists (designated by their last element).

annotableParameterCount:int

the number of elements in annotationWriters to put (elements [0..annotableParameterCount[ are put).

output:ByteVector

where the attribute must be put.

visitback to summary
public void visit(final String name, final Object value)

Overrides org.easymock.asm.AnnotationVisitor.visit.

Doc from org.easymock.asm.AnnotationVisitor.visit.

Visits a primitive value of the annotation.

Parameters
name:String

the value name.

value:Object

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 visitArray and visiting each array element in turn, but is more convenient).

Annotations
@Override
visitAnnotationback to summary
public AnnotationVisitor visitAnnotation(final String name, final String descriptor)

Overrides org.easymock.asm.AnnotationVisitor.visitAnnotation.

Doc from org.easymock.asm.AnnotationVisitor.visitAnnotation.

Visits a nested annotation value of the annotation.

Parameters
name:String

the value name.

descriptor:String

the class descriptor of the nested annotation class.

Returns:AnnotationVisitor

a visitor to visit the actual nested annotation value, or null if this visitor is not interested in visiting this nested annotation. The nested annotation value must be fully visited before calling other methods on this annotation visitor.

Annotations
@Override
visitArrayback to summary
public AnnotationVisitor visitArray(final String name)

Overrides org.easymock.asm.AnnotationVisitor.visitArray.

Doc from org.easymock.asm.AnnotationVisitor.visitArray.

Visits an array value of the annotation. Note that arrays of primitive values (such as byte, boolean, short, char, int, long, float or double) can be passed as value to visit. This is what ClassReader does for non empty arrays of primitive values.

Parameters
name:String

the value name.

Returns:AnnotationVisitor

a visitor to visit the actual array value elements, or null if this visitor is not interested in visiting these values. The 'name' parameters passed to the methods of this visitor are ignored. All the array values must be visited before calling other methods on this annotation visitor.

Annotations
@Override
visitEndback to summary
public void visitEnd()

Overrides org.easymock.asm.AnnotationVisitor.visitEnd.

Doc from org.easymock.asm.AnnotationVisitor.visitEnd.

Visits the end of the annotation.

Annotations
@Override
visitEnumback to summary
public void visitEnum(final String name, final String descriptor, final String value)

Overrides org.easymock.asm.AnnotationVisitor.visitEnum.

Doc from org.easymock.asm.AnnotationVisitor.visitEnum.

Visits an enumeration value of the annotation.

Parameters
name:String

the value name.

descriptor:String

the class descriptor of the enumeration class.

value:String

the actual enumeration value.

Annotations
@Override