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.
AnnotationDefs are immutable. An AnnotationDef with a non-null
retention policy is called a "top-level annotation definition".-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Map<String, ? extends AnnotationFieldType> A map of the names of this annotation type's fields to their types.final @BinaryName StringThe binary name of the annotation type, such as "foo.Bar$Baz" for inner class Baz in class Bar in package foo.Fields inherited from class org.checkerframework.afu.scenelib.el.AElement
description, tlAnnotationsHere, type -
Constructor Summary
ConstructorsConstructorDescriptionAnnotationDef(@BinaryName String name, Map<String, ? extends AnnotationFieldType> fieldTypes, String source) Constructs an annotation definition.AnnotationDef(@BinaryName String name, Map<String, ? extends AnnotationFieldType> fieldTypes, Supplier<String> sourceSupplier) Constructs an annotation definition.AnnotationDef(@BinaryName String name, Set<Annotation> tlAnnotationsHere, Map<String, ? extends AnnotationFieldType> fieldTypes, String source) Constructs an annotation definition.AnnotationDef(@BinaryName String name, Set<Annotation> tlAnnotationsHere, Map<String, ? extends AnnotationFieldType> fieldTypes, Supplier<String> sourceSupplier) Constructs an annotation definition. -
Method Summary
Modifier and TypeMethodDescriptionclone()booleanThisAnnotationDefequalsoif and only ifois another nonnullAnnotationDefandthisandodefine annotation types of the same name with the same field names and types.booleanReturns true if thisAnnotationDefequalso; a slightly faster variant ofequals(Object)for when the argument is statically known to be another nonnullAnnotationDef.static AnnotationDeffromClass(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.Returns where the annotation definition came from, such as a file name; used for diagnostics.inthashCode()static <K,V> Map <K, V> immutableMap(Map<K, V> map) Returns an immutable copy of the map.booleanTrue if this is a type annotation but not a declaration annotation.booleanTrue if this is valid in type annotation locations.static booleanisUnmodifiable(Map<?, ?> map) Returns true if the map is unmodifiable.static voidPrints the classpath.The retention policy for annotations of this type.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 AnnotationDefunify(AnnotationDef def1, AnnotationDef def2) Returns anAnnotationDefcontaining all the information from both arguments, ornullif 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. SinceAnnotationDefs are immutable, clients should not modify this map, and doing so will result in an exception.
-
-
Constructor Details
-
AnnotationDef
public AnnotationDef(@BinaryName String name, Map<String, ? extends AnnotationFieldType> fieldTypes, String source) Constructs an annotation definition.- Parameters:
name- the binary name of the annotation typefieldTypes- map from the names of this annotation type's fields to their typessource- where the annotation came from, such as a filename; used for diagnostics
-
AnnotationDef
public AnnotationDef(@BinaryName String name, Map<String, ? extends AnnotationFieldType> fieldTypes, Supplier<String> sourceSupplier) Constructs an annotation definition.- Parameters:
name- the binary name of the annotation typefieldTypes- map from the names of this annotation type's fields to their typessourceSupplier- computes where the annotation came from, such as a filename; it is called only if the source is needed for a diagnostic
-
AnnotationDef
public AnnotationDef(@BinaryName String name, Set<Annotation> tlAnnotationsHere, Map<String, ? extends AnnotationFieldType> fieldTypes, String source) Constructs an 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; if it is expensive to compute, useAnnotationDef(String,Set,Map,Supplier)instead
-
AnnotationDef
public AnnotationDef(@BinaryName String name, Set<Annotation> tlAnnotationsHere, Map<String, ? extends AnnotationFieldType> fieldTypes, Supplier<String> sourceSupplier) Constructs an annotation definition.- Parameters:
name- the binary name of the annotationtlAnnotationsHere- the meta-annotations that are directly on the annotation definitionfieldTypes- the annotation's element typessourceSupplier- computes where the annotation came from, such as a filename; it is called only if the source is needed for a diagnostic
-
-
Method Details
-
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
-
getSource
Returns where the annotation definition came from, such as a file name; used for diagnostics.- Returns:
- where the annotation definition came from, such as a file name
-
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 fully qualified name of the class to be read- Returns:
- a list of methods for the class, or an empty list if the class file cannot be read
-
clone
-
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
ThisAnnotationDefequalsoif and only ifois another nonnullAnnotationDefandthisandodefine annotation types of the same name with the same field names and types. -
equals
Returns true if thisAnnotationDefequalso; 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 anAnnotationDefcontaining all the information from both arguments, ornullif 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. -
immutableMap
Returns an immutable copy of the map. The result cannot be modified, directly or through an alias.WARNING: If the map is already unmodifiable, then it is returned unchanged. That means that a client that passes an unmodifiable (but not immutable) map can violate this method's contract.
- Type Parameters:
K- the type of map keysV- the type of map values- Parameters:
map- a map. If it is unmodifiable, it is immutable. That is, the client may not pass an unmodifiable map that can be modified through an alias.- Returns:
- an immutable copy of the map
-
isUnmodifiable
Returns true if the map is unmodifiable. May return false for a map that is unmodifiable but whose implementation this method does not recognize.- Parameters:
map- a map- Returns:
- true if the map is unmodifiable
-