Class SourceChecker
- All Implemented Interfaces:
- Processor,- OptionConfiguration
- Direct Known Subclasses:
- AggregateChecker,- AnnotationStatistics,- BaseTypeChecker,- JavaCodeStatistics
javac's annotation processing
 API, routines for error reporting via the JSR 199 compiler API, and an implementation for using a
 SourceVisitor to perform the type-checking.
 Most type-checker plug-ins should extend BaseTypeChecker, instead of this class. Only
 checkers that require annotated types but not subtype checking (e.g. for testing purposes) should
 extend this. Non-type checkers (e.g. for enforcing coding styles) may extend AbstractProcessor (or even this class).
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classRepresents a message (e.g., an error message) issued by a checker.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected @MonotonicNonNull Map<String,String> The active options for this checker.The source tree that is being scanned.static final StringSeparates parts of a "detailed message", to permit easier parsing.protected ElementsElement utilities.Elements with a@SuppressWarningsthat actually suppressed a warning for this checker.protected @MonotonicNonNull List<SourceChecker>The list of subcheckers that are direct dependencies of this checker.protected booleanIf true, javac failed to compile the code or a previously-run annotation processor issued an error.protected MessagerUsed to report error messages and warnings via the compiler.protected PropertiesMaps error keys to localized/custom error messages.protected @MonotonicNonNull TreeSet<SourceChecker.CheckerMessage>Stores all messages issued by this checker and its subcheckers for the current compilation unit.protected static final StringFile name of the localized messages.protected static final StringThe string that separates the checker name from the option name in a "-A" command-line argument.protected @Nullable SourceCheckerThe checker that called this one, whether that be a BaseTypeChecker (used as a compound checker) or an AggregateChecker.protected @MonotonicNonNull List<SourceChecker>The full list of subcheckers that need to be run prior to this one, in the order they need to be run.protected @MonotonicNonNull Set<String>Supported options for this checker.static final StringThe message key that will suppress all warnings (it matches any message key).static final StringThe SuppressWarnings prefix that will suppress warnings for all checkers.protected @MonotonicNonNull Collection<String>The list of suppress warnings prefixes supported by this checker or any of its subcheckers (including indirect subcheckers).protected TreePathCacherTreePathCacher to share between subcheckers.protected TreesTree utilities; used as a helper for theSourceVisitor.protected TypesType utilities.static final @CompilerMessageKey StringThe message key emitted when an unused warning suppression is found.protected @MonotonicNonNull List<@FullyQualifiedName String>List of upstream checker names.protected booleanIf true, use the "allcheckers:" warning string prefix.protected SourceVisitor<?,?> The visitor to use.Fields inherited from class javax.annotation.processing.AbstractProcessorprocessingEnv
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected abstract SourceVisitor<?,?> Provides theSourceVisitorthat the checker should use to scan input source trees.Compute the set of supported lint options for this checker and its subcheckers.protected Collection<String>expandCFOptions(List<? extends Class<?>> clazzPrefixes, String[] options) Generate the possible command-line option names by prefixing each class name fromclassPrefixestooptions, separated byOPTION_SEPARATOR.protected StringfullMessageOf(String messageKey, String defaultValue) Returns the localized long message corresponding to this key.Returns the AnnotationProvider (the type factory) associated with this.final booleangetBooleanOption(String name) Determines the boolean value of the option with the given name.final booleangetBooleanOption(String name, boolean defaultValue) Determines the boolean value of the option with the given name.Returns the element utilities associated with this.Return a list of stub files to be treated as if they had been written in a@StubFilesannotation.protected Set<Class<? extends SourceChecker>>Returns the set of subchecker classes on which this checker depends.final booleangetLintOption(String name) Determines the value of the lint option with the given name.final booleangetLintOption(String name, boolean def) Determines the value of the lint option with the given name.Provides a mapping of error keys to custom error messages.final StringDetermines the value of the option with the given name.final StringDetermines the boolean value of the option with the given name.Returns the OptionConfiguration associated with this.Return all active options for this checker.LikegetOptions(), but only includes options passed to this checker.Returns the immediate parent checker of the current checker.Return the path to the current compilation unit.Returns theProcessingEnvironmentthat was supplied to this checker.protected PropertiesgetProperties(Class<?> cls, String filePath, boolean permitNonExisting) A helper function to parse a Properties file.static @ClassGetName StringgetRelatedClassName(Class<?> checkerClass, String replacement) Returns the name of a class related to a given one, by replacing "Checker" or "Subchecker" byreplacement.protected final NavigableSet<String>Returns a sorted set of SuppressWarnings prefixes read from theSuppressWarningsPrefixmeta-annotation on the checker class.getStringsOption(String name, char separator, List<String> defaultValue) Determines the string list value of the option with the given name.getStringsOption(String name, String separator, List<String> defaultValue) Determines the string list value of the option with the given name.<T extends SourceChecker>
 @Nullable TgetSubchecker(Class<T> checkerClass) Returns the requested (immediate) subchecker.protected intIndex of this checker ingetSubcheckers()(whengetSubcheckers()is called on the ultimate ancestor), or the size ofgetSubcheckers()if this is the ancestor checker.Get the list of all subcheckers (if any).Overrides the default implementation to always return a singleton set containing only "*".Returns the lint options recognized by this checker.Map the Checker Framework version ofSupportedOptionsto the standard annotation provided versionSupportedOptions.final SourceVersionReturns a modifiable set of lower-case strings that are prefixes for SuppressWarnings strings.LikegetSuppressWarningsPrefixes(), but includes all prefixes supported by this checker or any of its subcheckers.Get the shared TreePathCacher instance.Returns the tree utilities associated with this.Returns the type utilities associated with this.Returns a list containing this checker name and all checkers it is a part of (that is, checkers that called it).SourceVisitor<?,?> Returns the SourceVisitor associated with this.final booleanCheck whether the given option is provided.final booleanhasOptionNoSubcheckers(String name) LikehasOption(java.lang.String), but checks whether the given option is passed to this checker.final voidvoidInitialize the checker.protected List<SourceChecker>instantiateSubcheckers(Map<Class<? extends SourceChecker>, SourceChecker> alreadyInitializedSubcheckerMap) Computes the unmodifiable list of immediate subcheckers of this checker, in the order the checkers need to be run.voidmessage(Diagnostic.Kind kind, String msg) Print a non-localized message using the javac messager.voidmessage(Diagnostic.Kind kind, String msg, Object... args) Print a non-localized message using the javac messager.protected booleanmessageKeyMatches(String messageKey, String messageKeyInSuppressWarningsString) Does the given messageKey match a messageKey that appears in a SuppressWarnings? Subclasses should override this method if they need additional logic to compare message keys.protected voidprintOrStoreMessage(Diagnostic.Kind kind, String message, Tree source, CompilationUnitTree root) Do not call this method.protected voidprintOrStoreMessage(Diagnostic.Kind kind, String message, Tree source, CompilationUnitTree root, StackTraceElement[] trace) Do not call this method.protected voidPrint resource usage statistics.protected voidPrints error messages for this checker and all subcheckers such that the errors are ordered by line and column number and then by checker.protected ObjectProcess an argument to an error message before it is passed to String.format.voidreport(@Nullable Object source, DiagMessage d) Reports a diagnostic message.voidreportError(@Nullable Object source, @CompilerMessageKey String messageKey, Object... args) Reports an error.voidreportWarning(@Nullable Object source, @CompilerMessageKey String messageKey, Object... args) Reports a warning.protected final voidsetLintOption(String name, boolean val) Set the value of the lint option with the given name.protected voidsetParentChecker(SourceChecker parentChecker) Set the parent checker of the current checker.voidsetRoot(CompilationUnitTree newRoot) Invoked when the current compilation unit root changes.protected booleanReturn true to indicate that methodshutdownHook()should be added as a shutdownHook of the JVM.booleanReturns true if reflection should be resolved.final booleanshouldSkipDefs(ClassTree tree) Tests whether the class definition should not be checked because it matches thechecker.skipDefsproperty.final booleanshouldSkipDefs(ClassTree cls, MethodTree meth) Tests whether the method definition should not be checked because it matches thechecker.skipDefsproperty.booleanshouldSkipDefs(MethodTree tree) Tests whether the method definition should not be checked because it matches thechecker.skipDefsproperty.final booleanshouldSkipFiles(ClassTree tree) Tests whether the enclosing file path of the passed tree matches the pattern specified in thechecker.skipFilesproperty.final booleanshouldSkipUses(@Nullable Element element) Tests whether the class owner of the passed element is an unannotated class and matches the pattern specified in thechecker.skipUsesproperty.booleanshouldSkipUses(@FullyQualifiedName String typeName) Tests whether the class owner of the passed type matches the pattern specified in thechecker.skipUsesproperty.booleanshouldSuppressWarnings(@Nullable TreePath path, String errKey) Returns true if all the warnings pertaining to a given tree path should be suppressed.booleanshouldSuppressWarnings(@Nullable Element elt, String errKey) Returns true if all the warnings pertaining to a given element should be suppressed.booleanshouldSuppressWarnings(Tree tree, String errKey) Returns true if all the warnings pertaining to a given tree should be suppressed.protected voidMethod that gets called exactly once at shutdown time of the JVM.voidtypeProcess(TypeElement e, TreePath p) Type-check the code using this checker's visitor.voidA method to be called once all the classes are processed.voidA method to be called once before the first call to typeProcess.booleanuseConservativeDefault(String kindOfCode) Should conservative defaults be used for the kind of unchecked code indicated by the parameter?protected voidIssues a warning about any@SuppressWarningsthat didn't suppress a warning, but starts with this checker name or "allcheckers".protected voidwarnUnneededSuppressions(Set<Element> elementsSuppress, Set<String> prefixes, Set<String> allErrorKeys) Issues a warning about any@SuppressWarningsstring that didn't suppress a warning, but starts with one of the given prefixes (checker names).Methods inherited from class org.checkerframework.javacutil.AbstractTypeProcessorgetCompilerLog, processMethods inherited from class javax.annotation.processing.AbstractProcessorgetCompletions, isInitializedMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.checkerframework.framework.util.OptionConfigurationgetStringsOption, getStringsOption
- 
Field Details- 
SUPPRESS_ALL_MESSAGE_KEYThe message key that will suppress all warnings (it matches any message key).- See Also:
 
- 
SUPPRESS_ALL_PREFIXThe SuppressWarnings prefix that will suppress warnings for all checkers.- See Also:
 
- 
UNNEEDED_SUPPRESSION_KEYThe message key emitted when an unused warning suppression is found.- See Also:
 
- 
MSGS_FILEFile name of the localized messages.- See Also:
 
- 
messagesPropertiesMaps error keys to localized/custom error messages. Do not use directly; callfullMessageOf(java.lang.String, java.lang.String)orprocessErrorMessageArg(java.lang.Object). Is set ininitChecker().
- 
messagerUsed to report error messages and warnings via the compiler. Is set intypeProcessingStart().
- 
elementsElement utilities.
- 
treesTree utilities; used as a helper for theSourceVisitor.
- 
typesType utilities.
- 
currentRootThe source tree that is being scanned. Is set insetRoot(com.sun.source.tree.CompilationUnitTree).
- 
visitorThe visitor to use.
- 
suppressWarningsPrefixesOfSubcheckersThe list of suppress warnings prefixes supported by this checker or any of its subcheckers (including indirect subcheckers). Do not access this field directly; instead, usegetSuppressWarningsPrefixesOfSubcheckers().
- 
messageStoreStores all messages issued by this checker and its subcheckers for the current compilation unit. The messages are printed after all checkers have processed the current compilation unit. The purpose is to sort messages, grouping together all messages about a particular line of code.If this checker has no subcheckers and is not a subchecker for any other checker, then messageStore is null and messages will be printed as they are issued by this checker. 
- 
useAllcheckersPrefixprotected boolean useAllcheckersPrefixIf true, use the "allcheckers:" warning string prefix.Checkers that never issue any error messages should set this to false. That prevents -AwarnUnneededSuppressionsfrom issuing warnings about@SuppressWarnings("allcheckers:...").
- 
activeOptionsThe active options for this checker. This is a processed version ofProcessingEnvironment.getOptions(): If the option is of the form "-ACheckerName_key=value" and the current checker class, or one of its superclasses, is named "CheckerName", then add key → value. If the option is of the form "-ACheckerName_key=value" and the current checker class, and none of its superclasses, is named "CheckerName", then do not add key → value. If the option is of the form "-Akey=value", then add key → value.Both the simple and the canonical name of the checker can be used. Superclasses of the current checker are also considered. 
- 
supportedOptionsSupported options for this checker. This is the set of all possible options that could be passed to this checker. By contrast,activeOptionsis a map for options that were passed for this run of the checker.
- 
OPTION_SEPARATORThe string that separates the checker name from the option name in a "-A" command-line argument. This string may only consist of valid Java identifier part characters, because it will be used within the key of an option.- See Also:
 
- 
parentCheckerThe checker that called this one, whether that be a BaseTypeChecker (used as a compound checker) or an AggregateChecker. Null if this is the checker that calls all others. Note that in the case of a compound checker, the compound checker is the parent, not the checker that was run prior to this one by the compound checker.
- 
upstreamCheckerNamesList of upstream checker names. Includes the current checker.
- 
subcheckersThe full list of subcheckers that need to be run prior to this one, in the order they need to be run. This list will only be non-empty for the one checker that runs all other subcheckers. Do not read this field directly. Instead, retrieve it viagetSubcheckers().This field will be nulluntilgetSubcheckersis called.getSubcheckerssets this field to an immutable list which is empty for all but the ultimate parent checker.
- 
immediateSubcheckersThe list of subcheckers that are direct dependencies of this checker. This list will be non-empty for any checker that has at least one subchecker.
- 
treePathCacherTreePathCacher to share between subcheckers. Initialized either ingetTreePathCacher()orinstantiateSubcheckers(Map).
- 
javacErroredprotected boolean javacErroredIf true, javac failed to compile the code or a previously-run annotation processor issued an error.
- 
DETAILS_SEPARATORSeparates parts of a "detailed message", to permit easier parsing.- See Also:
 
- 
elementsWithSuppressedWarningsElements with a@SuppressWarningsthat actually suppressed a warning for this checker.
 
- 
- 
Constructor Details- 
SourceCheckerprotected SourceChecker()Creates a source checker.
 
- 
- 
Method Details- 
initDescription copied from class:AbstractTypeProcessorRegister a TaskListener that will get called after FLOW. - Specified by:
- initin interface- Processor
- Overrides:
- initin class- AbstractTypeProcessor
 
- 
getProcessingEnvironmentReturns theProcessingEnvironmentthat was supplied to this checker.- Returns:
- the ProcessingEnvironmentthat was supplied to this checker
 
- 
setParentCheckerSet the parent checker of the current checker.
- 
getParentCheckerReturns the immediate parent checker of the current checker.- Returns:
- the immediate parent checker of the current checker, or null if there is none
 
- 
setRootInvoked when the current compilation unit root changes.- Parameters:
- newRoot- the new compilation unit root
 
- 
getUpstreamCheckerNamesReturns a list containing this checker name and all checkers it is a part of (that is, checkers that called it).- Returns:
- a list containing this checker name and all checkers it is a part of (that is, checkers that called it)
 
- 
getOptionConfigurationReturns the OptionConfiguration associated with this.- Returns:
- the OptionConfiguration associated with this
 
- 
getElementUtilsReturns the element utilities associated with this.- Returns:
- the element utilities associated with this
 
- 
getTypeUtilsReturns the type utilities associated with this.- Returns:
- the type utilities associated with this
 
- 
getTreeUtilsReturns the tree utilities associated with this.- Returns:
- the tree utilities associated with this
 
- 
getVisitorReturns the SourceVisitor associated with this.- Returns:
- the SourceVisitor associated with this
 
- 
getOptionsNoSubcheckersLikegetOptions(), but only includes options passed to this checker. Does not include those passed only to subcheckers.- Returns:
- the active options for this checker, not including those passed only to subcheckers
 
- 
hasOptionNoSubcheckersLikehasOption(java.lang.String), but checks whether the given option is passed to this checker. Does not consider options only passed to subcheckers.- Parameters:
- name- the name of the option to check
- Returns:
- true if the option name was passed to this checker, false otherwise
 
- 
getExtraStubFilesReturn a list of stub files to be treated as if they had been written in a@StubFilesannotation.- Returns:
- stub files to be treated as if they had been written in a @StubFilesannotation
 
- 
createSourceVisitorProvides theSourceVisitorthat the checker should use to scan input source trees.- Returns:
- a SourceVisitorto use to scan source trees
 
- 
getAnnotationProviderReturns the AnnotationProvider (the type factory) associated with this.- Returns:
- the AnnotationProvider (the type factory) associated with this
 
- 
getMessagesPropertiesProvides a mapping of error keys to custom error messages.As a default, this implementation builds a Propertiesout of filemessages.properties. It accumulates all the properties files in the Java class hierarchy from the checker up toSourceChecker. This permits subclasses to inherit default messages while being able to override them.- Returns:
- a Propertiesthat maps error keys to error message text
 
- 
typeProcessingStartpublic void typeProcessingStart()A method to be called once before the first call to typeProcess.Subclasses may override this method to do any initialization work. Type-checkers are not supposed to override this. Instead override initChecker. This allows us to handle BugInCF only here and doesn't require all overriding implementations to be aware of BugInCF. - Overrides:
- typeProcessingStartin class- AbstractTypeProcessor
- See Also:
 
- 
typeProcessingOverpublic void typeProcessingOver()Description copied from class:AbstractTypeProcessorA method to be called once all the classes are processed.Subclasses may override this method to do any aggregate analysis (e.g. generate report, persistence) or resource deallocation. Method AbstractTypeProcessor.getCompilerLog()can be used to access the number of compiler errors.- Overrides:
- typeProcessingOverin class- AbstractTypeProcessor
 
- 
initCheckerpublic void initChecker()Initialize the checker.
- 
getSubcheckerReturns the requested (immediate) subchecker. A checker of a given class can only be run once, so this returns the only such checker, or null if none was found. The caller must know the exact checker class to request.- Type Parameters:
- T- the class of the subchecker to return
- Parameters:
- checkerClass- the class of the subchecker to return
- Returns:
- the requested (immediate) subchecker or null if not found
 
- 
instantiateSubcheckersprotected List<SourceChecker> instantiateSubcheckers(Map<Class<? extends SourceChecker>, SourceChecker> alreadyInitializedSubcheckerMap) Computes the unmodifiable list of immediate subcheckers of this checker, in the order the checkers need to be run.Modifies the alreadyInitializedSubcheckerMapparameter by adding all recursively newly instantiated subcheckers' class objects and instances. It is necessary to use a map that preserves the order in which entries were inserted, such as LinkedHashMap or ArrayMap.- Parameters:
- alreadyInitializedSubcheckerMap- subcheckers that have already been instantiated. Is modified by this method. Its point is to ensure that if two checkers A and B both depend on checker C, then checker C is instantiated and run only once, not twice.
- Returns:
- the unmodifiable list of immediate subcheckers of this checker
 
- 
getSubcheckersGet the list of all subcheckers (if any). This list is only non-empty for the one checker that runs all other subcheckers. These are recursively instantiated via instantiateSubcheckers() the first time this method is called if fieldsubcheckersis null. Assumes all checkers run on the same thread.- Returns:
- the list of all subcheckers (if any)
 
- 
getTreePathCacherGet the shared TreePathCacher instance.- Returns:
- the shared TreePathCacher instance.
 
- 
typeProcessType-check the code using this checker's visitor.- Specified by:
- typeProcessin class- AbstractTypeProcessor
- Parameters:
- e- element of the analyzed class
- p- the tree path to the element, with the leaf being a- ClassTree
- See Also:
 
- 
reportErrorpublic void reportError(@Nullable Object source, @CompilerMessageKey String messageKey, Object... args) Reports an error. By default, prints it to the screen via the compiler's internal messager.- Parameters:
- source- the source position information; may be an Element, a Tree, or null
- messageKey- the message key
- args- arguments for interpolation in the string corresponding to the given message key
 
- 
reportWarningpublic void reportWarning(@Nullable Object source, @CompilerMessageKey String messageKey, Object... args) Reports a warning. By default, prints it to the screen via the compiler's internal messager.- Parameters:
- source- the source position information; may be an Element, a Tree, or null
- messageKey- the message key
- args- arguments for interpolation in the string corresponding to the given message key
 
- 
reportReports a diagnostic message. By default, prints it to the screen via the compiler's internal messager.It is rare to use this method. Most clients should use reportError(java.lang.Object, java.lang.String, java.lang.Object...)orreportWarning(java.lang.Object, java.lang.String, java.lang.Object...).- Parameters:
- source- the source position information; may be an Element, a Tree, or null
- d- the diagnostic message
 
- 
messagePrint a non-localized message using the javac messager. This is preferable to using System.out or System.err, but should only be used for exceptional cases that don't happen in correct usage. Localized messages should be raised usingreportError(java.lang.Object, java.lang.String, java.lang.Object...),reportWarning(java.lang.Object, java.lang.String, java.lang.Object...), etc.- Parameters:
- kind- the kind of message to print
- msg- the message text
- args- optional arguments to substitute in the message
- See Also:
 
- 
messagePrint a non-localized message using the javac messager. This is preferable to using System.out or System.err, but should only be used for exceptional cases that don't happen in correct usage. Localized messages should be raised usingreportError(java.lang.Object, java.lang.String, java.lang.Object...),reportWarning(java.lang.Object, java.lang.String, java.lang.Object...), etc.- Parameters:
- kind- the kind of message to print
- msg- the message text
- See Also:
 
- 
getSuppressWarningsPrefixesOfSubcheckersLikegetSuppressWarningsPrefixes(), but includes all prefixes supported by this checker or any of its subcheckers. Does not guarantee that the result is in any particular order. The result is immutable.- Returns:
- the suppress warnings prefixes supported by this checker or any of its subcheckers
 
- 
printOrStoreMessageprotected void printOrStoreMessage(Diagnostic.Kind kind, String message, Tree source, CompilationUnitTree root) Do not call this method. CallreportError(java.lang.Object, java.lang.String, java.lang.Object...)orreportWarning(java.lang.Object, java.lang.String, java.lang.Object...)instead.This method exists so that the BaseTypeChecker can override it. For compound checkers, it stores all messages and sorts them by location before outputting them. - Parameters:
- kind- the kind of message to print
- message- the message text
- source- the source code position of the diagnostic message
- root- the compilation unit
 
- 
printOrStoreMessageprotected void printOrStoreMessage(Diagnostic.Kind kind, String message, Tree source, CompilationUnitTree root, StackTraceElement[] trace) Do not call this method. CallreportError(java.lang.Object, java.lang.String, java.lang.Object...)orreportWarning(java.lang.Object, java.lang.String, java.lang.Object...)instead.This method exists so that the BaseTypeChecker can override it. For compound checkers, it stores all messages and sorts them by location before outputting them. - Parameters:
- kind- the kind of message to print
- message- the message text
- source- the source code position of the diagnostic message
- root- the compilation unit
- trace- the stack trace where the checker encountered an error. It is printed when the dumpOnErrors option is enabled.
 
- 
fullMessageOfReturns the localized long message corresponding to this key. If not found, tries suffixes of this key, stripping off dot-separated prefixes. If still not found, returnsdefaultValue.- Parameters:
- messageKey- a message key
- defaultValue- a default value to use if- messageKeyis not a message key
- Returns:
- the localized long message corresponding to this key or a suffix, or defaultValue
 
- 
processErrorMessageArgProcess 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, fullMessageOf(java.lang.String, java.lang.String)processes the message key itself but not the arguments, and tries suffixes.- Parameters:
- arg- the argument
- Returns:
- the result after processing
 
- 
getLintOptionDetermines the value of the lint option with the given name. Just as javac uses "-Xlint:xxx" to enable and "-Xlint:-xxx" to disable option xxx, annotation-related lint options are enabled with "-Alint:xxx" and disabled with "-Alint:-xxx".- Parameters:
- name- the name of the lint option to check for
- Returns:
- true if the lint option was given, false if it was not given or was given prepended with a "-"
- Throws:
- IllegalArgumentException- if the option name is not recognized via the- SupportedLintOptionsannotation or the- getSupportedLintOptions()method
- See Also:
 
- 
getLintOptionDetermines the value of the lint option with the given name. Just as javac uses "-Xlint:xxx" to enable and "-Xlint:-xxx" to disable option xxx, annotation-related lint options are enabled with "-Alint=xxx" and disabled with "-Alint=-xxx".- Parameters:
- name- the name of the lint option to check for
- def- the default option value, returned if the option was not given
- Returns:
- true if the lint option was given, false if it was given prepended with a "-", or
     defif it was not given at all
- Throws:
- IllegalArgumentException- if the option name is not recognized via the- SupportedLintOptionsannotation or the- getSupportedLintOptions()method
- See Also:
 
- 
setLintOptionSet the value of the lint option with the given name. Just as javac uses "-Xlint:xxx" to enable and "-Xlint:-xxx" to disable option xxx, annotation-related lint options are enabled with "-Alint=xxx" and disabled with "-Alint=-xxx". This method can be used by subclasses to enforce having certain lint options enabled/disabled.- Parameters:
- name- the name of the lint option to set
- val- the option value
- Throws:
- IllegalArgumentException- if the option name is not recognized via the- SupportedLintOptionsannotation or the- getSupportedLintOptions()method
- See Also:
 
- 
getImmediateSubcheckerClassesReturns the set of subchecker classes on which this checker depends. ("Depends" means the checkers that are subcheckers of the current checker rather than a subchecker of some other checker.) Returns an empty set if this checker does not depend on any others.If this checker should run multiple independent checkers and not contain a type system, then subclass AggregateChecker.Subclasses should override this method to specify subcheckers. If they do so, they should call the super implementation of this method and add dependencies to the returned set so that checkers required for reflection resolution are included if reflection resolution is requested. If a checker should be added or not based on a command line option, use getOptionsNoSubcheckers()orhasOptionNoSubcheckers(String)to avoid recursively calling this method.Each subchecker of this checker may also depend on other checkers. If this checker and one of its subcheckers both depend on a third checker, that checker will only be instantiated once. Though each checker is run on a whole compilation unit before the next checker is run, error and warning messages are collected and sorted based on the location in the source file before being printed. (See printOrStoreMessage(Diagnostic.Kind, String, Tree, CompilationUnitTree).)WARNING: Circular dependencies are not supported. (In other words, if checker A depends on checker B, checker B cannot depend on checker A.) The Checker Framework does not check for circularity. Make sure no circular dependencies are created when overriding this method. This method is protected so it can be overridden, but it should only be called internally by SourceChecker.- Returns:
- the subchecker classes on which this checker depends; will be modified by callees
 
- 
shouldResolveReflectionpublic boolean shouldResolveReflection()Returns true if reflection should be resolved.- Returns:
- true if reflection should be resolved
 
- 
getRelatedClassNameReturns the name of a class related to a given one, by replacing "Checker" or "Subchecker" byreplacement.- Parameters:
- checkerClass- the checker class
- replacement- the string that replaces "Checker" or "Subchecker"
- Returns:
- the name of the related class
 
- 
getSupportedLintOptionsReturns the lint options recognized by this checker. Lint options are those which can be checked for viagetLintOption(java.lang.String).- Returns:
- an unmodifiable Setof the lint options recognized by this checker
 
- 
createSupportedLintOptionsCompute the set of supported lint options for this checker and its subcheckers.- Returns:
- the set of supported lint options for this checker and its subcheckers
 
- 
getOptionsDescription copied from interface:OptionConfigurationReturn all active options for this checker.- Specified by:
- getOptionsin interface- OptionConfiguration
- Returns:
- all active options for this checker
 
- 
hasOptionDescription copied from interface:OptionConfigurationCheck whether the given option is provided.Note that OptionConfiguration.getOption(java.lang.String)can still return null even ifhasOptionreturns true: this happens e.g. for-Amyopt- Specified by:
- hasOptionin interface- OptionConfiguration
- Parameters:
- name- the name of the option to check
- Returns:
- true if the option name was provided, false otherwise
 
- 
getOptionDetermines the value of the option with the given name.Note that getOptioncan still return null even ifOptionConfiguration.hasOption(java.lang.String)returns true: this happens e.g. for-Amyopt- Specified by:
- getOptionin interface- OptionConfiguration
- Parameters:
- name- the name of the option to check
- Returns:
- the value of the option with the given name
- See Also:
 
- 
getOptionDetermines the boolean value of the option with the given name. ReturnsdefaultValueif the option is not set.- Specified by:
- getOptionin interface- OptionConfiguration
- Parameters:
- name- the name of the option to check
- defaultValue- the default value to return if the option is not set
- Returns:
- the value of the option with the given name, or defaultValue
- See Also:
 
- 
getBooleanOptionDetermines the boolean value of the option with the given name. Returns false if the option is not set.- Specified by:
- getBooleanOptionin interface- OptionConfiguration
- Parameters:
- name- the name of the option to check
- Returns:
- the boolean value of the option
- See Also:
 
- 
getBooleanOptionDetermines the boolean value of the option with the given name. Returns the given default value if the option is not set.- Specified by:
- getBooleanOptionin interface- OptionConfiguration
- Parameters:
- name- the name of the option to check
- defaultValue- the default value to use if the option is not set
- Returns:
- the boolean value of the option
- See Also:
 
- 
getStringsOptionDetermines the string list value of the option with the given name. The option's value is split on the given separator. Returns the given default value if the option is not set.- Specified by:
- getStringsOptionin interface- OptionConfiguration
- Parameters:
- name- the name of the option to check
- separator- the separator for list elements
- defaultValue- the default value to use if the option is not set
- Returns:
- the list of options
- See Also:
 
- 
getStringsOptionpublic final List<String> getStringsOption(String name, String separator, List<String> defaultValue) Determines the string list value of the option with the given name. The option's value is split on the given separator. Returns the given default value if the option is not set.- Specified by:
- getStringsOptionin interface- OptionConfiguration
- Parameters:
- name- the name of the option to check
- separator- the separator for list elements
- defaultValue- the default value to use if the option is not set
- Returns:
- the list of options
- See Also:
 
- 
printStoredMessagesPrints error messages for this checker and all subcheckers such that the errors are ordered by line and column number and then by checker. (SeeSourceChecker.CheckerMessage.compareTo(CheckerMessage)for more precise order.)- Parameters:
- unit- current compilation unit
 
- 
getSupportedOptionsDescription copied from interface:OptionConfigurationMap the Checker Framework version ofSupportedOptionsto the standard annotation provided versionSupportedOptions.- Specified by:
- getSupportedOptionsin interface- OptionConfiguration
- Specified by:
- getSupportedOptionsin interface- Processor
- Overrides:
- getSupportedOptionsin class- AbstractProcessor
- Returns:
- the supported options
 
- 
expandCFOptionsprotected Collection<String> expandCFOptions(List<? extends Class<?>> clazzPrefixes, String[] options) Generate the possible command-line option names by prefixing each class name fromclassPrefixestooptions, separated byOPTION_SEPARATOR.- Parameters:
- clazzPrefixes- the classes to prefix
- options- the option names
- Returns:
- the possible combinations that should be supported
 
- 
getSupportedAnnotationTypesOverrides the default implementation to always return a singleton set containing only "*".javac uses this list to determine which classes process; javac only runs an annotation processor on classes that contain at least one of the mentioned annotations. Thus, the effect of returning "*" is as if the checker were annotated by @SupportedAnnotationTypes("*"): javac runs the checker on every class mentioned on the javac command line. This method also checks that subclasses do not contain aSupportedAnnotationTypesannotation.To specify the annotations that a checker recognizes as type qualifiers, see AnnotatedTypeFactory.createSupportedTypeQualifiers().- Specified by:
- getSupportedAnnotationTypesin interface- Processor
- Overrides:
- getSupportedAnnotationTypesin class- AbstractProcessor
- Throws:
- Error- if a subclass is annotated with- SupportedAnnotationTypes
 
- 
warnUnneededSuppressionsprotected void warnUnneededSuppressions()Issues a warning about any@SuppressWarningsthat didn't suppress a warning, but starts with this checker name or "allcheckers".
- 
warnUnneededSuppressionsprotected void warnUnneededSuppressions(Set<Element> elementsSuppress, Set<String> prefixes, Set<String> allErrorKeys) Issues a warning about any@SuppressWarningsstring that didn't suppress a warning, but starts with one of the given prefixes (checker names). Does nothing if the string doesn't start with a checker name.- Parameters:
- elementsSuppress- elements with a- @SuppressWarningsthat actually suppressed a warning
- prefixes- the SuppressWarnings prefixes that suppress all warnings from this checker
- allErrorKeys- all error keys that can be issued by this checker
 
- 
shouldSuppressWarningsReturns true if all the warnings pertaining to a given tree should be suppressed. Returns true if the tree is within the scope of a @SuppressWarnings annotation, one of whose values suppresses the checker's warning. Also, returns true if theerrKeymatches a string in-AsuppressWarnings.- Parameters:
- tree- the tree that might be a source of a warning
- errKey- the error key the checker is emitting
- Returns:
- true if no warning should be emitted for the given tree because it is contained by a declaration with an appropriately-valued @SuppressWarnings annotation; false otherwise
 
- 
shouldSuppressWarningsReturns true if all the warnings pertaining to a given tree path should be suppressed. Returns true if the path is within the scope of a @SuppressWarnings annotation, one of whose values suppresses the checker's warning.- Parameters:
- path- the TreePath that might be a source of, or related to, a warning
- errKey- the error key the checker is emitting
- Returns:
- true if no warning should be emitted for the given path because it is contained by a
     declaration with an appropriately-valued @SuppressWarningsannotation; false otherwise
 
- 
useConservativeDefaultShould conservative defaults be used for the kind of unchecked code indicated by the parameter?- Parameters:
- kindOfCode- source or bytecode
- Returns:
- whether conservative defaults should be used
 
- 
shouldSuppressWarningsReturns true if all the warnings pertaining to a given element should be suppressed. Returns true if the element is within the scope of a @SuppressWarnings annotation, one of whose values suppresses all the checker's warnings.- Parameters:
- elt- the Element that might be a source of, or related to, a warning
- errKey- the error key the checker is emitting
- Returns:
- true if no warning should be emitted for the given Element because it is contained by a
     declaration with an appropriately-valued @SuppressWarningsannotation; false otherwise
 
- 
messageKeyMatchesDoes the given messageKey match a messageKey that appears in a SuppressWarnings? Subclasses should override this method if they need additional logic to compare message keys.- Parameters:
- messageKey- the message key of the error that is being emitted, without any "checker:" prefix
- messageKeyInSuppressWarningsString- the message key in a- @SuppressWarningsannotation
- Returns:
- true if the arguments match
 
- 
getSuppressWarningsPrefixesReturns a modifiable set of lower-case strings that are prefixes for SuppressWarnings strings.The collection must not be empty and must not contain only SUPPRESS_ALL_PREFIX.- Returns:
- non-empty modifiable set of lower-case prefixes for SuppressWarnings strings
 
- 
getStandardSuppressWarningsPrefixesReturns a sorted set of SuppressWarnings prefixes read from theSuppressWarningsPrefixmeta-annotation on the checker class. Or if noSuppressWarningsPrefixis used, the checker name is used.SUPPRESS_ALL_PREFIXis also added, at the end, unlessuseAllcheckersPrefixis false.- Returns:
- a sorted set of SuppressWarnings prefixes
 
- 
shouldSkipUsesTests whether the class owner of the passed element is an unannotated class and matches the pattern specified in thechecker.skipUsesproperty.- Parameters:
- element- an element
- Returns:
- true iff the enclosing class of element should be skipped
 
- 
shouldSkipUsesTests whether the class owner of the passed type matches the pattern specified in thechecker.skipUsesproperty. In contrast toshouldSkipUses(Element)this version can also be used from primitive types, which don't have an element.Checkers that require their annotations not to be checked on certain JDK classes may override this method to skip them. They shall call super.shouldSkipUses(typeName)to also skip the classes matching the pattern.- Parameters:
- typeName- the fully-qualified name of a type
- Returns:
- true iff the enclosing class of element should be skipped
 
- 
shouldSkipDefsTests whether the class definition should not be checked because it matches thechecker.skipDefsproperty.- Parameters:
- tree- class to potentially skip
- Returns:
- true if checker should not type-check tree
 
- 
shouldSkipDefsTests whether the method definition should not be checked because it matches thechecker.skipDefsproperty.- Parameters:
- tree- method to potentially skip
- Returns:
- true if checker should not type-check tree
 
- 
shouldSkipDefsTests whether the method definition should not be checked because it matches thechecker.skipDefsproperty.TODO: currently only uses the class definition. Refine pattern. Same for skipUses. - Parameters:
- cls- class to potentially skip
- meth- method to potentially skip
- Returns:
- true if checker should not type-check meth
 
- 
shouldSkipFilesTests whether the enclosing file path of the passed tree matches the pattern specified in thechecker.skipFilesproperty.- Parameters:
- tree- a tree
- Returns:
- true iff the enclosing directory of the tree should be skipped
 
- 
shouldAddShutdownHookprotected boolean shouldAddShutdownHook()Return true to indicate that methodshutdownHook()should be added as a shutdownHook of the JVM.- Returns:
- true to add shutdownHook()as a shutdown hook of the JVM
 
- 
shutdownHookprotected void shutdownHook()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 shouldAddShutdownHook()to return true.
- 
printStatsprotected void printStats()Print resource usage statistics.
- 
getPropertiesA helper function to parse a Properties file.- Parameters:
- cls- the class whose location is the base of the file path
- filePath- the name/path of the file to be read
- permitNonExisting- if true, return an empty Properties if the file does not exist or cannot be parsed; if false, issue an error
- Returns:
- the properties
 
- 
getSupportedSourceVersion- Specified by:
- getSupportedSourceVersionin interface- Processor
- Overrides:
- getSupportedSourceVersionin class- AbstractProcessor
 
- 
getPathToCompilationUnitReturn the path to the current compilation unit.- Returns:
- path to the current compilation unit
 
- 
getSubCheckerIndexprotected int getSubCheckerIndex()Index of this checker ingetSubcheckers()(whengetSubcheckers()is called on the ultimate ancestor), or the size ofgetSubcheckers()if this is the ancestor checker.- Returns:
- index of this checker in the ultimate ancestor's getSubcheckers(), or the size ofgetSubcheckers()if this is the ancestor checker
 
 
-