Package com.puppycrawl.tools.checkstyle
Class Checker
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.Checker
-
- All Implemented Interfaces:
Configurable,Contextualizable,MessageDispatcher,RootModule
public class Checker extends AutomaticBean implements 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.api.AutomaticBean
AutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringEXCEPTION_MSGMessage to use when an exception occurs and should be printed as a violation.
-
Constructor Summary
Constructors Constructor Description Checker()Creates a newCheckerinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBeforeExecutionFileFilter(BeforeExecutionFileFilter filter)Adds 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().voidaddFilter(Filter filter)Adds a filter to the end of the audit event filter chain.voidaddListener(AuditListener listener)Add the listener that will be used to receive events from the audit.voidclearCache()Clears the cache.voiddestroy()Cleans up the object.protected voidfinishLocalSetup()Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.voidfireErrors(java.lang.String fileName, java.util.SortedSet<LocalizedMessage> errors)Notify all listeners about the errors in a file.voidfireFileFinished(java.lang.String fileName)Notify all listeners about the end of a file audit.voidfireFileStarted(java.lang.String fileName)Notify all listeners about the beginning of a file audit.intprocess(java.util.List<java.io.File> files)Processes a set of files.voidremoveBeforeExecutionFileFilter(BeforeExecutionFileFilter filter)Removes before execution file filter.voidremoveFilter(Filter filter)Removes filter.voidremoveListener(AuditListener listener)Removes a given listener.voidsetBasedir(java.lang.String basedir)Sets base directory.voidsetCacheFile(java.lang.String fileName)Sets cache file.voidsetCharset(java.lang.String charset)Sets a named charset.voidsetFileExtensions(java.lang.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(java.lang.String localeCountry)Sets locale country.voidsetLocaleLanguage(java.lang.String localeLanguage)Sets locale language.voidsetModuleClassLoader(java.lang.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.voidsetSeverity(java.lang.String severity)Sets the severity level.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.api.AutomaticBean
configure, contextualize, getConfiguration
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.puppycrawl.tools.checkstyle.api.Configurable
configure
-
-
-
-
Field Detail
-
EXCEPTION_MSG
public static final java.lang.String EXCEPTION_MSG
Message to use when an exception occurs and should be printed as a violation.- See Also:
- Constant Field Values
-
-
Method Detail
-
setCacheFile
public void setCacheFile(java.lang.String fileName) throws java.io.IOExceptionSets cache file.- Parameters:
fileName- the cache file.- Throws:
java.io.IOException- if there are some problems with file loading.
-
removeBeforeExecutionFileFilter
public void removeBeforeExecutionFileFilter(BeforeExecutionFileFilter filter)
Removes before execution file filter.- Parameters:
filter- before execution file filter to remove.
-
removeFilter
public void removeFilter(Filter filter)
Removes filter.- Parameters:
filter- filter to remove.
-
destroy
public void destroy()
Description copied from interface:RootModuleCleans up the object.- Specified by:
destroyin interfaceRootModule
-
removeListener
public void removeListener(AuditListener listener)
Removes a given listener.- Parameters:
listener- a listener to remove
-
setBasedir
public void setBasedir(java.lang.String basedir)
Sets base directory.- Parameters:
basedir- the base directory to strip off in file names
-
process
public int process(java.util.List<java.io.File> files) throws CheckstyleExceptionDescription 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:
RootModule.destroy()
-
fireFileStarted
public void fireFileStarted(java.lang.String fileName)
Notify all listeners about the beginning of a file audit.- Specified by:
fireFileStartedin interfaceMessageDispatcher- Parameters:
fileName- the file to be audited
-
fireErrors
public void fireErrors(java.lang.String fileName, java.util.SortedSet<LocalizedMessage> errors)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
public void fireFileFinished(java.lang.String fileName)
Notify all listeners about the end of a file audit.- Specified by:
fireFileFinishedin interfaceMessageDispatcher- Parameters:
fileName- the audited file
-
finishLocalSetup
protected void finishLocalSetup() throws CheckstyleExceptionDescription copied from class:AutomaticBeanProvides 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 classAutomaticBean- Throws:
CheckstyleException- if there is a configuration error.
-
setupChild
protected void setupChild(Configuration childConf) throws CheckstyleException
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 classAutomaticBean- Parameters:
childConf- a child of this component's Configuration- Throws:
CheckstyleException- if there is a configuration error.- See Also:
Configuration.getChildren()
-
addFileSetCheck
public void addFileSetCheck(FileSetCheck fileSetCheck)
Adds a FileSetCheck to the list of FileSetChecks that is executed in process().- Parameters:
fileSetCheck- the additional FileSetCheck
-
addBeforeExecutionFileFilter
public void addBeforeExecutionFileFilter(BeforeExecutionFileFilter filter)
Adds a before execution file filter to the end of the event chain.- Parameters:
filter- the additional filter
-
addFilter
public void addFilter(Filter filter)
Adds a filter to the end of the audit event filter chain.- Parameters:
filter- the additional filter
-
addListener
public final void addListener(AuditListener listener)
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
public final void setFileExtensions(java.lang.String... extensions)
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
public void setModuleFactory(ModuleFactory moduleFactory)
Sets the factory for creating submodules.- Parameters:
moduleFactory- the factory for creating FileSetChecks
-
setLocaleCountry
public void setLocaleCountry(java.lang.String localeCountry)
Sets locale country.- Parameters:
localeCountry- the country to report messages
-
setLocaleLanguage
public void setLocaleLanguage(java.lang.String localeLanguage)
Sets locale language.- Parameters:
localeLanguage- the language to report messages
-
setSeverity
public final void setSeverity(java.lang.String severity)
Sets the severity level. The string should be one of the names defined in theSeverityLevelclass.- Parameters:
severity- The new severity level- See Also:
SeverityLevel
-
setModuleClassLoader
public final void setModuleClassLoader(java.lang.ClassLoader moduleClassLoader)
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
public void setCharset(java.lang.String charset) throws java.io.UnsupportedEncodingExceptionSets a named charset.- Parameters:
charset- the name of a charset- Throws:
java.io.UnsupportedEncodingException- if charset is unsupported.
-
setHaltOnException
public void setHaltOnException(boolean haltOnException)
Sets the field haltOnException.- Parameters:
haltOnException- the new value.
-
setTabWidth
public final void setTabWidth(int tabWidth)
Set the tab width to report audit events with.- Parameters:
tabWidth- anintvalue
-
clearCache
public void clearCache()
Clears the cache.
-
-