类 AnnotationWriter
java.lang.Object
cn.taketoday.bytecode.AnnotationVisitor
cn.taketoday.bytecode.AnnotationWriter
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(int, cn.taketoday.bytecode.ByteVector) method. Similarly, arrays of such
lists can be used to generate Runtime[In]VisibleParameterAnnotations attributes.- 作者:
- Eric Bruneton, Eugene Kuleshov
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private final ByteVectorThe 'annotation' or 'type_annotation' JVMS structure corresponding to the annotation values visited so far.private AnnotationWriterThe next AnnotationWriter.private intThe number of element value pairs visited so far.private final intThe offset inannotationwherenumElementValuePairsmust be stored (or -1 for the case of AnnotationDefault attributes).private final AnnotationWriterThe previous AnnotationWriter.private final SymbolTableWhere the constants used in this AnnotationWriter must be stored.private final booleanWhether values are named or not.从类继承的字段 cn.taketoday.bytecode.AnnotationVisitor
av -
构造器概要
构造器构造器说明AnnotationWriter(SymbolTable symbolTable, boolean useNamedValues, ByteVector annotation, AnnotationWriter previousAnnotation) Constructs a newAnnotationWriter. -
方法概要
修饰符和类型方法说明(专用程序包) static intcomputeAnnotationsSize(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 (seepreviousAnnotation.(专用程序包) intcomputeAnnotationsSize(String attributeName) Returns the size of a Runtime[In]Visible[Type]Annotations attribute containing this annotation and all its predecessors (seepreviousAnnotation.(专用程序包) static intcomputeParameterAnnotationsSize(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.(专用程序包) static AnnotationWritercreate(SymbolTable symbolTable, int typeRef, TypePath typePath, String descriptor, AnnotationWriter previousAnnotation) Creates a newAnnotationWriterusing named values.(专用程序包) static AnnotationWritercreate(SymbolTable symbolTable, String descriptor, AnnotationWriter previousAnnotation) Creates a newAnnotationWriterusing named values.(专用程序包) voidputAnnotations(int attributeNameIndex, ByteVector output) Puts a Runtime[In]Visible[Type]Annotations attribute containing this annotations and all its predecessors (seepreviousAnnotationin the given ByteVector.(专用程序包) static voidputAnnotations(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 (seepreviousAnnotationin the given ByteVector.(专用程序包) static voidputParameterAnnotations(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.voidVisits a primitive value of the annotation.visitAnnotation(String name, String descriptor) Visits a nested annotation value of the annotation.visitArray(String name) Visits an array value of the annotation.voidvisitEnd()Visits the end of the annotation.voidVisits an enumeration value of the annotation.
-
字段详细资料
-
symbolTable
Where the constants used in this AnnotationWriter must be stored. -
useNamedValues
private final boolean useNamedValuesWhether 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). -
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 invisitEnd()). 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
numElementValuePairsOffsetis set to -1. -
numElementValuePairsOffset
private final int numElementValuePairsOffsetThe offset inannotationwherenumElementValuePairsmust be stored (or -1 for the case of AnnotationDefault attributes). -
numElementValuePairs
private int numElementValuePairsThe number of element value pairs visited so far. -
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. -
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.
-
-
构造器详细资料
-
AnnotationWriter
AnnotationWriter(SymbolTable symbolTable, boolean useNamedValues, ByteVector annotation, AnnotationWriter previousAnnotation) Constructs a newAnnotationWriter.- 参数:
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).
-
-
方法详细资料
-
create
static AnnotationWriter create(SymbolTable symbolTable, String descriptor, AnnotationWriter previousAnnotation) Creates a newAnnotationWriterusing 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).- 返回:
- a new
AnnotationWriterfor the given annotation descriptor.
-
create
static AnnotationWriter create(SymbolTable symbolTable, int typeRef, TypePath typePath, String descriptor, AnnotationWriter previousAnnotation) Creates a newAnnotationWriterusing 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 beTypeReference.CLASS_TYPE_PARAMETER,TypeReference.CLASS_TYPE_PARAMETER_BOUNDorTypeReference.CLASS_EXTENDS. SeeTypeReference.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).- 返回:
- a new
AnnotationWriterfor the given type annotation reference and descriptor.
-
visit
从类复制的说明:AnnotationVisitorVisits a primitive value of the annotation.- 覆盖:
visit在类中AnnotationVisitor- 参数:
name- the value name.value- the actual value, whose type must beByte,Boolean,Character,Short,Integer,Long,Float,Double,StringorTypeofType.OBJECTorType.ARRAYsort. This value can also be an array of byte, boolean, short, char, int, long, float or double values (this is equivalent to usingAnnotationVisitor.visitArray(java.lang.String)and visiting each array element in turn, but is more convenient).
-
visitEnum
从类复制的说明:AnnotationVisitorVisits an enumeration value of the annotation.- 覆盖:
visitEnum在类中AnnotationVisitor- 参数:
name- the value name.descriptor- the class descriptor of the enumeration class.value- the actual enumeration value.
-
visitAnnotation
从类复制的说明:AnnotationVisitorVisits a nested annotation value of the annotation.- 覆盖:
visitAnnotation在类中AnnotationVisitor- 参数:
name- the value name.descriptor- the class descriptor of the nested annotation class.- 返回:
- 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.
-
visitArray
从类复制的说明:AnnotationVisitorVisits 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 tovisit. This is whatClassReaderdoes for non empty arrays of primitive values.- 覆盖:
visitArray在类中AnnotationVisitor- 参数:
name- the value name.- 返回:
- 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.
-
visitEnd
public void visitEnd()从类复制的说明:AnnotationVisitorVisits the end of the annotation.- 覆盖:
visitEnd在类中AnnotationVisitor
-
computeAnnotationsSize
Returns the size of a Runtime[In]Visible[Type]Annotations attribute containing this annotation and all its predecessors (seepreviousAnnotation. 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.- 返回:
- 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
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 (seepreviousAnnotation. 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 thepreviousAnnotationfield. May be null.lastRuntimeInvisibleAnnotation- The last runtime invisible annotation of this a field, method or class. The previous ones can be accessed with thepreviousAnnotationfield. May be null.lastRuntimeVisibleTypeAnnotation- The last runtime visible type annotation of this a field, method or class. The previous ones can be accessed with thepreviousAnnotationfield. May be null.lastRuntimeInvisibleTypeAnnotation- The last runtime invisible type annotation of a field, method or class field. The previous ones can be accessed with thepreviousAnnotationfield. May be null.- 返回:
- 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.
-
putAnnotations
Puts a Runtime[In]Visible[Type]Annotations attribute containing this annotations and all its predecessors (seepreviousAnnotationin 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.
-
putAnnotations
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 (seepreviousAnnotationin 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 thepreviousAnnotationfield. May be null.lastRuntimeInvisibleAnnotation- The last runtime invisible annotation of this a field, method or class. The previous ones can be accessed with thepreviousAnnotationfield. May be null.lastRuntimeVisibleTypeAnnotation- The last runtime visible type annotation of this a field, method or class. The previous ones can be accessed with thepreviousAnnotationfield. May be null.lastRuntimeInvisibleTypeAnnotation- The last runtime invisible type annotation of a field, method or class field. The previous ones can be accessed with thepreviousAnnotationfield. May be null.output- where the attributes must be put.
-
computeParameterAnnotationsSize
static int computeParameterAnnotationsSize(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. Also adds the attribute name to the constant pool of the class.- 参数:
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).- 返回:
- 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.
-
putParameterAnnotations
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.- 参数:
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.
-