Class AnnotationDef

java.lang.Object
org.checkerframework.afu.scenelib.el.AElement
org.checkerframework.afu.scenelib.el.AnnotationDef
All Implemented Interfaces:
Cloneable

public final class AnnotationDef extends AElement
An annotation type definition, consisting of the annotation name, its meta-annotations, and its field names and types. AnnotationDefs are immutable. An AnnotationDef with a non-null retention policy is called a "top-level annotation definition".
  • Field Details

    • name

      public final @BinaryName String name
      The binary name of the annotation type, such as "foo.Bar$Baz" for inner class Baz in class Bar in package foo.
    • fieldTypes

      public Map<String,AnnotationFieldType> fieldTypes
      A map of the names of this annotation type's fields to their types. Since AnnotationDefs are immutable, clients should not modify this map, and doing so will result in an exception.
    • source

      public String source
      Where the annotation definition came from, such as a file name.
  • Constructor Details

    • AnnotationDef

      public AnnotationDef(@BinaryName String name, String source)
      Constructs an annotation definition with the given name. You MUST call setFieldTypes afterward, even if with an empty map. (Yuck.)
      Parameters:
      name - the binary name of the annotation type
      source - where the annotation came from, such as a filename
    • AnnotationDef

      public AnnotationDef(@BinaryName String name, Set<Annotation> tlAnnotationsHere, String source)
      Constructs an empty (so far) annotation definition.
      Parameters:
      name - the binary name of the annotation
      tlAnnotationsHere - the meta-annotations that are directly on the annotation definition
      source - where the annotation came from, such as a filename
    • AnnotationDef

      public AnnotationDef(@BinaryName String name, Set<Annotation> tlAnnotationsHere, Map<String,? extends AnnotationFieldType> fieldTypes, String source)
      Constructs an annotation definition with the given name and field types. Uses setFieldTypes(java.util.Map<java.lang.String, ? extends org.checkerframework.afu.scenelib.field.AnnotationFieldType>) to protect the immutability of the annotation definition.
      Parameters:
      name - the binary name of the annotation
      tlAnnotationsHere - the meta-annotations that are directly on the annotation definition
      fieldTypes - the annotation's element types
      source - where the annotation came from, such as a filename
  • Method Details

    • getDeclaredMethods

      public static List<String> getDeclaredMethods(String name)
      Returns a list of method names for a class in the order in which they occur in the .class file. Note that the JDK method Class.getDeclaredMethods() does not preserve this order.
      Parameters:
      name - the ifully qualified name of the class to be read
      Returns:
      a list of methods for the class
    • fromClass

      public static AnnotationDef fromClass(Class<? extends Annotation> annoType, Map<String,AnnotationDef> adefs)
      Returns an AnnotationDef for the given annotation type. It might have been looked up in adefs, or created new and inserted in adefs.
      Parameters:
      annoType - the type for which to create an AnnotationDef
      adefs - a cache of known AnnotationDef objects
      Returns:
      an AnnotationDef for the given annotation type
    • clone

      public AnnotationDef clone()
      Overrides:
      clone in class AElement
    • setFieldTypes

      public void setFieldTypes(Map<String,? extends AnnotationFieldType> fieldTypes)
      Sets the field types of this annotation. The field type map is copied and then wrapped in an unmodifiable map to protect the immutability of the annotation definition.
      Parameters:
      fieldTypes - the annotation's element types
    • retention

      public @Nullable RetentionPolicy retention()
      The retention policy for annotations of this type. If non-null, this is called a "top-level" annotation definition. It may be null for annotations that are used only as a field of other annotations.
      Returns:
      the retention policy for annotations of this type
    • targets

      public List<String> targets()
      Returns the contents of the java.lang.annotation.Target meta-annotation, or null if there is none.
      Returns:
      the contents of the @Target meta-annotation, or null
    • target

      public Annotation target()
      Returns the java.lang.annotation.Target meta-annotation, or null if there is none.
      Returns:
      the @Target meta-annotation, or null
    • isTypeAnnotation

      public boolean isTypeAnnotation()
      True if this is valid in type annotation locations. It was meta-annotated with @Target({ElementType.TYPE_USE, ...}).

      Returns true if this is valid in type annotation locations and (possibly) declaration locations. To test whether this is valid only in type annotation locations and not in declaration locations, use isOnlyTypeAnnotation().

      Returns:
      true iff this is a type annotation
    • isOnlyTypeAnnotation

      public boolean isOnlyTypeAnnotation()
      True if this is a type annotation but not a declaration annotation. It was meta-annotated with @Target(ElementType.TYPE_USE) or @Target({ElementType.TYPE_USE, ElementType.TYPE}) or @Target({ElementType.TYPE, ElementType.TYPE_USE}).
      Returns:
      true iff this is valid only in type annotation locations
      See Also:
    • equals

      public boolean equals(Object o)
      This AnnotationDef equals o if and only if o is another nonnull AnnotationDef and this and o define annotation types of the same name with the same field names and types.
      Overrides:
      equals in class AElement
    • equals

      public boolean equals(AnnotationDef o)
      Returns true if this AnnotationDef equals o; a slightly faster variant of equals(Object) for when the argument is statically known to be another nonnull AnnotationDef.
      Parameters:
      o - another AnnotationDef to compare this to
      Returns:
      true if this is equal to the given value
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AElement
    • unify

      public static AnnotationDef unify(AnnotationDef def1, AnnotationDef def2)
      Returns an AnnotationDef containing all the information from both arguments, or null if the two arguments contradict each other. Currently this just unifies the field types to handle arrays of unknown element type, which can arise via AnnotationBuilder.addEmptyArrayField(java.lang.String).

      As a special case, if one annotation has no elements, the other one's elements are used.

      Parameters:
      def1 - the first AnnotationDef to unify
      def2 - the second AnnotationDef to unify
      Returns:
      an AnnotationDef that contains all the fields of either argument
    • toString

      public String toString()
      The printed representation is: "[meta-annos...] @name(args...)".
      Overrides:
      toString in class AElement
    • toStringDebug

      public String toStringDebug()
      Returns a string representation of this object, useful for debugging.
      Returns:
      a string representation of this object, useful for debugging
    • printClasspath

      public static void printClasspath()
      Prints the classpath.