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
ConstructorDescriptionAnnotationsWriter
(OutputStream os, ConstPool cp) Constructs with the given output stream. -
Method Summary
Modifier and TypeMethodDescriptionvoid
annotation
(int typeIndex, int numMemberValuePairs) Writesannotation
.void
annotation
(String type, int numMemberValuePairs) Writesannotation
.void
Writestag
andannotation_value
inelement_value
.void
arrayValue
(int numValues) Writestag
andarray_value
inelement_value
.void
classInfoIndex
(int index) Writestag
andclass_info_index
inelement_value
.void
classInfoIndex
(String name) Writestag
andclass_info_index
inelement_value
.void
close()
Closes the output stream.void
constValueIndex
(boolean value) Writestag
andconst_value_index
inelement_value
.void
constValueIndex
(byte value) Writestag
andconst_value_index
inelement_value
.void
constValueIndex
(char value) Writestag
andconst_value_index
inelement_value
.void
constValueIndex
(double value) Writestag
andconst_value_index
inelement_value
.void
constValueIndex
(float value) Writestag
andconst_value_index
inelement_value
.void
constValueIndex
(int value) Writestag
andconst_value_index
inelement_value
.void
constValueIndex
(int tag, int index) Writestag
andconst_value_index
inelement_value
.void
constValueIndex
(long value) Writestag
andconst_value_index
inelement_value
.void
constValueIndex
(short value) Writestag
andconst_value_index
inelement_value
.void
constValueIndex
(String value) Writestag
andconst_value_index
inelement_value
.void
enumConstValue
(int typeNameIndex, int constNameIndex) Writestag
andenum_const_value
inelement_value
.void
enumConstValue
(String typeName, String constName) Writestag
andenum_const_value
inelement_value
.Obtains the constant pool given to the constructor.void
memberValuePair
(int memberNameIndex) Writes an element of aelement_value_pairs
array inannotation
.void
memberValuePair
(String memberName) Writes an element of aelement_value_pairs
array inannotation
.void
numAnnotations
(int num) Writesnum_annotations
inRuntime(In)VisibleAnnotations_attribute
.void
numParameters
(int num) Writesnum_parameters
inRuntime(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_parameters
inRuntime(In)VisibleParameterAnnotations_attribute
. This method must be followed bynum
calls tonumAnnotations()
.- Throws:
IOException
-
numAnnotations
Writesnum_annotations
inRuntime(In)VisibleAnnotations_attribute
. This method must be followed bynum
calls toannotation()
.- Throws:
IOException
-
annotation
Writesannotation
. This method must be followed bynumMemberValuePairs
calls tomemberValuePair()
.- Parameters:
type
- the annotation interface name.numMemberValuePairs
-num_element_value_pairs
inannotation
.- Throws:
IOException
-
annotation
Writesannotation
. This method must be followed bynumMemberValuePairs
calls tomemberValuePair()
.- Parameters:
typeIndex
-type_index
inannotation
.numMemberValuePairs
-num_element_value_pairs
inannotation
.- Throws:
IOException
-
memberValuePair
Writes an element of aelement_value_pairs
array 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_pairs
array inannotation
. This method must be followed by a call toconstValueIndex()
,enumConstValue()
, etc.- Parameters:
memberNameIndex
-element_name_index
inelement_value_pairs
array.- Throws:
IOException
-
constValueIndex
Writestag
andconst_value_index
inelement_value
.- Parameters:
value
- the constant value.- Throws:
IOException
-
constValueIndex
Writestag
andconst_value_index
inelement_value
.- Parameters:
value
- the constant value.- Throws:
IOException
-
constValueIndex
Writestag
andconst_value_index
inelement_value
.- Parameters:
value
- the constant value.- Throws:
IOException
-
constValueIndex
Writestag
andconst_value_index
inelement_value
.- Parameters:
value
- the constant value.- Throws:
IOException
-
constValueIndex
Writestag
andconst_value_index
inelement_value
.- Parameters:
value
- the constant value.- Throws:
IOException
-
constValueIndex
Writestag
andconst_value_index
inelement_value
.- Parameters:
value
- the constant value.- Throws:
IOException
-
constValueIndex
Writestag
andconst_value_index
inelement_value
.- Parameters:
value
- the constant value.- Throws:
IOException
-
constValueIndex
Writestag
andconst_value_index
inelement_value
.- Parameters:
value
- the constant value.- Throws:
IOException
-
constValueIndex
Writestag
andconst_value_index
inelement_value
.- Parameters:
value
- the constant value.- Throws:
IOException
-
constValueIndex
Writestag
andconst_value_index
inelement_value
.- Parameters:
tag
-tag
inelement_value
.index
-const_value_index
inelement_value
.- Throws:
IOException
-
enumConstValue
Writestag
andenum_const_value
inelement_value
.- Parameters:
typeName
- the type name of the enum constant.constName
- the simple name of the enum constant.- Throws:
IOException
-
enumConstValue
Writestag
andenum_const_value
inelement_value
.- Parameters:
typeNameIndex
-type_name_index
inelement_value
.constNameIndex
-const_name_index
inelement_value
.- Throws:
IOException
-
classInfoIndex
Writestag
andclass_info_index
inelement_value
.- Parameters:
name
- the class name.- Throws:
IOException
-
classInfoIndex
Writestag
andclass_info_index
inelement_value
.- Parameters:
index
-class_info_index
- Throws:
IOException
-
annotationValue
Writestag
andannotation_value
inelement_value
. This method must be followed by a call toannotation()
.- Throws:
IOException
-
arrayValue
Writestag
andarray_value
inelement_value
. This method must be followed bynumValues
calls toconstValueIndex()
,enumConstValue()
, etc.- Parameters:
numValues
-num_values
inarray_value
.- Throws:
IOException
-