Class AnnotationBuilder
AnnotationBuilder
builds a single annotation object after the annotation's fields have
been supplied one by one.
It is not possible to specify the type name or the retention policy. Either the AnnotationBuilder
expects a certain definition (and may throw exceptions if the fields deviate
from it) or it determines the definition automatically from the supplied fields.
Each AnnotationBuilder
is mutable and single-use; the purpose of an AnnotationFactory
is to produce as many AnnotationBuilder
s as needed.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addEmptyArrayField
(String fieldName) Supplies an zero-element array field whose element type is unknown.void
addScalarField
(String fieldName, ScalarAFT aft, Object x) Supplies a scalar field of the given name, type, and value for inclusion in the annotation returned byfinish()
.beginArrayField
(String fieldName, ArrayAFT aft) Begins supplying an array field of the given name and type.finish()
Returns the completed annotation.toString()
typeName()
Returns the name of the annotation.
-
Method Details
-
typeName
Returns the name of the annotation.- Returns:
- the name of the annotation
-
fieldTypes
-
addScalarField
Supplies a scalar field of the given name, type, and value for inclusion in the annotation returned byfinish()
. See the rules for values onAnnotation.getFieldValue(java.lang.String)
.Each field may be supplied only once. This method may throw an exception if the
AnnotationBuilder
expects a certain definition for the built annotation and the given field does not exist in that definition or has the wrong type.- Parameters:
fieldName
- the name of the annotation element to setaft
- the element's type, which is a scalar typex
- the element's value
-
beginArrayField
Begins supplying an array field of the given name and type. The elements of the array must be passed to the returnedArrayBuilder
in order, and theArrayBuilder
must be finished before any other methods on thisAnnotationBuilder
are called.aft.
must be known (notelementType
null
).Each field may be supplied only once. This method may throw an exception if the
AnnotationBuilder
expects a certain definition for the built annotation and the given field does not exist in that definition or has the wrong type.- Parameters:
fieldName
- the name of the annotation element to setaft
- the element's type, which is an array type
-
addEmptyArrayField
Supplies an zero-element array field whose element type is unknown. The field type of this array is represented by anArrayAFT
withelementType
==null
.This can sometimes happen due to a design flaw in the format of annotations in class files. An array value does not specify an type itself; instead, each element carries a type. Thus, a zero-length array carries no indication of its element type.
- Parameters:
fieldName
- the name of the annotation element to set to an empty array
-
finish
Returns the completed annotation. This method may throw an exception if theAnnotationBuilder
expects a certain definition for the built annotation and one or more fields in that definition were not supplied. Once this method has been called, no more method calls may be made on thisAnnotationBuilder
.- Returns:
- the completed annotation corresponding to this builder
-
toString
-