public abstract class BaseTypeChecker extends SourceChecker implements BaseTypeContext
SourceChecker
that provides a simple SourceVisitor
implementation that type-checks assignments,
pseudo-assignments such as parameter passing and method invocation, and method overriding.
Most type-checker annotation processor should extend this class, instead of SourceChecker
. Checkers that require annotated types but not subtype checking (e.g. for testing
purposes) should extend SourceChecker
. Non-type checkers (e.g. checkers to enforce coding
styles) can extend SourceChecker
or AbstractTypeProcessor
; the Checker Framework
is not designed for such checkers.
It is a convention that, for a type system Foo, the checker, the visitor, and the annotated type factory are named as FooChecker, FooVisitor, and FooAnnotatedTypeFactory. Some factory methods use this convention to construct the appropriate classes reflectively.
BaseTypeChecker
encapsulates a group for factories for various representations/classes
related the type system, mainly:
QualifierHierarchy
: to represent the supported qualifiers in addition to their
hierarchy, mainly, subtyping rules
TypeHierarchy
: to check subtyping rules between annotated types rather than
qualifiers
AnnotatedTypeFactory
: to construct qualified types enriched with implicit
qualifiers according to the type system rules
BaseTypeVisitor
: to visit the compiled Java files and check for violations of the
type system rules
Subclasses must specify the set of type qualifiers they support. See AnnotatedTypeFactory.createSupportedTypeQualifiers()
.
If the specified type qualifiers are meta-annotated with SubtypeOf
, this
implementation will automatically construct the type qualifier hierarchy. Otherwise, or if this
behavior must be overridden, the subclass may override the AnnotatedTypeFactory.createQualifierHierarchy()
method.
org.checkerframework.framework.qual
SourceChecker.CheckerError
currentRoot, DETAILS_SEPARATOR, errsOnLastExit, messager, messages, MSGS_FILE, parentChecker, SUPPRESS_ALL_KEY, trees, upstreamCheckerNames, visitor
processingEnv
Constructor and Description |
---|
BaseTypeChecker() |
Modifier and Type | Method and Description |
---|---|
protected BaseTypeVisitor<?> |
createSourceVisitor()
Returns the appropriate visitor that type-checks the compilation unit according to the type
system rules.
|
AnnotationProvider |
getAnnotationProvider() |
BaseTypeChecker |
getChecker() |
BaseTypeContext |
getContext() |
protected LinkedHashSet<Class<? extends BaseTypeChecker>> |
getImmediateSubcheckerClasses()
Returns the set of subchecker classes this checker depends on.
|
Map<String,String> |
getOptions()
Return all active options for this checker.
|
<T extends BaseTypeChecker> |
getSubchecker(Class<T> checkerClass)
Returns the requested subchecker.
|
Set<String> |
getSupportedLintOptions()
Specify supported lint options for all type-checkers.
|
Set<String> |
getSupportedOptions()
Map the Checker Framework version of
SupportedOptions to the standard annotation
provided version SupportedOptions . |
GenericAnnotatedTypeFactory<?,?,?,?> |
getTypeFactory() |
<T extends GenericAnnotatedTypeFactory<?,?,?,?>,U extends BaseTypeChecker> |
getTypeFactoryOfSubchecker(Class<U> checkerClass)
Returns the type factory used by a subchecker.
|
BaseTypeVisitor<?> |
getVisitor() |
void |
initChecker()
Initialize the checker.
|
static <T> T |
invokeConstructorFor(String name,
Class<?>[] paramTypes,
Object[] args)
Invokes the constructor belonging to the class named by
name having the given
parameter types on the given arguments. |
protected Object |
processArg(Object arg)
Process an argument to an error message before it is passed to String.format.
|
protected boolean |
shouldAddShutdownHook()
Return true to indicate that method
SourceChecker.shutdownHook() should be added as a shutdownHook
of the JVM. |
boolean |
shouldResolveReflection()
Returns whether or not reflection should be resolved
|
protected void |
shutdownHook()
Method that gets called exactly once at shutdown time of the JVM.
|
void |
typeProcess(TypeElement element,
TreePath tree)
Type-check the code with Java specifications and then runs the Checker Rule Checking visitor
on the processed source.
|
void |
typeProcessingOver()
A method to be called once all the classes are processed and no error is reported.
|
addOptions, createSupportedLintOptions, errorAbort, errorAbort, expandCFOptions, formatStackTrace, fullMessageOf, getElementUtils, getLintOption, getLintOption, getMessages, getOption, getOption, getOptionConfiguration, getProcessingEnvironment, getProperties, getStandardSuppressWarningsKeys, getSupportedAnnotationTypes, getSupportedSourceVersion, getSuppressWarningsKeys, getTreeUtils, getTypeUtils, getUpstreamCheckerNames, hasOption, init, message, message, printStats, report, setLintOption, setParentChecker, setProcessingEnvironment, setSupportedLintOptions, shouldSkipDefs, shouldSkipDefs, shouldSkipUses, shouldSkipUses, shouldSuppressWarnings, shouldSuppressWarnings, treeToFilePositionString, typeProcessingStart, userErrorAbort, useUncheckedCodeDefault
process
getCompletions, isInitialized
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getElementUtils, getOptionConfiguration, getProcessingEnvironment, getTreeUtils, getTypeUtils
public void initChecker()
SourceChecker
initChecker
in class SourceChecker
AbstractProcessor.init(ProcessingEnvironment)
protected LinkedHashSet<Class<? extends BaseTypeChecker>> getImmediateSubcheckerClasses()
Each subclass of BaseTypeChecker must declare all dependencies it relies on if there are any. Each subchecker of this checker is in turn free to change its own dependencies. It's OK for various checkers to declare a dependency on the same subchecker, since the BaseTypeChecker will ensure that each subchecker is instantiated only once.
WARNING: Circular dependencies are not supported. We do not check for their absence. Make sure no circular dependencies are created when overriding this method.
This method is protected so it can be overridden, but it is only intended to be called internally by the BaseTypeChecker. Please override this method but do not call it from classes other than BaseTypeChecker. Subclasses that override this method should call super and added dependencies so that checkers required for reflection resolution are included if reflection resolution is requested.
The BaseTypeChecker will not modify the list returned by this method.
public boolean shouldResolveReflection()
protected BaseTypeVisitor<?> createSourceVisitor()
This implementation uses the checker naming convention to create the appropriate visitor.
If no visitor is found, it returns an instance of BaseTypeVisitor
. It reflectively
invokes the constructor that accepts this checker and the compilation unit tree (in that
order) as arguments.
Subclasses have to override this method to create the appropriate visitor if they do not follow the checker naming convention.
createSourceVisitor
in class SourceChecker
public Set<String> getSupportedLintOptions()
getSupportedLintOptions
in class SourceChecker
Set
of the lint options recognized by this checkerpublic static <T> T invokeConstructorFor(String name, Class<?>[] paramTypes, Object[] args)
name
having the given
parameter types on the given arguments. Returns null
if the class cannot be found, or
the constructor does not exist or cannot be invoked on the given arguments.T
- the type to which the constructor belongsname
- the name of the class to which the constructor belongsparamTypes
- the types of the constructor's parametersargs
- the arguments on which to invoke the constructorargs
, or null if the constructor
does not exist or could not be invokedpublic BaseTypeContext getContext()
getContext
in class SourceChecker
CFContext
used by this checkerpublic BaseTypeChecker getChecker()
getChecker
in interface BaseTypeContext
getChecker
in interface CFContext
getChecker
in class SourceChecker
public BaseTypeVisitor<?> getVisitor()
getVisitor
in interface BaseTypeContext
getVisitor
in interface CFContext
getVisitor
in class SourceChecker
public GenericAnnotatedTypeFactory<?,?,?,?> getTypeFactory()
getTypeFactory
in interface BaseTypeContext
public AnnotationProvider getAnnotationProvider()
getAnnotationProvider
in interface BaseContext
getAnnotationProvider
in class SourceChecker
public <T extends BaseTypeChecker> T getSubchecker(Class<T> checkerClass)
checkerClass
- the class of the subcheckerpublic <T extends GenericAnnotatedTypeFactory<?,?,?,?>,U extends BaseTypeChecker> T getTypeFactoryOfSubchecker(Class<U> checkerClass)
checkerClass
- the class of the subcheckerpublic void typeProcess(TypeElement element, TreePath tree)
SourceChecker
typeProcess
in class SourceChecker
element
- element of the analyzed classtree
- the tree path to the element, with the leaf being a ClassTree
Processor.process(Set, RoundEnvironment)
public void typeProcessingOver()
AbstractTypeProcessor
Subclasses may override this method to do any aggregate analysis (e.g. generate report, persistence) or resource deallocation.
If an error (a Java error or a processor error) is reported, this method is not guaranteed to be invoked.
typeProcessingOver
in class AbstractTypeProcessor
public Set<String> getSupportedOptions()
SourceChecker
SupportedOptions
to the standard annotation
provided version SupportedOptions
.getSupportedOptions
in interface Processor
getSupportedOptions
in interface OptionConfiguration
getSupportedOptions
in class SourceChecker
public Map<String,String> getOptions()
SourceChecker
getOptions
in interface OptionConfiguration
getOptions
in class SourceChecker
protected Object processArg(Object arg)
SourceChecker
processArg
in class SourceChecker
arg
- the argumentprotected boolean shouldAddShutdownHook()
SourceChecker
SourceChecker.shutdownHook()
should be added as a shutdownHook
of the JVM.shouldAddShutdownHook
in class SourceChecker
protected void shutdownHook()
SourceChecker
shutdownHook
in class SourceChecker