Package javassist.bytecode.annotation
Class AnnotationsWriter
- java.lang.Object
-
- javassist.bytecode.annotation.AnnotationsWriter
-
- Direct Known Subclasses:
TypeAnnotationsWriter
public class AnnotationsWriter extends Object
A convenience class for constructing a..Annotations_attribute. See the source code of theAnnotationsAttribute.Copierclass.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
Constructors Constructor Description AnnotationsWriter(OutputStream os, ConstPool cp)Constructs with the given output stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidannotation(int typeIndex, int numMemberValuePairs)Writesannotation.voidannotation(String type, int numMemberValuePairs)Writesannotation.voidannotationValue()Writestagandannotation_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.ConstPoolgetConstPool()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 Detail
-
AnnotationsWriter
public AnnotationsWriter(OutputStream os, ConstPool cp)
Constructs with the given output stream.- Parameters:
os- the output stream.cp- the constant pool.
-
-
Method Detail
-
getConstPool
public ConstPool getConstPool()
Obtains the constant pool given to the constructor.
-
close
public void close() throws IOExceptionCloses the output stream.- Throws:
IOException
-
numParameters
public void numParameters(int num) throws IOExceptionWritesnum_parametersinRuntime(In)VisibleParameterAnnotations_attribute. This method must be followed bynumcalls tonumAnnotations().- Throws:
IOException
-
numAnnotations
public void numAnnotations(int num) throws IOExceptionWritesnum_annotationsinRuntime(In)VisibleAnnotations_attribute. This method must be followed bynumcalls toannotation().- Throws:
IOException
-
annotation
public void annotation(String type, int numMemberValuePairs) throws IOException
Writesannotation. This method must be followed bynumMemberValuePairscalls tomemberValuePair().- Parameters:
type- the annotation interface name.numMemberValuePairs-num_element_value_pairsinannotation.- Throws:
IOException
-
annotation
public void annotation(int typeIndex, int numMemberValuePairs) throws IOExceptionWritesannotation. This method must be followed bynumMemberValuePairscalls tomemberValuePair().- Parameters:
typeIndex-type_indexinannotation.numMemberValuePairs-num_element_value_pairsinannotation.- Throws:
IOException
-
memberValuePair
public void memberValuePair(String memberName) throws IOException
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
public void memberValuePair(int memberNameIndex) throws IOExceptionWrites 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
public void constValueIndex(boolean value) throws IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
public void constValueIndex(byte value) throws IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
public void constValueIndex(char value) throws IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
public void constValueIndex(short value) throws IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
public void constValueIndex(int value) throws IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
public void constValueIndex(long value) throws IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
public void constValueIndex(float value) throws IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
public void constValueIndex(double value) throws IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
public void constValueIndex(String value) throws IOException
Writestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
IOException
-
constValueIndex
public void constValueIndex(int tag, int index) throws IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
tag-taginelement_value.index-const_value_indexinelement_value.- Throws:
IOException
-
enumConstValue
public void enumConstValue(String typeName, String constName) throws IOException
Writestagandenum_const_valueinelement_value.- Parameters:
typeName- the type name of the enum constant.constName- the simple name of the enum constant.- Throws:
IOException
-
enumConstValue
public void enumConstValue(int typeNameIndex, int constNameIndex) throws IOExceptionWritestagandenum_const_valueinelement_value.- Parameters:
typeNameIndex-type_name_indexinelement_value.constNameIndex-const_name_indexinelement_value.- Throws:
IOException
-
classInfoIndex
public void classInfoIndex(String name) throws IOException
Writestagandclass_info_indexinelement_value.- Parameters:
name- the class name.- Throws:
IOException
-
classInfoIndex
public void classInfoIndex(int index) throws IOExceptionWritestagandclass_info_indexinelement_value.- Parameters:
index-class_info_index- Throws:
IOException
-
annotationValue
public void annotationValue() throws IOExceptionWritestagandannotation_valueinelement_value. This method must be followed by a call toannotation().- Throws:
IOException
-
arrayValue
public void arrayValue(int numValues) throws IOExceptionWritestagandarray_valueinelement_value. This method must be followed bynumValuescalls toconstValueIndex(),enumConstValue(), etc.- Parameters:
numValues-num_valuesinarray_value.- Throws:
IOException
-
-