Package javassist.bytecode.annotation
Class AnnotationsWriter
java.lang.Object
javassist.bytecode.annotation.AnnotationsWriter
- Direct Known Subclasses:
TypeAnnotationsWriter
A convenience class for constructing a
..Annotations_attribute.
See the source code of the AnnotationsAttribute.Copier class.
The following code snippet is an example of use of this class:
ConstPool pool = ...;
output = new ByteArrayOutputStream();
writer = new AnnotationsWriter(output, pool);
writer.numAnnotations(1);
writer.annotation("Author", 2);
writer.memberValuePair("name"); // element_value_pair
writer.constValueIndex("chiba");
writer.memberValuePair("address"); // element_value_pair
writer.constValueIndex("tokyo");
writer.close();
byte[] attribute_info = output.toByteArray();
AnnotationsAttribute anno
= new AnnotationsAttribute(pool, AnnotationsAttribute.visibleTag,
attribute_info);
The code snippet above generates the annotation attribute corresponding to this annotation:
@Author(name = "chiba", address = "tokyo")
-
Constructor Summary
ConstructorsConstructorDescriptionAnnotationsWriter(OutputStream os, ConstPool cp) Constructs with the given output stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidannotation(int typeIndex, int numMemberValuePairs) Writesannotation.voidannotation(String type, int numMemberValuePairs) Writesannotation.voidWritestagandannotation_valueinelement_value.voidarrayValue(int numValues) Writestagandarray_valueinelement_value.voidclassInfoIndex(int index) Writestagandclass_info_indexinelement_value.voidclassInfoIndex(String name) Writestagandclass_info_indexinelement_value.voidclose()Closes the output stream.voidconstValueIndex(boolean value) Writestagandconst_value_indexinelement_value.voidconstValueIndex(byte value) Writestagandconst_value_indexinelement_value.voidconstValueIndex(char value) Writestagandconst_value_indexinelement_value.voidconstValueIndex(double value) Writestagandconst_value_indexinelement_value.voidconstValueIndex(float value) Writestagandconst_value_indexinelement_value.voidconstValueIndex(int value) Writestagandconst_value_indexinelement_value.voidconstValueIndex(int tag, int index) Writestagandconst_value_indexinelement_value.voidconstValueIndex(long value) Writestagandconst_value_indexinelement_value.voidconstValueIndex(short value) Writestagandconst_value_indexinelement_value.voidconstValueIndex(String value) Writestagandconst_value_indexinelement_value.voidenumConstValue(int typeNameIndex, int constNameIndex) Writestagandenum_const_valueinelement_value.voidenumConstValue(String typeName, String constName) Writestagandenum_const_valueinelement_value.Obtains the constant pool given to the constructor.voidmemberValuePair(int memberNameIndex) Writes an element of aelement_value_pairsarray inannotation.voidmemberValuePair(String memberName) Writes an element of aelement_value_pairsarray inannotation.voidnumAnnotations(int num) Writesnum_annotationsinRuntime(In)VisibleAnnotations_attribute.voidnumParameters(int num) Writesnum_parametersinRuntime(In)VisibleParameterAnnotations_attribute.
-
Constructor Details
-
AnnotationsWriter
Constructs with the given output stream.- Parameters:
os- the output stream.cp- the constant pool.
-
-
Method Details
-
getConstPool
Obtains the constant pool given to the constructor. -
close
Closes the output stream.- Throws:
IOException
-
numParameters
Writesnum_parametersinRuntime(In)VisibleParameterAnnotations_attribute. This method must be followed bynumcalls tonumAnnotations().- Throws:
IOException
-
numAnnotations
Writesnum_annotationsinRuntime(In)VisibleAnnotations_attribute. This method must be followed bynumcalls toannotation().- Throws:
IOException
-
annotation
Writesannotation. This method must be followed bynumMemberValuePairscalls tomemberValuePair().- Parameters:
type- the annotation interface name.numMemberValuePairs-num_element_value_pairsinannotation.- Throws:
IOException
-
annotation
Writesannotation. This method must be followed bynumMemberValuePairscalls tomemberValuePair().- Parameters:
typeIndex-type_indexinannotation.numMemberValuePairs-num_element_value_pairsinannotation.- Throws:
IOException
-
memberValuePair
Writes an element of aelement_value_pairsarray inannotation. This method must be followed by a call toconstValueIndex(),enumConstValue(), etc.- Parameters:
memberName- the element name.- Throws:
IOException
-
memberValuePair
Writes an element of aelement_value_pairsarray inannotation. This method must be followed by a call toconstValueIndex(),enumConstValue(), etc.- Parameters:
memberNameIndex-element_name_indexinelement_value_pairsarray.- Throws:
IOException
-
constValueIndex
Writestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
Writestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
Writestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
Writestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
Writestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
Writestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
Writestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
Writestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
Writestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
Writestagandconst_value_indexinelement_value.- Parameters:
tag-taginelement_value.index-const_value_indexinelement_value.- Throws:
IOException
-
enumConstValue
Writestagandenum_const_valueinelement_value.- Parameters:
typeName- the type name of the enum constant.constName- the simple name of the enum constant.- Throws:
IOException
-
enumConstValue
Writestagandenum_const_valueinelement_value.- Parameters:
typeNameIndex-type_name_indexinelement_value.constNameIndex-const_name_indexinelement_value.- Throws:
IOException
-
classInfoIndex
Writestagandclass_info_indexinelement_value.- Parameters:
name- the class name.- Throws:
IOException
-
classInfoIndex
Writestagandclass_info_indexinelement_value.- Parameters:
index-class_info_index- Throws:
IOException
-
annotationValue
Writestagandannotation_valueinelement_value. This method must be followed by a call toannotation().- Throws:
IOException
-
arrayValue
Writestagandarray_valueinelement_value. This method must be followed bynumValuescalls toconstValueIndex(),enumConstValue(), etc.- Parameters:
numValues-num_valuesinarray_value.- Throws:
IOException
-