com.puppycrawl.tools.checkstyle.api
Class AbstractFileSetCheck

java.lang.Object
  extended by com.puppycrawl.tools.checkstyle.api.AutomaticBean
      extended by com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
          extended by com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
All Implemented Interfaces:
Configurable, Contextualizable, FileSetCheck
Direct Known Subclasses:
TreeWalker

public abstract class AbstractFileSetCheck
extends AbstractViolationReporter
implements FileSetCheck

Provides common functionality for many FileSetChecks.

Author:
lkuehne

Constructor Summary
AbstractFileSetCheck()
           
 
Method Summary
 void destroy()
          Cleans up the object.
protected  File[] filter(File[] aFiles)
          Determines the set of files this FileSetCheck is interested in.
protected  void fireErrors(String aFileName)
          Notify all listeners about the errors in a file.
 String getCharset()
           
protected  LocalizedMessages getMessageCollector()
          Returns the collector for violation messages.
protected  MessageDispatcher getMessageDispatcher()
          A message dispatcher is used to fire violation messages to interested audit listeners.
protected  void log(int aLineNo, int aColNo, String aKey, Object[] aArgs)
          Adds a violation message to the message collector.
protected  void log(int aLine, String aKey, Object[] aArgs)
          Adds a violation message to the message collector.
 void setCharset(String aCharset)
          Sets a named charset.
 void setFileExtensions(String[] aExtensions)
          Sets the file extensions that identify the files that pass the filter of this FileSetCheck.
 void setMessageDispatcher(MessageDispatcher aDispatcher)
          Sets the MessageDispatcher that is used to dispatch error messages to AuditListeners during processing.
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, setSeverity
 
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
 
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.FileSetCheck
process
 
Methods inherited from interface com.puppycrawl.tools.checkstyle.api.Configurable
configure
 
Methods inherited from interface com.puppycrawl.tools.checkstyle.api.Contextualizable
contextualize
 

Constructor Detail

AbstractFileSetCheck

public AbstractFileSetCheck()
Method Detail

destroy

public void destroy()
Description copied from interface: FileSetCheck
Cleans up the object.

Specified by:
destroy in interface FileSetCheck
See Also:
FileSetCheck

getCharset

public String getCharset()
Returns:
the name of the charset

setCharset

public void setCharset(String aCharset)
                throws UnsupportedEncodingException
Sets a named charset.

Parameters:
aCharset - the name of a charset
Throws:
UnsupportedEncodingException - if aCharset is unsupported.

setMessageDispatcher

public final void setMessageDispatcher(MessageDispatcher aDispatcher)
Sets the MessageDispatcher that is used to dispatch error messages to AuditListeners during processing.

Specified by:
setMessageDispatcher in interface FileSetCheck
Parameters:
aDispatcher - the dispatcher

getMessageDispatcher

protected final MessageDispatcher getMessageDispatcher()
A message dispatcher is used to fire violation messages to interested audit listeners.

Returns:
the current MessageDispatcher.

filter

protected final File[] filter(File[] aFiles)
Determines the set of files this FileSetCheck is interested in. Returns the files that have one of the currently active file extensions. If no file extensions are active the argument array is returned.

This method can be used in the implementation of process() to filter it's argument list for interesting files.

Parameters:
aFiles - the candidates for processing
Returns:
the subset of aFiles that this FileSetCheck should process
See Also:
FileSetCheck.process(java.io.File[])

setFileExtensions

public final void setFileExtensions(String[] aExtensions)
Sets the file extensions that identify the files that pass the filter of this FileSetCheck.

Parameters:
aExtensions - the set of file extensions. A missing initial '.' character of an extension is automatically added.

getMessageCollector

protected final LocalizedMessages getMessageCollector()
Returns the collector for violation messages. Subclasses can use the collector to find out the violation messages to fire via the message dispatcher.

Returns:
the collector for localized messages.

log

protected final void log(int aLine,
                         String aKey,
                         Object[] aArgs)
Adds a violation message to the message collector. Log a message that has no column information.

Specified by:
log in class AbstractViolationReporter
Parameters:
aLine - the line number where the error was found
aKey - the message that describes the error
aArgs - the details of the message
See Also:
MessageFormat

log

protected final void log(int aLineNo,
                         int aColNo,
                         String aKey,
                         Object[] aArgs)
Adds a violation message to the message collector. Log a message that has column information.

Specified by:
log in class AbstractViolationReporter
Parameters:
aLineNo - the line number where the error was found
aColNo - the column number where the error was found
aKey - the message that describes the error
aArgs - the details of the message
See Also:
MessageFormat

fireErrors

protected final void fireErrors(String aFileName)
Notify all listeners about the errors in a file. Calls MessageDispatcher.fireErrors() with all logged errors and than clears errors' list.

Parameters:
aFileName - the audited file

Back to the Checkstyle Home Page