Class AnnotationDef
java.lang.Object
org.checkerframework.afu.scenelib.el.AElement
org.checkerframework.afu.scenelib.el.AnnotationDef
- All Implemented Interfaces:
Cloneable
An annotation type definition, consisting of the annotation name, its meta-annotations, and its
field names and types.
AnnotationDef
s are immutable. An AnnotationDef with a non-null
retention policy is called a "top-level annotation definition".-
Field Summary
FieldsModifier and TypeFieldDescriptionA map of the names of this annotation type's fields to their types.final @BinaryName String
The binary name of the annotation type, such as "foo.Bar$Baz" for inner class Baz in class Bar in package foo.Where the annotation definition came from, such as a file name.Fields inherited from class org.checkerframework.afu.scenelib.el.AElement
description, tlAnnotationsHere, type
-
Constructor Summary
ConstructorsConstructorDescriptionAnnotationDef
(@BinaryName String name, String source) Constructs an annotation definition with the given name.AnnotationDef
(@BinaryName String name, Set<Annotation> tlAnnotationsHere, String source) Constructs an empty (so far) annotation definition.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. -
Method Summary
Modifier and TypeMethodDescriptionclone()
boolean
ThisAnnotationDef
equalso
if and only ifo
is another nonnullAnnotationDef
andthis
ando
define annotation types of the same name with the same field names and types.boolean
Returns true if thisAnnotationDef
equalso
; a slightly faster variant ofequals(Object)
for when the argument is statically known to be another nonnullAnnotationDef
.static AnnotationDef
fromClass
(Class<? extends Annotation> annoType, Map<String, AnnotationDef> adefs) Returns an AnnotationDef for the given annotation type.getDeclaredMethods
(String name) Returns a list of method names for a class in the order in which they occur in the .class file.int
hashCode()
boolean
True if this is a type annotation but not a declaration annotation.boolean
True if this is valid in type annotation locations.static void
Prints the classpath.The retention policy for annotations of this type.void
setFieldTypes
(Map<String, ? extends AnnotationFieldType> fieldTypes) Sets the field types of this annotation.target()
Returns the java.lang.annotation.Target meta-annotation, or null if there is none.targets()
Returns the contents of the java.lang.annotation.Target meta-annotation, or null if there is none.toString()
The printed representation is: "[meta-annos...] @name(args...)".Returns a string representation of this object, useful for debugging.static AnnotationDef
unify
(AnnotationDef def1, AnnotationDef def2) Returns anAnnotationDef
containing all the information from both arguments, ornull
if the two arguments contradict each other.
-
Field Details
-
name
The binary name of the annotation type, such as "foo.Bar$Baz" for inner class Baz in class Bar in package foo. -
fieldTypes
A map of the names of this annotation type's fields to their types. SinceAnnotationDef
s are immutable, clients should not modify this map, and doing so will result in an exception. -
source
Where the annotation definition came from, such as a file name.
-
-
Constructor Details
-
AnnotationDef
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 typesource
- where the annotation came from, such as a filename
-
AnnotationDef
Constructs an empty (so far) annotation definition.- Parameters:
name
- the binary name of the annotationtlAnnotationsHere
- the meta-annotations that are directly on the annotation definitionsource
- 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. UsessetFieldTypes(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 annotationtlAnnotationsHere
- the meta-annotations that are directly on the annotation definitionfieldTypes
- the annotation's element typessource
- where the annotation came from, such as a filename
-
-
Method Details
-
getDeclaredMethods
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 AnnotationDefadefs
- a cache of known AnnotationDef objects- Returns:
- an AnnotationDef for the given annotation type
-
clone
-
setFieldTypes
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
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
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
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
ThisAnnotationDef
equalso
if and only ifo
is another nonnullAnnotationDef
andthis
ando
define annotation types of the same name with the same field names and types. -
equals
Returns true if thisAnnotationDef
equalso
; a slightly faster variant ofequals(Object)
for when the argument is statically known to be another nonnullAnnotationDef
.- Parameters:
o
- another AnnotationDef to compare this to- Returns:
- true if this is equal to the given value
-
hashCode
public int hashCode() -
unify
Returns anAnnotationDef
containing all the information from both arguments, ornull
if the two arguments contradict each other. Currently this just unifies the field types to handle arrays of unknown element type, which can arise viaAnnotationBuilder.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 unifydef2
- the second AnnotationDef to unify- Returns:
- an AnnotationDef that contains all the fields of either argument
-
toString
The printed representation is: "[meta-annos...] @name(args...)". -
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.
-