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 Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier 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 Summary
Constructors -
Method Summary
Modifier 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 voidProvides a hook to finish the part of this component's setup that was not handled by the bean introspection.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.AbstractAutomaticBean
configure, contextualize, getConfigurationMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.puppycrawl.tools.checkstyle.api.Configurable
configure
-
Field Details
-
EXCEPTION_MSG
Message to use when an exception occurs and should be printed as a violation.- See Also:
-
EXTENSION_SEPARATOR
The extension separator.- See Also:
-
log
Logger for Checker. -
counter
Maintains error count. -
listeners
Vector of listeners. -
fileSetChecks
Vector of fileset checks. -
beforeExecutionFileFilters
The audit event before execution file filters. -
filters
The audit event filters. -
basedir
The basedir to strip off in file names. -
localeCountry
Locale country to report messages . -
localeLanguage
Locale language to report messages . -
moduleFactory
The factory for instantiating submodules. -
moduleClassLoader
The classloader used for loading Checkstyle module classes. -
childContext
The context of all child components. -
fileExtensions
The file extensions that are accepted. -
severity
The 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.
-
charset
Name of a charset. -
cacheFile
Cache file. -
haltOnException
Controls whether exceptions should halt execution or not. -
tabWidth
The tab width for column reporting.
-
-
Constructor Details
-
Checker
public Checker()Creates a newCheckerinstance. The instance needs to be contextualized and configured.
-
-
Method Details
-
setCacheFile
Sets cache file.- Parameters:
fileName- the cache file.- Throws:
IOException- if there are some problems with file loading.
-
removeBeforeExecutionFileFilter
Removes before execution file filter.- Parameters:
filter- before execution file filter to remove.
-
removeFilter
Removes filter.- Parameters:
filter- filter to remove.
-
destroy
Description copied from interface:RootModuleCleans up the object.- Specified by:
destroyin interfaceRootModule
-
removeListener
Removes a given listener.- Parameters:
listener- a listener to remove
-
setBasedir
Sets base directory.- Parameters:
basedir- the base directory to strip off in file names
-
process
Description 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 interfaceRootModule- 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:
-
getExternalResourceLocations
Returns 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.
-
fireAuditStarted
Notify all listeners about the audit start. -
fireAuditFinished
Notify all listeners about the audit end. -
processFiles
Processes 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
-
processFile
Processes 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.
-
acceptFileStarted
Check if all before execution file filters accept starting the file.- Parameters:
fileName- the file to be audited- Returns:
trueif the file is accepted.
-
fireFileStarted
Notify all listeners about the beginning of a file audit.- Specified by:
fireFileStartedin interfaceMessageDispatcher- Parameters:
fileName- the file to be audited
-
fireErrors
Notify all listeners about the errors in a file.- Specified by:
fireErrorsin interfaceMessageDispatcher- Parameters:
fileName- the audited fileerrors- the audit errors from the file
-
fireFileFinished
Notify all listeners about the end of a file audit.- Specified by:
fireFileFinishedin interfaceMessageDispatcher- Parameters:
fileName- the audited file
-
finishLocalSetup
Description copied from class:AbstractAutomaticBeanProvides a hook to finish the part of this component's setup that was not handled by the bean introspection.The default implementation does nothing.
- Specified by:
finishLocalSetupin classAbstractAutomaticBean- Throws:
CheckstyleException- if there is a configuration error.
-
setupChild
Called 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 classAbstractAutomaticBean- Parameters:
childConf- a child of this component's Configuration- Throws:
CheckstyleException- if there is a configuration error.- See Also:
-
addFileSetCheck
Adds a FileSetCheck to the list of FileSetChecks that is executed in process().- Parameters:
fileSetCheck- the additional FileSetCheck
-
addBeforeExecutionFileFilter
Adds a before execution file filter to the end of the event chain.- Parameters:
filter- the additional filter
-
addFilter
Adds a filter to the end of the audit event filter chain.- Parameters:
filter- the additional filter
-
addListener
Description copied from interface:RootModuleAdd the listener that will be used to receive events from the audit.- Specified by:
addListenerin interfaceRootModule- Parameters:
listener- the nosy thing
-
setFileExtensions
Sets 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.
-
setModuleFactory
Sets the factory for creating submodules.- Parameters:
moduleFactory- the factory for creating FileSetChecks
-
setLocaleCountry
Sets locale country.- Parameters:
localeCountry- the country to report messages
-
setLocaleLanguage
Sets locale language.- Parameters:
localeLanguage- the language to report messages
-
setSeverity
Sets the severity level. The string should be one of the names defined in theSeverityLevelclass.- Parameters:
severity- The new severity level- See Also:
-
setModuleClassLoader
Description 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 interfaceRootModule- Parameters:
moduleClassLoader- the classloader used to load module classes
-
setCharset
Sets a named charset.- Parameters:
charset- the name of a charset- Throws:
UnsupportedEncodingException- if charset is unsupported.
-
setHaltOnException
Sets the field haltOnException.- Parameters:
haltOnException- the new value.
-
setTabWidth
Set the tab width to report audit events with.- Parameters:
tabWidth- anintvalue
-
clearCache
Clears the cache. -
getLocalizedMessage
Extracts 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
-