checkers.util
Class AnnotationUtils

java.lang.Object
  extended by checkers.util.AnnotationUtils

@Default(value="checkers.nonnull.quals.NonNull")
public class AnnotationUtils
extends Object

A utility class for working with annotations.


Constructor Summary
AnnotationUtils(ProcessingEnvironment env)
           
 
Method Summary
static Name annotationName(AnnotationMirror annotation)
           
static Comparator<AnnotationMirror> annotationOrdering()
           
static
<V> Map<AnnotationMirror,V>
createAnnotationMap()
          Create a map suitable for storing AnnotationMirror as keys.
static Set<AnnotationMirror> createAnnotationSet()
          Constructs a Set suitable for storing AnnotationMirrors.
 Map<TypeElement,Set<DefaultLocation>> findDefaultLocations(Element elt)
          Finds default annotations starting at the given element, inspecting the element and its enclosing method and class declarations for Default annotations.
 Map<TypeElement,Set<DefaultLocation>> findDefaultLocations(TreePath path)
          Finds default annotations starting at the leaf of the given tree path by inspecting enclosing variable, method, and class declarations for Default annotations.
static Map<? extends ExecutableElement,? extends AnnotationValue> getElementValuesWithDefaults(AnnotationMirror ad)
          Returns the values of an annotation's elements, including defaults.
static boolean isSame(AnnotationMirror a1, AnnotationMirror a2)
          Checks if both annotations are the same
static
<R extends Enum<R>>
Set<R>
parseEnumConstantArrayValue(AnnotationMirror ad, String field, Class<R> enumType)
           
static Set<String> parseStringArrayValue(AnnotationMirror ad, String field)
           
static String parseStringValue(AnnotationMirror ad, String field)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationUtils

public AnnotationUtils(ProcessingEnvironment env)
Method Detail

findDefaultLocations

public Map<TypeElement,Set<DefaultLocation>> findDefaultLocations(TreePath path)
Finds default annotations starting at the leaf of the given tree path by inspecting enclosing variable, method, and class declarations for Default annotations.

Parameters:
path - the tree path from which to start searching
Returns:
a mapping from annotations (as TypeElements) to the DefaultLocations for those annotations
See Also:
findDefaultLocations(Element)

findDefaultLocations

public Map<TypeElement,Set<DefaultLocation>> findDefaultLocations(Element elt)
Finds default annotations starting at the given element, inspecting the element and its enclosing method and class declarations for Default annotations.

Parameters:
elt - the element from which to start searching
Returns:
a mapping from annotations (as TypeElements) to the DefaultLocations for those annotations
See Also:
findDefaultLocations(TreePath)

getElementValuesWithDefaults

public static Map<? extends ExecutableElement,? extends AnnotationValue> getElementValuesWithDefaults(AnnotationMirror ad)
Returns the values of an annotation's elements, including defaults.

Parameters:
ad - annotation to examine
Returns:
the values of the annotation's elements, including defaults
See Also:
AnnotationMirror.getElementValues()

parseEnumConstantArrayValue

public static <R extends Enum<R>> Set<R> parseEnumConstantArrayValue(AnnotationMirror ad,
                                                                     String field,
                                                                     Class<R> enumType)
Type Parameters:
R - the enum type
Parameters:
ad - the annotation for which a value will be parsed
field - the name of the field to parse
enumType - the type of the enum
Returns:
the enum constant values of the given field

parseStringValue

public static String parseStringValue(AnnotationMirror ad,
                                      String field)
Parameters:
ad - the annotation for which a value will be parsed
field - the name of the field to parse
Returns:
the String value of the given field

parseStringArrayValue

public static Set<String> parseStringArrayValue(AnnotationMirror ad,
                                                String field)
Parameters:
ad - the annotation for which a value will be parsed
field - the name of the field to parse
Returns:
the String values of the given field

annotationName

public static final Name annotationName(AnnotationMirror annotation)
Returns:
the fully-qualified name of an annotation as a String

isSame

public static boolean isSame(AnnotationMirror a1,
                             AnnotationMirror a2)
Checks if both annotations are the same

Returns:
true iff a1 and a2 are the same annotation

annotationOrdering

public static Comparator<AnnotationMirror> annotationOrdering()

createAnnotationMap

public static <V> Map<AnnotationMirror,V> createAnnotationMap()
Create a map suitable for storing AnnotationMirror as keys. It can store one instance of AnnotationMirror of a given declared type, regardless of the annotation element values.

Type Parameters:
V - the value of the map
Returns:
a new map with AnnotationMirror as key

createAnnotationSet

public static Set<AnnotationMirror> createAnnotationSet()
Constructs a Set suitable for storing AnnotationMirrors. It stores at most once instance of AnnotationMirror of a given type, regardless of the annotation element values.

Returns:
a new set to store AnnotationMirror as element