public class AnnotationClassLoader extends Object
AnnotatedTypeFactory
by reflectively looking
up the list of annotation class names in each checker's qual directory, and
then loading and returning it as a set of annotation classes. It can also
look up and load annotation classes from external directories that are passed
as arguments to checkers that have extension capabilities such as the
Subtyping Checker, Fenum Checker, and Units Checker.
To load annotations using this class, their directory structure and package
structure must be identical.
Only annotation classes that have the Target
meta-annotation with the
value of ElementType.TYPE_USE
(and optionally
ElementType.TYPE_PARAMETER
) are loaded. If it has other
ElementType
values, it won't be loaded. Other annotation classes must
be manually listed in a checker's annotated type factory by overriding
AnnotatedTypeFactory.createSupportedTypeQualifiers()
.
Checker writers may wish to subclass this class if they wish to implement
some custom rules to filter or process loaded annotation classes, by
providing an override implementation of
isSupportedAnnotationClass(Class)
. See
UnitsAnnotationClassLoader
for an example.Modifier and Type | Field and Description |
---|---|
protected ProcessingEnvironment |
processingEnv
Processing Env used to create an
AnnotationBuilder , which is in
turn used to build the annotation mirror from the loaded class. |
Constructor and Description |
---|
AnnotationClassLoader(BaseTypeChecker checker)
Constructor for loading annotations defined for a checker.
|
Modifier and Type | Method and Description |
---|---|
Set<Class<? extends Annotation>> |
getLoadedAnnotationClasses()
Gets the set of the loaded annotation classes.
|
protected boolean |
isSupportedAnnotationClass(Class<? extends Annotation> annoClass)
Checks to see whether a particular annotation class is supported.
|
@Nullable Class<? extends Annotation> |
loadExternalAnnotationClass(String annoName)
This method takes as input the canonical name of an external annotation
class and loads and returns that class via the class loader.
|
Set<Class<? extends Annotation>> |
loadExternalAnnotationClassesFromDirectory(String dirName)
This method takes as input a fully qualified path to a directory, and
loads and returns the set of all annotation classes from that directory.
|
protected final ProcessingEnvironment processingEnv
AnnotationBuilder
, which is in
turn used to build the annotation mirror from the loaded class.public AnnotationClassLoader(BaseTypeChecker checker)
checker
- a BaseTypeChecker
or its subclasspublic final Set<Class<? extends Annotation>> getLoadedAnnotationClasses()
createSupportedTypeQualifiers()
(or its helper methods) to help define
the set of supported qualifiers.
createSupportedTypeQualifiers()
must return an immutable set, and it is
the responsibility of that method (or helper methods it calls) to convert
the set returned by this method, along with any additional annotation
classes, into an immutable set.public final @Nullable Class<? extends Annotation> loadExternalAnnotationClass(String annoName)
annoName
- canonical name of an external annotation class, e.g.
"myproject.qual.myannotation"public final Set<Class<? extends Annotation>> loadExternalAnnotationClassesFromDirectory(String dirName)
dirName
- absolute path to a directory containing annotation classesprotected boolean isSupportedAnnotationClass(Class<? extends Annotation> annoClass)
annoClass
- an annotation class