public class AnnotationsWriter extends Object
..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");
writer.constValueIndex("chiba");
writer.memberValuePair("address");
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 and Description |
|---|
AnnotationsWriter(OutputStream os,
ConstPool cp)
Constructs with the given output stream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
annotation(int typeIndex,
int numMemberValuePairs)
Writes
annotation. |
void |
annotation(String type,
int numMemberValuePairs)
Writes
annotation. |
void |
annotationValue()
Writes
tag and annotation_value
in member_value. |
void |
arrayValue(int numValues)
Writes
tag and array_value
in member_value. |
void |
classInfoIndex(int index)
Writes
tag and class_info_index
in member_value. |
void |
classInfoIndex(String name)
Writes
tag and class_info_index
in member_value. |
void |
close()
Closes the output stream.
|
void |
constValueIndex(boolean value)
Writes
tag and const_value_index
in member_value. |
void |
constValueIndex(byte value)
Writes
tag and const_value_index
in member_value. |
void |
constValueIndex(char value)
Writes
tag and const_value_index
in member_value. |
void |
constValueIndex(double value)
Writes
tag and const_value_index
in member_value. |
void |
constValueIndex(float value)
Writes
tag and const_value_index
in member_value. |
void |
constValueIndex(int value)
Writes
tag and const_value_index
in member_value. |
void |
constValueIndex(int tag,
int index)
Writes
tag and const_value_index
in member_value. |
void |
constValueIndex(long value)
Writes
tag and const_value_index
in member_value. |
void |
constValueIndex(short value)
Writes
tag and const_value_index
in member_value. |
void |
constValueIndex(String value)
Writes
tag and const_value_index
in member_value. |
void |
enumConstValue(int typeNameIndex,
int constNameIndex)
Writes
tag and enum_const_value
in member_value. |
void |
enumConstValue(String typeName,
String constName)
Writes
tag and enum_const_value
in member_value. |
ConstPool |
getConstPool()
Obtains the constant pool given to the constructor.
|
void |
memberValuePair(int memberNameIndex)
Writes an element of a
member_value_pairs array
in annotation. |
void |
memberValuePair(String memberName)
Writes an element of a
member_value_pairs array
in annotation. |
void |
numAnnotations(int num)
Writes
num_annotations in
Runtime(In)VisibleAnnotations_attribute. |
void |
numParameters(int num)
Writes
num_parameters in
Runtime(In)VisibleParameterAnnotations_attribute. |
public AnnotationsWriter(OutputStream os, ConstPool cp)
os - the output stream.cp - the constant pool.public ConstPool getConstPool()
public void close()
throws IOException
IOExceptionpublic void numParameters(int num)
throws IOException
num_parameters in
Runtime(In)VisibleParameterAnnotations_attribute.
This method must be followed by num calls to
numAnnotations().IOExceptionpublic void numAnnotations(int num)
throws IOException
num_annotations in
Runtime(In)VisibleAnnotations_attribute.
This method must be followed by num calls to
annotation().IOExceptionpublic void annotation(String type, int numMemberValuePairs) throws IOException
annotation.
This method must be followed by numMemberValuePairs
calls to memberValuePair().type - the annotation interface name.numMemberValuePairs - num_member_value_pairs
in annotation.IOExceptionpublic void annotation(int typeIndex,
int numMemberValuePairs)
throws IOException
annotation.
This method must be followed by numMemberValuePairs
calls to memberValuePair().typeIndex - type_index in annotation.numMemberValuePairs - num_member_value_pairs
in annotation.IOExceptionpublic void memberValuePair(String memberName) throws IOException
member_value_pairs array
in annotation.
This method must be followed by a
call to constValueIndex(), enumConstValue(),
etc.memberName - the name of the annotation type member.IOExceptionpublic void memberValuePair(int memberNameIndex)
throws IOException
member_value_pairs array
in annotation.
This method must be followed by a
call to constValueIndex(), enumConstValue(),
etc.memberNameIndex - member_name_index
in member_value_pairs array.IOExceptionpublic void constValueIndex(boolean value)
throws IOException
tag and const_value_index
in member_value.value - the constant value.IOExceptionpublic void constValueIndex(byte value)
throws IOException
tag and const_value_index
in member_value.value - the constant value.IOExceptionpublic void constValueIndex(char value)
throws IOException
tag and const_value_index
in member_value.value - the constant value.IOExceptionpublic void constValueIndex(short value)
throws IOException
tag and const_value_index
in member_value.value - the constant value.IOExceptionpublic void constValueIndex(int value)
throws IOException
tag and const_value_index
in member_value.value - the constant value.IOExceptionpublic void constValueIndex(long value)
throws IOException
tag and const_value_index
in member_value.value - the constant value.IOExceptionpublic void constValueIndex(float value)
throws IOException
tag and const_value_index
in member_value.value - the constant value.IOExceptionpublic void constValueIndex(double value)
throws IOException
tag and const_value_index
in member_value.value - the constant value.IOExceptionpublic void constValueIndex(String value) throws IOException
tag and const_value_index
in member_value.value - the constant value.IOExceptionpublic void constValueIndex(int tag,
int index)
throws IOException
tag and const_value_index
in member_value.tag - tag in member_value.index - const_value_index
in member_value.IOExceptionpublic void enumConstValue(String typeName, String constName) throws IOException
tag and enum_const_value
in member_value.typeName - the type name of the enum constant.constName - the simple name of the enum constant.IOExceptionpublic void enumConstValue(int typeNameIndex,
int constNameIndex)
throws IOException
tag and enum_const_value
in member_value.typeNameIndex - type_name_index
in member_value.constNameIndex - const_name_index
in member_value.IOExceptionpublic void classInfoIndex(String name) throws IOException
tag and class_info_index
in member_value.name - the class name.IOExceptionpublic void classInfoIndex(int index)
throws IOException
tag and class_info_index
in member_value.index - class_info_indexIOExceptionpublic void annotationValue()
throws IOException
tag and annotation_value
in member_value.
This method must be followed by a call to annotation().IOExceptionpublic void arrayValue(int numValues)
throws IOException
tag and array_value
in member_value.
This method must be followed by numValues calls
to constValueIndex(), enumConstValue(),
etc.numValues - num_values
in array_value.IOExceptionCopyright © 2013. All rights reserved.