Package com.puppycrawl.tools.checkstyle
Class Checker
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.Checker
- All Implemented Interfaces:
- Configurable,- Contextualizable,- MessageDispatcher,- RootModule
This class provides the functionality to check a set of files.
- 
Nested Class SummaryNested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanAbstractAutomaticBean.OutputStreamOptions
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate StringThe basedir to strip off in file names.private final BeforeExecutionFileFilterSetThe audit event before execution file filters.private PropertyCacheFileCache file.private StringName of a charset.private ContextThe context of all child components.private final SeverityLevelCounterMaintains error count.static final StringMessage to use when an exception occurs and should be printed as a violation.private static final StringThe extension separator.private String[]The file extensions that are accepted.private final List<FileSetCheck>Vector of fileset checks.private final FilterSetThe audit event filters.private booleanControls whether exceptions should halt execution or not.private final List<AuditListener>Vector of listeners.private StringLocale country to report messages .private StringLocale language to report messages .private final org.apache.commons.logging.LogLogger for Checker.private ClassLoaderThe classloader used for loading Checkstyle module classes.private ModuleFactoryThe factory for instantiating submodules.private SeverityLevelThe severity level of any violations found by submodules.private intThe tab width for column reporting.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprivate booleanacceptFileStarted(String fileName) Check if all before execution file filters accept starting the file.voidAdds a before execution file filter to the end of the event chain.voidaddFileSetCheck(FileSetCheck fileSetCheck) Adds a FileSetCheck to the list of FileSetChecks that is executed in process().voidAdds a filter to the end of the audit event filter chain.final voidaddListener(AuditListener listener) Add the listener that will be used to receive events from the audit.voidClears the cache.voiddestroy()Cleans up the object.protected voidPerforms final setup of the Checker after configuration is complete.private voidNotify all listeners about the audit end.private voidNotify all listeners about the audit start.voidfireErrors(String fileName, SortedSet<Violation> errors) Notify all listeners about the errors in a file.voidfireFileFinished(String fileName) Notify all listeners about the end of a file audit.voidfireFileStarted(String fileName) Notify all listeners about the beginning of a file audit.Returns a set of external configuration resource locations which are used by all file set checks and filters.private StringgetLocalizedMessage(String messageKey, Object... args) Extracts localized messages from properties files.intProcesses a set of files.processFile(File file) Processes a file with all FileSetChecks.private voidprocessFiles(List<File> files) Processes a list of files with all FileSetChecks.voidRemoves before execution file filter.voidremoveFilter(Filter filter) Removes filter.voidremoveListener(AuditListener listener) Removes a given listener.voidsetBasedir(String basedir) Sets base directory.voidsetCacheFile(String fileName) Sets cache file.voidsetCharset(String charset) Sets a named charset.final voidsetFileExtensions(String... extensions) Sets the file extensions that identify the files that pass the filter of this FileSetCheck.voidsetHaltOnException(boolean haltOnException) Sets the field haltOnException.voidsetLocaleCountry(String localeCountry) Sets locale country.voidsetLocaleLanguage(String localeLanguage) Sets locale language.final voidsetModuleClassLoader(ClassLoader moduleClassLoader) Sets the classloader used to load Checkstyle core and custom module classes when the module tree is being built up.voidsetModuleFactory(ModuleFactory moduleFactory) Sets the factory for creating submodules.final voidsetSeverity(String severity) Sets the severity level.final voidsetTabWidth(int tabWidth) Set the tab width to report audit events with.protected voidsetupChild(Configuration childConf) Called by configure() for every child of this component's Configuration.Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBeanconfigure, contextualize, getConfigurationMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.puppycrawl.tools.checkstyle.api.Configurableconfigure
- 
Field Details- 
EXCEPTION_MSGMessage to use when an exception occurs and should be printed as a violation.- See Also:
 
- 
EXTENSION_SEPARATORThe extension separator.- See Also:
 
- 
logLogger for Checker.
- 
counterMaintains error count.
- 
listenersVector of listeners.
- 
fileSetChecksVector of fileset checks.
- 
beforeExecutionFileFiltersThe audit event before execution file filters.
- 
filtersThe audit event filters.
- 
basedirThe basedir to strip off in file names.
- 
localeCountryLocale country to report messages .
- 
localeLanguageLocale language to report messages .
- 
moduleFactoryThe factory for instantiating submodules.
- 
moduleClassLoaderThe classloader used for loading Checkstyle module classes.
- 
childContextThe context of all child components.
- 
fileExtensionsThe file extensions that are accepted.
- 
severityThe severity level of any violations found by submodules. The value of this property is passed to submodules via contextualize().Note: Since the Checker is merely a container for modules it does not make sense to implement logging functionality here. Consequently, Checker does not extend AbstractViolationReporter, leading to a bit of duplicated code for severity level setting. 
- 
charsetName of a charset.
- 
cacheFileCache file.
- 
haltOnExceptionControls whether exceptions should halt execution or not.
- 
tabWidthThe tab width for column reporting.
 
- 
- 
Constructor Details- 
Checkerpublic Checker()Creates a newCheckerinstance. The instance needs to be contextualized and configured.
 
- 
- 
Method Details- 
setCacheFileSets cache file.- Parameters:
- fileName- the cache file.
- Throws:
- IOException- if there are some problems with file loading.
 
- 
removeBeforeExecutionFileFilterRemoves before execution file filter.- Parameters:
- filter- before execution file filter to remove.
 
- 
removeFilterRemoves filter.- Parameters:
- filter- filter to remove.
 
- 
destroyDescription copied from interface:RootModuleCleans up the object.- Specified by:
- destroyin interface- RootModule
 
- 
removeListenerRemoves a given listener.- Parameters:
- listener- a listener to remove
 
- 
setBasedirSets base directory.- Parameters:
- basedir- the base directory to strip off in file names
 
- 
processDescription copied from interface:RootModuleProcesses a set of files. Once this is done, it is highly recommended to call for the destroy method to close and remove the listeners.- Specified by:
- processin interface- RootModule
- Parameters:
- files- the list of files to be audited.
- Returns:
- the total number of audit events with error severity found
- Throws:
- CheckstyleException- if error condition within Checkstyle occurs
- See Also:
 
- 
getExternalResourceLocationsReturns a set of external configuration resource locations which are used by all file set checks and filters.- Returns:
- a set of external configuration resource locations which are used by all file set checks and filters.
 
- 
fireAuditStartedNotify all listeners about the audit start.
- 
fireAuditFinishedNotify all listeners about the audit end.
- 
processFilesProcesses a list of files with all FileSetChecks.- Parameters:
- files- a list of files to process.
- Throws:
- CheckstyleException- if error condition within Checkstyle occurs.
- Error- wraps any java.lang.Error happened during execution
 
- 
processFileProcesses a file with all FileSetChecks.- Parameters:
- file- a file to process.
- Returns:
- a sorted set of violations to be logged.
- Throws:
- CheckstyleException- if error condition within Checkstyle occurs.
 
- 
acceptFileStartedCheck if all before execution file filters accept starting the file.- Parameters:
- fileName- the file to be audited
- Returns:
- trueif the file is accepted.
 
- 
fireFileStartedNotify all listeners about the beginning of a file audit.- Specified by:
- fireFileStartedin interface- MessageDispatcher
- Parameters:
- fileName- the file to be audited
 
- 
fireErrorsNotify all listeners about the errors in a file.- Specified by:
- fireErrorsin interface- MessageDispatcher
- Parameters:
- fileName- the audited file
- errors- the audit errors from the file
 
- 
fireFileFinishedNotify all listeners about the end of a file audit.- Specified by:
- fireFileFinishedin interface- MessageDispatcher
- Parameters:
- fileName- the audited file
 
- 
finishLocalSetupPerforms final setup of the Checker after configuration is complete.- Specified by:
- finishLocalSetupin class- AbstractAutomaticBean
- Throws:
- CheckstyleException- if there is a configuration error.
 
- 
setupChildCalled by configure() for every child of this component's Configuration.The default implementation throws Creates child module.CheckstyleExceptionifchildConfisnullbecause it doesn't support children. It must be overridden to validate and support children that are wanted.- Overrides:
- setupChildin class- AbstractAutomaticBean
- Parameters:
- childConf- a child of this component's Configuration
- Throws:
- CheckstyleException- if there is a configuration error.
- See Also:
 
- 
addFileSetCheckAdds a FileSetCheck to the list of FileSetChecks that is executed in process().- Parameters:
- fileSetCheck- the additional FileSetCheck
 
- 
addBeforeExecutionFileFilterAdds a before execution file filter to the end of the event chain.- Parameters:
- filter- the additional filter
 
- 
addFilterAdds a filter to the end of the audit event filter chain.- Parameters:
- filter- the additional filter
 
- 
addListenerDescription copied from interface:RootModuleAdd the listener that will be used to receive events from the audit.- Specified by:
- addListenerin interface- RootModule
- Parameters:
- listener- the nosy thing
 
- 
setFileExtensionsSets the file extensions that identify the files that pass the filter of this FileSetCheck.- Parameters:
- extensions- the set of file extensions. A missing initial '.' character of an extension is automatically added.
 
- 
setModuleFactorySets the factory for creating submodules.- Parameters:
- moduleFactory- the factory for creating FileSetChecks
 
- 
setLocaleCountrySets locale country.- Parameters:
- localeCountry- the country to report messages
 
- 
setLocaleLanguageSets locale language.- Parameters:
- localeLanguage- the language to report messages
 
- 
setSeveritySets the severity level. The string should be one of the names defined in theSeverityLevelclass.- Parameters:
- severity- The new severity level
- See Also:
 
- 
setModuleClassLoaderDescription copied from interface:RootModuleSets the classloader used to load Checkstyle core and custom module classes when the module tree is being built up. If no custom ModuleFactory is being set for the root module then this module classloader must be specified.- Specified by:
- setModuleClassLoaderin interface- RootModule
- Parameters:
- moduleClassLoader- the classloader used to load module classes
 
- 
setCharsetSets a named charset.- Parameters:
- charset- the name of a charset
- Throws:
- UnsupportedEncodingException- if charset is unsupported.
 
- 
setHaltOnExceptionSets the field haltOnException.- Parameters:
- haltOnException- the new value.
 
- 
setTabWidthSet the tab width to report audit events with.- Parameters:
- tabWidth- an- intvalue
 
- 
clearCacheClears the cache.
- 
getLocalizedMessageExtracts localized messages from properties files.- Parameters:
- messageKey- the key pointing to localized message in respective properties file.
- args- the arguments of message in respective properties file.
- Returns:
- a string containing extracted localized message
 
 
-