Class AnnotationBuilder

java.lang.Object
org.checkerframework.afu.scenelib.AnnotationBuilder

public class AnnotationBuilder extends Object
An 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 AnnotationBuilders as needed.

  • Method Details

    • typeName

      public @BinaryName String typeName()
      Returns the name of the annotation.
      Returns:
      the name of the annotation
    • fieldTypes

      public Map<String,AnnotationFieldType> fieldTypes()
    • addScalarField

      public 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 by finish(). See the rules for values on Annotation.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 set
      aft - the element's type, which is a scalar type
      x - the element's value
    • beginArrayField

      public ArrayBuilder beginArrayField(String fieldName, ArrayAFT aft)
      Begins supplying an array field of the given name and type. The elements of the array must be passed to the returned ArrayBuilder in order, and the ArrayBuilder must be finished before any other methods on this AnnotationBuilder are called. aft.elementType must be known (not 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 set
      aft - the element's type, which is an array type
    • addEmptyArrayField

      public void addEmptyArrayField(String fieldName)
      Supplies an zero-element array field whose element type is unknown. The field type of this array is represented by an ArrayAFT with elementType == 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

      public Annotation finish()
      Returns the completed annotation. This method may throw an exception if the AnnotationBuilder 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 this AnnotationBuilder.
      Returns:
      the completed annotation corresponding to this builder
    • toString

      public String toString()
      Overrides:
      toString in class Object