Package javassist.bytecode.annotation
Class AnnotationsWriter
- java.lang.Object
-
- javassist.bytecode.annotation.AnnotationsWriter
-
- Direct Known Subclasses:
TypeAnnotationsWriter
public class AnnotationsWriter extends java.lang.ObjectA 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(java.io.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(java.lang.String type, int numMemberValuePairs)Writesannotation.voidannotationValue()Writestagandannotation_valueinelement_value.voidarrayValue(int numValues)Writestagandarray_valueinelement_value.voidclassInfoIndex(int index)Writestagandclass_info_indexinelement_value.voidclassInfoIndex(java.lang.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(java.lang.String value)Writestagandconst_value_indexinelement_value.voidenumConstValue(int typeNameIndex, int constNameIndex)Writestagandenum_const_valueinelement_value.voidenumConstValue(java.lang.String typeName, java.lang.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(java.lang.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(java.io.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 java.io.IOExceptionCloses the output stream.- Throws:
java.io.IOException
-
numParameters
public void numParameters(int num) throws java.io.IOExceptionWritesnum_parametersinRuntime(In)VisibleParameterAnnotations_attribute. This method must be followed bynumcalls tonumAnnotations().- Throws:
java.io.IOException
-
numAnnotations
public void numAnnotations(int num) throws java.io.IOExceptionWritesnum_annotationsinRuntime(In)VisibleAnnotations_attribute. This method must be followed bynumcalls toannotation().- Throws:
java.io.IOException
-
annotation
public void annotation(java.lang.String type, int numMemberValuePairs) throws java.io.IOExceptionWritesannotation. This method must be followed bynumMemberValuePairscalls tomemberValuePair().- Parameters:
type- the annotation interface name.numMemberValuePairs-num_element_value_pairsinannotation.- Throws:
java.io.IOException
-
annotation
public void annotation(int typeIndex, int numMemberValuePairs) throws java.io.IOExceptionWritesannotation. This method must be followed bynumMemberValuePairscalls tomemberValuePair().- Parameters:
typeIndex-type_indexinannotation.numMemberValuePairs-num_element_value_pairsinannotation.- Throws:
java.io.IOException
-
memberValuePair
public void memberValuePair(java.lang.String memberName) throws java.io.IOExceptionWrites an element of aelement_value_pairsarray inannotation. This method must be followed by a call toconstValueIndex(),enumConstValue(), etc.- Parameters:
memberName- the element name.- Throws:
java.io.IOException
-
memberValuePair
public void memberValuePair(int memberNameIndex) throws java.io.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:
java.io.IOException
-
constValueIndex
public void constValueIndex(boolean value) throws java.io.IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
java.io.IOException
-
constValueIndex
public void constValueIndex(byte value) throws java.io.IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
java.io.IOException
-
constValueIndex
public void constValueIndex(char value) throws java.io.IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
java.io.IOException
-
constValueIndex
public void constValueIndex(short value) throws java.io.IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
java.io.IOException
-
constValueIndex
public void constValueIndex(int value) throws java.io.IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
java.io.IOException
-
constValueIndex
public void constValueIndex(long value) throws java.io.IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
java.io.IOException
-
constValueIndex
public void constValueIndex(float value) throws java.io.IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
java.io.IOException
-
constValueIndex
public void constValueIndex(double value) throws java.io.IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
java.io.IOException
-
constValueIndex
public void constValueIndex(java.lang.String value) throws java.io.IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
value- the constant value.- Throws:
java.io.IOException
-
constValueIndex
public void constValueIndex(int tag, int index) throws java.io.IOExceptionWritestagandconst_value_indexinelement_value.- Parameters:
tag-taginelement_value.index-const_value_indexinelement_value.- Throws:
java.io.IOException
-
enumConstValue
public void enumConstValue(java.lang.String typeName, java.lang.String constName) throws java.io.IOExceptionWritestagandenum_const_valueinelement_value.- Parameters:
typeName- the type name of the enum constant.constName- the simple name of the enum constant.- Throws:
java.io.IOException
-
enumConstValue
public void enumConstValue(int typeNameIndex, int constNameIndex) throws java.io.IOExceptionWritestagandenum_const_valueinelement_value.- Parameters:
typeNameIndex-type_name_indexinelement_value.constNameIndex-const_name_indexinelement_value.- Throws:
java.io.IOException
-
classInfoIndex
public void classInfoIndex(java.lang.String name) throws java.io.IOExceptionWritestagandclass_info_indexinelement_value.- Parameters:
name- the class name.- Throws:
java.io.IOException
-
classInfoIndex
public void classInfoIndex(int index) throws java.io.IOExceptionWritestagandclass_info_indexinelement_value.- Parameters:
index-class_info_index- Throws:
java.io.IOException
-
annotationValue
public void annotationValue() throws java.io.IOExceptionWritestagandannotation_valueinelement_value. This method must be followed by a call toannotation().- Throws:
java.io.IOException
-
arrayValue
public void arrayValue(int numValues) throws java.io.IOExceptionWritestagandarray_valueinelement_value. This method must be followed bynumValuescalls toconstValueIndex(),enumConstValue(), etc.- Parameters:
numValues-num_valuesinarray_value.- Throws:
java.io.IOException
-
-