Class Annotation

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

public final class Annotation extends Object
A very simple annotation representation constructed with a map of field names to values. See the rules for values on getFieldValue(java.lang.String); furthermore, subannotations must be Annotations. Annotations are immutable.

Annotations can be constructed directly or through AnnotationFactory.saf. Either way works, but if you construct one directly, you must provide a matching AnnotationDef yourself.

  • Field Details

    • def

      public final AnnotationDef def
      The annotation definition.
    • fieldValues

      public final Map<String,Object> fieldValues
      An unmodifiable copy of the passed map of field values.
  • Constructor Details

    • Annotation

      public Annotation(AnnotationDef def, Map<String,? extends Object> fields)
      Constructs a Annotation with the given definition and field values. Make sure that the field values obey the rules given on getFieldValue(java.lang.String) and that subannotations are also Annotations; this constructor does not validate the values.
      Parameters:
      def - the definition for the constructed annotation
      fields - the fields for the constructed annotation
    • Annotation

      public Annotation(Annotation ja, Map<String,AnnotationDef> adefs)
      Construct an Annotation for the given java.lang.annotation.Annotation.
      Parameters:
      ja - the java.lang.annotation.Annotation to make an Annotation for
      adefs - a cache from which to look up (or insert into) AnnotationDefs
  • Method Details

    • checkRep

      public void checkRep()
      Check the representation, throw assertion failure if it is violated.
    • getFieldValue

      public Object getFieldValue(String fieldName)
      Returns the value of the field whose name is given.

      Everywhere in the annotation scene library, field values are to be represented as follows:

      Parameters:
      fieldName - the name of the field whose value to return
      Returns:
      the value of the field named fieldName
    • def

      public final AnnotationDef def()
      Returns the definition of the annotation type to which this annotation belongs.
      Returns:
      the definition of the annotation type to which this annotation belongs
    • equals

      public final boolean equals(Object o)
      This Annotation equals o if and only if o is a nonnull Annotation and this and o have recursively equal definitions and field values, even if they were created by different AnnotationFactorys.
      Overrides:
      equals in class Object
    • equals

      public boolean equals(Annotation o)
      Returns true if this annotation equals o; a slightly faster variant of equals(Object) for when the argument is statically known to be another nonnull Annotation. Subclasses may wish to override this with a hard-coded "&&" of field comparisons to improve performance.
      Parameters:
      o - the Annotation to compare to this
      Returns:
      true if this equals o
    • hashCode

      public int hashCode()
      Returns the hash code of this annotation as defined on hashCode(). Subclasses may wish to override this with a hard-coded XOR/addition of fields to improve performance.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a string representation of this annotation, using valid Java syntax.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this annotation, using valid Java syntax
    • toString

      public void toString(StringBuilder sb)
      Formats this annotation, using valid Java syntax.
      Parameters:
      sb - where to format the annotation to