Class BaseTypeChecker
- All Implemented Interfaces:
Processor
,OptionConfiguration
- Direct Known Subclasses:
AccumulationChecker
,AliasingChecker
,ClassValChecker
,FenumChecker
,FormatterChecker
,GuiEffectChecker
,I18nFormatterChecker
,I18nSubchecker
,InitializationChecker
,InterningChecker
,KeyForSubchecker
,LessThanChecker
,LockChecker
,LowerBoundChecker
,MethodValChecker
,MustCallChecker
,NonEmptyChecker
,OptionalChecker
,PropertyKeyChecker
,PurityChecker
,RegexChecker
,ReportChecker
,ReturnsReceiverChecker
,SameLenChecker
,SearchIndexChecker
,SignatureChecker
,SignednessChecker
,SqlQuotesChecker
,SubstringIndexChecker
,SubtypingChecker
,TaintingChecker
,TypeOutputtingChecker
,UnitsChecker
,UpperBoundChecker
,ValueChecker
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 processors 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 specifically designed to support 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 rulesTypeHierarchy
: to check subtyping rules between annotated types rather than qualifiersAnnotatedTypeFactory
: to construct qualified types enriched with default qualifiers according to the type system rulesBaseTypeVisitor
: 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.
- See the Checker Framework Manual:
- The checker class
-
Nested Class Summary
Nested classes/interfaces inherited from class org.checkerframework.framework.source.SourceChecker
SourceChecker.CheckerMessage
-
Field Summary
Modifier and TypeFieldDescriptionprotected static Class<?>[]
An array containing justBaseTypeChecker.class
.protected @MonotonicNonNull BaseTypeChecker
A cache forgetUltimateParentChecker()
.Fields inherited from class org.checkerframework.framework.source.SourceChecker
activeOptions, currentRoot, DETAILS_SEPARATOR, elements, elementsWithSuppressedWarnings, immediateSubcheckers, javacErrored, messager, messagesProperties, messageStore, MSGS_FILE, OPTION_SEPARATOR, parentChecker, subcheckers, supportedOptions, SUPPRESS_ALL_MESSAGE_KEY, SUPPRESS_ALL_PREFIX, suppressWarningsPrefixesOfSubcheckers, treePathCacher, trees, types, UNNEEDED_SUPPRESSION_KEY, upstreamCheckerNames, useAllcheckersPrefix, visitor
Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected BaseTypeVisitor<?>
Returns the appropriate visitor that type-checks the compilation unit according to the type system rules.A public variant ofcreateSourceVisitor()
.Compute the set of supported lint options for this checker and its subcheckers.Returns the AnnotationProvider (the type factory) associated with this.GenericAnnotatedTypeFactory<?,
?, ?, ?> Return the type factory associated with this checker.<T extends GenericAnnotatedTypeFactory<?,
?, ?, ?>>
@Nullable TgetTypeFactoryOfSubcheckerOrNull
(Class<? extends BaseTypeChecker> subCheckerClass) Returns the type factory used by a subchecker.Finds the ultimate parent checker of this checker.Returns the SourceVisitor associated with this.static <T> @Nullable T
invokeConstructorFor
(@ClassGetName String className, Class<?>[] paramTypes, Object[] args) Invokes the constructor belonging to the class named byname
having the given parameter types on the given arguments.protected Object
Process an argument to an error message before it is passed to String.format.protected boolean
Return true to indicate that methodSourceChecker.shutdownHook()
should be added as a shutdownHook of the JVM.protected void
Method that gets called exactly once at shutdown time of the JVM.Methods inherited from class org.checkerframework.framework.source.SourceChecker
expandCFOptions, fullMessageOf, getBooleanOption, getBooleanOption, getElementUtils, getExtraStubFiles, getImmediateSubcheckerClasses, getLintOption, getLintOption, getMessagesProperties, getOption, getOption, getOptionConfiguration, getOptions, getOptionsNoSubcheckers, getParentChecker, getPathToCompilationUnit, getProcessingEnvironment, getProperties, getRelatedClassName, getStandardSuppressWarningsPrefixes, getStringsOption, getStringsOption, getSubchecker, getSubCheckerIndex, getSubcheckers, getSupportedAnnotationTypes, getSupportedLintOptions, getSupportedOptions, getSupportedSourceVersion, getSuppressWarningsPrefixes, getSuppressWarningsPrefixesOfSubcheckers, getTreePathCacher, getTreeUtils, getTypeUtils, getUpstreamCheckerNames, hasOption, hasOptionNoSubcheckers, init, initChecker, instantiateSubcheckers, message, message, messageKeyMatches, printOrStoreMessage, printOrStoreMessage, printStats, printStoredMessages, report, reportError, reportWarning, setLintOption, setParentChecker, setRoot, shouldResolveReflection, shouldSkipDefs, shouldSkipDefs, shouldSkipDefs, shouldSkipFiles, shouldSkipUses, shouldSkipUses, shouldSuppressWarnings, shouldSuppressWarnings, shouldSuppressWarnings, typeProcess, typeProcessingOver, typeProcessingStart, useConservativeDefault, warnUnneededSuppressions, warnUnneededSuppressions
Methods inherited from class org.checkerframework.javacutil.AbstractTypeProcessor
getCompilerLog, process
Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, isInitialized
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.checkerframework.framework.util.OptionConfiguration
getStringsOption, getStringsOption
-
Field Details
-
baseTypeCheckerClassArray
An array containing justBaseTypeChecker.class
. -
ultimateParentChecker
A cache forgetUltimateParentChecker()
.
-
-
Constructor Details
-
BaseTypeChecker
protected BaseTypeChecker()Create a new BaseTypeChecker.
-
-
Method Details
-
createSourceVisitor
Returns the appropriate visitor that type-checks the compilation unit according to the type system rules.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.
- Specified by:
createSourceVisitor
in classSourceChecker
- Returns:
- the type-checking visitor
-
createSourceVisitorPublic
A public variant ofcreateSourceVisitor()
. Only use this if you know what you are doing.- Returns:
- the type-checking visitor
-
getVisitor
Description copied from class:SourceChecker
Returns the SourceVisitor associated with this.- Overrides:
getVisitor
in classSourceChecker
- Returns:
- the SourceVisitor associated with this
-
getTypeFactory
Return the type factory associated with this checker.- Returns:
- the type factory associated with this checker
-
getAnnotationProvider
Description copied from class:SourceChecker
Returns the AnnotationProvider (the type factory) associated with this.- Overrides:
getAnnotationProvider
in classSourceChecker
- Returns:
- the AnnotationProvider (the type factory) associated with this
-
getTypeFactoryOfSubcheckerOrNull
public <T extends GenericAnnotatedTypeFactory<?,?, @Nullable T getTypeFactoryOfSubcheckerOrNull?, ?>> (Class<? extends BaseTypeChecker> subCheckerClass) Returns the type factory used by a subchecker. Returns null if no matching subchecker was found or if the type factory is null. The caller must know the exact checker class to request.Because the visitor state is copied, call this method each time a subfactory is needed rather than store the returned subfactory in a field.
- Type Parameters:
T
- the type ofsubCheckerClass
'sAnnotatedTypeFactory
- Parameters:
subCheckerClass
- the class of the subchecker- Returns:
- the type factory of the requested subchecker or null if not found
-
processErrorMessageArg
Description copied from class:SourceChecker
Process an argument to an error message before it is passed to String.format.This implementation expands the argument if it is exactly a message key.
By contrast,
SourceChecker.fullMessageOf(java.lang.String, java.lang.String)
processes the message key itself but not the arguments, and tries suffixes.- Overrides:
processErrorMessageArg
in classSourceChecker
- Parameters:
arg
- the argument- Returns:
- the result after processing
-
shouldAddShutdownHook
protected boolean shouldAddShutdownHook()Description copied from class:SourceChecker
Return true to indicate that methodSourceChecker.shutdownHook()
should be added as a shutdownHook of the JVM.- Overrides:
shouldAddShutdownHook
in classSourceChecker
- Returns:
- true to add
SourceChecker.shutdownHook()
as a shutdown hook of the JVM
-
shutdownHook
protected void shutdownHook()Description copied from class:SourceChecker
Method that gets called exactly once at shutdown time of the JVM. Checkers can override this method to customize the behavior.If you override this, you must also override
SourceChecker.shouldAddShutdownHook()
to return true.- Overrides:
shutdownHook
in classSourceChecker
-
createSupportedLintOptions
Description copied from class:SourceChecker
Compute the set of supported lint options for this checker and its subcheckers.- Overrides:
createSupportedLintOptions
in classSourceChecker
- Returns:
- the set of supported lint options for this checker and its subcheckers
-
getUltimateParentChecker
Finds the ultimate parent checker of this checker. The ultimate parent checker is the checker that the user actually requested, i.e. the one with no parent. The ultimate parent might be this checker itself.- Returns:
- the first checker in the parent checker chain with no parent checker of its own, i.e., the ultimate parent checker
-
invokeConstructorFor
public static <T> @Nullable T invokeConstructorFor(@ClassGetName String className, Class<?>[] paramTypes, Object[] args) Invokes the constructor belonging to the class named byname
having the given parameter types on the given arguments. Returnsnull
if the class cannot be found. Otherwise, throws an exception if there is trouble with the constructor invocation.- Type Parameters:
T
- the type to which the constructor belongs- Parameters:
className
- the name of the class to which the constructor belongsparamTypes
- the types of the constructor's parametersargs
- the arguments on which to invoke the constructor- Returns:
- the result of the constructor invocation on
args
, or null if the class does not exist
-