Top Description Fields Constructors Methods
javassist.bytecode.annotation

public Class AnnotationsWriter

extends Object
Class Inheritance
Known Direct Subclasses
javassist.bytecode.annotation.TypeAnnotationsWriter
Imports
java.io.IOException, .OutputStream, javassist.bytecode.ByteArray, .ConstPool

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")
See Also
javassist.bytecode.AnnotationsAttribute, javassist.bytecode.ParameterAnnotationsAttribute

Field Summary

Modifier and TypeField and Description
protected OutputStream
private ConstPool

Constructor Summary

AccessConstructor and Description
public
AnnotationsWriter(OutputStream
the output stream.
os
,
ConstPool
the constant pool.
cp
)

Constructs with the given output stream.

Method Summary

Modifier and TypeMethod and Description
public void
annotation(String
the annotation interface name.
type
,
int
num_element_value_pairs in annotation.
numMemberValuePairs
)

Writes annotation.

public void
annotation(int
type_index in annotation.
typeIndex
,
int
num_element_value_pairs in annotation.
numMemberValuePairs
)

Writes annotation.

public void
annotationValue()

Writes tag and annotation_value in element_value.

public void
arrayValue(int
num_values in array_value.
numValues
)

Writes tag and array_value in element_value.

public void
classInfoIndex(String
the class name.
name
)

Writes tag and class_info_index in element_value.

public void
classInfoIndex(int
class_info_index
index
)

Writes tag and class_info_index in element_value.

public void
close()

Closes the output stream.

public void
constValueIndex(boolean
the constant value.
value
)

Writes tag and const_value_index in element_value.

public void
constValueIndex(byte
the constant value.
value
)

Writes tag and const_value_index in element_value.

public void
constValueIndex(char
the constant value.
value
)

Writes tag and const_value_index in element_value.

public void
constValueIndex(short
the constant value.
value
)

Writes tag and const_value_index in element_value.

public void
constValueIndex(int
the constant value.
value
)

Writes tag and const_value_index in element_value.

public void
constValueIndex(long
the constant value.
value
)

Writes tag and const_value_index in element_value.

public void
constValueIndex(float
the constant value.
value
)

Writes tag and const_value_index in element_value.

public void
constValueIndex(double
the constant value.
value
)

Writes tag and const_value_index in element_value.

public void
constValueIndex(String
the constant value.
value
)

Writes tag and const_value_index in element_value.

public void
constValueIndex(int
tag in element_value.
tag
,
int
const_value_index in element_value.
index
)

Writes tag and const_value_index in element_value.

public void
enumConstValue(String
the type name of the enum constant.
typeName
,
String
the simple name of the enum constant.
constName
)

Writes tag and enum_const_value in element_value.

public void
enumConstValue(int
type_name_index in element_value.
typeNameIndex
,
int
const_name_index in element_value.
constNameIndex
)

Writes tag and enum_const_value in element_value.

public ConstPool
getConstPool()

Obtains the constant pool given to the constructor.

public void
memberValuePair(String
the element name.
memberName
)

Writes an element of a element_value_pairs array in annotation.

public void
memberValuePair(int
element_name_index in element_value_pairs array.
memberNameIndex
)

Writes an element of a element_value_pairs array in annotation.

public void
numAnnotations(int num)

Writes num_annotations in Runtime(In)VisibleAnnotations_attribute.

public void
numParameters(int num)

Writes num_parameters in Runtime(In)VisibleParameterAnnotations_attribute.

protected void
write16bit(int value)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

outputback to summary
protected OutputStream output
poolback to summary
private ConstPool pool

Constructor Detail

AnnotationsWriterback to summary
public AnnotationsWriter(OutputStream os, ConstPool cp)

Constructs with the given output stream.

Parameters
os:OutputStream

the output stream.

cp:ConstPool

the constant pool.

Method Detail

annotationback to summary
public void annotation(String type, int numMemberValuePairs) throws IOException

Writes annotation. This method must be followed by numMemberValuePairs calls to memberValuePair().

Parameters
type:String

the annotation interface name.

numMemberValuePairs:int

num_element_value_pairs in annotation.

annotationback to summary
public void annotation(int typeIndex, int numMemberValuePairs) throws IOException

Writes annotation. This method must be followed by numMemberValuePairs calls to memberValuePair().

Parameters
typeIndex:int

type_index in annotation.

numMemberValuePairs:int

num_element_value_pairs in annotation.

annotationValueback to summary
public void annotationValue() throws IOException

Writes tag and annotation_value in element_value. This method must be followed by a call to annotation().

arrayValueback to summary
public void arrayValue(int numValues) throws IOException

Writes tag and array_value in element_value. This method must be followed by numValues calls to constValueIndex(), enumConstValue(), etc.

Parameters
numValues:int

num_values in array_value.

classInfoIndexback to summary
public void classInfoIndex(String name) throws IOException

Writes tag and class_info_index in element_value.

Parameters
name:String

the class name.

classInfoIndexback to summary
public void classInfoIndex(int index) throws IOException

Writes tag and class_info_index in element_value.

Parameters
index:int

class_info_index

closeback to summary
public void close() throws IOException

Closes the output stream.

constValueIndexback to summary
public void constValueIndex(boolean value) throws IOException

Writes tag and const_value_index in element_value.

Parameters
value:boolean

the constant value.

constValueIndexback to summary
public void constValueIndex(byte value) throws IOException

Writes tag and const_value_index in element_value.

Parameters
value:byte

the constant value.

constValueIndexback to summary
public void constValueIndex(char value) throws IOException

Writes tag and const_value_index in element_value.

Parameters
value:char

the constant value.

constValueIndexback to summary
public void constValueIndex(short value) throws IOException

Writes tag and const_value_index in element_value.

Parameters
value:short

the constant value.

constValueIndexback to summary
public void constValueIndex(int value) throws IOException

Writes tag and const_value_index in element_value.

Parameters
value:int

the constant value.

constValueIndexback to summary
public void constValueIndex(long value) throws IOException

Writes tag and const_value_index in element_value.

Parameters
value:long

the constant value.

constValueIndexback to summary
public void constValueIndex(float value) throws IOException

Writes tag and const_value_index in element_value.

Parameters
value:float

the constant value.

constValueIndexback to summary
public void constValueIndex(double value) throws IOException

Writes tag and const_value_index in element_value.

Parameters
value:double

the constant value.

constValueIndexback to summary
public void constValueIndex(String value) throws IOException

Writes tag and const_value_index in element_value.

Parameters
value:String

the constant value.

constValueIndexback to summary
public void constValueIndex(int tag, int index) throws IOException

Writes tag and const_value_index in element_value.

Parameters
tag:int

tag in element_value.

index:int

const_value_index in element_value.

enumConstValueback to summary
public void enumConstValue(String typeName, String constName) throws IOException

Writes tag and enum_const_value in element_value.

Parameters
typeName:String

the type name of the enum constant.

constName:String

the simple name of the enum constant.

enumConstValueback to summary
public void enumConstValue(int typeNameIndex, int constNameIndex) throws IOException

Writes tag and enum_const_value in element_value.

Parameters
typeNameIndex:int

type_name_index in element_value.

constNameIndex:int

const_name_index in element_value.

getConstPoolback to summary
public ConstPool getConstPool()

Obtains the constant pool given to the constructor.

memberValuePairback to summary
public void memberValuePair(String memberName) throws IOException

Writes an element of a element_value_pairs array in annotation. This method must be followed by a call to constValueIndex(), enumConstValue(), etc.

Parameters
memberName:String

the element name.

memberValuePairback to summary
public void memberValuePair(int memberNameIndex) throws IOException

Writes an element of a element_value_pairs array in annotation. This method must be followed by a call to constValueIndex(), enumConstValue(), etc.

Parameters
memberNameIndex:int

element_name_index in element_value_pairs array.

numAnnotationsback to summary
public void numAnnotations(int num) throws IOException

Writes num_annotations in Runtime(In)VisibleAnnotations_attribute. This method must be followed by num calls to annotation().

numParametersback to summary
public void numParameters(int num) throws IOException

Writes num_parameters in Runtime(In)VisibleParameterAnnotations_attribute. This method must be followed by num calls to numAnnotations().

write16bitback to summary
protected void write16bit(int value) throws IOException