com.puppycrawl.tools.checkstyle

Class Checker

public class Checker extends AutomaticBean implements MessageDispatcher

This class provides the functionality to check a set of files.

Author: Oliver Burn Stephane Bailliez lkuehne

Constructor Summary
Checker()
Creates a new Checker instance.
Method Summary
voidaddFileSetCheck(FileSetCheck aFileSetCheck)
Adds a FileSetCheck to the list of FileSetChecks that is executed in process().
voidaddFilter(Filter aFilter)
Adds a filter to the end of the audit event filter chain.
voidaddListener(AuditListener aListener)
Add the listener that will be used to receive events from the audit.
voiddestroy()
Cleans up the object.
voidfinishLocalSetup()
{@inheritDoc}
protected voidfireAuditFinished()
notify all listeners about the audit end
protected voidfireAuditStarted()
notify all listeners about the audit start
voidfireErrors(String aFileName, LocalizedMessage[] aErrors)
notify all listeners about the errors in a file.
voidfireFileFinished(String aFileName)
Notify all listeners about the end of a file audit.
voidfireFileStarted(String aFileName)
Notify all listeners about the beginning of a file audit.
StringgetBasedir()
Stringnormalize(String aPath)
"normalize" the given absolute path.
intprocess(File[] aFiles)
Processes a set of files with all FileSetChecks.
voidremoveFilter(Filter aFilter)
Removes filter.
voidremoveListener(AuditListener aListener)
Removes a given listener.
voidsetBasedir(String aBasedir)
voidsetClassloader(ClassLoader aLoader)
Sets the classloader that is used to contextualize filesetchecks.
voidsetLocaleCountry(String aLocaleCountry)
voidsetLocaleLanguage(String aLocaleLanguage)
voidsetModuleFactory(ModuleFactory aModuleFactory)
Sets the factory for creating submodules.
voidsetSeverity(String aSeverity)
Sets the severity level.
protected voidsetupChild(Configuration aChildConf)
Instantiates, configures and registers a child AbstractFilter or FileSetCheck that is specified in the provided configuration.

Constructor Detail

Checker

public Checker()
Creates a new Checker instance. The instance needs to be contextualized and configured.

Throws: CheckstyleException if an error occurs

Method Detail

addFileSetCheck

public void addFileSetCheck(FileSetCheck aFileSetCheck)
Adds a FileSetCheck to the list of FileSetChecks that is executed in process().

Parameters: aFileSetCheck the additional FileSetCheck

addFilter

public void addFilter(Filter aFilter)
Adds a filter to the end of the audit event filter chain.

Parameters: aFilter the additional filter

addListener

public void addListener(AuditListener aListener)
Add the listener that will be used to receive events from the audit.

Parameters: aListener the nosy thing

destroy

public void destroy()
Cleans up the object. *

finishLocalSetup

public void finishLocalSetup()
{@inheritDoc}

fireAuditFinished

protected void fireAuditFinished()
notify all listeners about the audit end

fireAuditStarted

protected void fireAuditStarted()
notify all listeners about the audit start

fireErrors

public void fireErrors(String aFileName, LocalizedMessage[] aErrors)
notify all listeners about the errors in a file.

Parameters: aFileName the audited file aErrors the audit errors from the file

fireFileFinished

public void fireFileFinished(String aFileName)
Notify all listeners about the end of a file audit.

Parameters: aFileName the audited file

fireFileStarted

public void fireFileStarted(String aFileName)
Notify all listeners about the beginning of a file audit.

Parameters: aFileName the file to be audited

getBasedir

public final String getBasedir()

Returns: the base directory property used in unit-test.

normalize

public String normalize(String aPath)
"normalize" the given absolute path.

This includes:

Parameters: aPath a path for "normalizing"

Returns: "normalized" file name

Throws: java.lang.NullPointerException if the file path is equal to null.

process

public int process(File[] aFiles)
Processes a set of files with all FileSetChecks. Once this is done, it is highly recommended to call for the destroy method to close and remove the listeners.

Parameters: aFiles the list of files to be audited.

Returns: the total number of errors found

See Also: destroy

removeFilter

public void removeFilter(Filter aFilter)
Removes filter.

Parameters: aFilter filter to remove.

removeListener

public void removeListener(AuditListener aListener)
Removes a given listener.

Parameters: aListener a listener to remove

setBasedir

public void setBasedir(String aBasedir)

Parameters: aBasedir the base directory to strip off in filenames

setClassloader

public final void setClassloader(ClassLoader aLoader)
Sets the classloader that is used to contextualize filesetchecks. Some Check implementations will use that classloader to improve the quality of their reports, e.g. to load a class and then analyze it via reflection.

Parameters: aLoader the new classloader

setLocaleCountry

public void setLocaleCountry(String aLocaleCountry)

Parameters: aLocaleCountry the country to report messages *

setLocaleLanguage

public void setLocaleLanguage(String aLocaleLanguage)

Parameters: aLocaleLanguage the language to report messages *

setModuleFactory

public void setModuleFactory(ModuleFactory aModuleFactory)
Sets the factory for creating submodules.

Parameters: aModuleFactory the factory for creating FileSetChecks

setSeverity

public final void setSeverity(String aSeverity)
Sets the severity level. The string should be one of the names defined in the SeverityLevel class.

Parameters: aSeverity The new severity level

See Also: SeverityLevel

setupChild

protected void setupChild(Configuration aChildConf)
Instantiates, configures and registers a child AbstractFilter or FileSetCheck that is specified in the provided configuration.

Parameters: aChildConf {@inheritDoc}

Throws: CheckstyleException {@inheritDoc}

See Also: AutomaticBean