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:
AbstractHeaderCheck, FileLengthCheck, FileTabCharacterCheck, JavadocPackageCheck, NewlineAtEndOfFileCheck, RegexpMultilineCheck, RegexpSinglelineCheck, StrictDuplicateCodeCheck, TranslationCheck, TreeWalker, UniquePropertiesCheck

public abstract class AbstractFileSetCheck
extends AbstractViolationReporter
implements FileSetCheck

Provides common functionality for many FileSetChecks.

Author:
lkuehne, oliver

Constructor Summary
AbstractFileSetCheck()
           
 
Method Summary
 void beginProcessing(String aCharset)
          Called when about to be called to process a set of files.
 void destroy()
          Cleans up the object.
 void finishProcessing()
          Called when all the files have been processed.
protected  void fireErrors(String aFileName)
          Notify all listeners about the errors in a file.
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.
 void init()
          Initialise the instance.
 void log(int aLineNo, int aColNo, String aKey, Object... aArgs)
          Log a message that has column information.
 void log(int aLine, String aKey, Object... aArgs)
          Log a message that has no column information.
 TreeSet<LocalizedMessage> process(File aFile, List<String> aLines)
          Request to process a file.
protected abstract  void processFiltered(File aFile, List<String> aLines)
          Called to process a file that matches the specified file extensions.
 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
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, 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.Configurable
configure
 
Methods inherited from interface com.puppycrawl.tools.checkstyle.api.Contextualizable
contextualize
 

Constructor Detail

AbstractFileSetCheck

public AbstractFileSetCheck()
Method Detail

processFiltered

protected abstract void processFiltered(File aFile,
                                        List<String> aLines)
Called to process a file that matches the specified file extensions.

Parameters:
aFile - the file to be processed
aLines - an immutable list of the contents of the file.

init

public void init()
Initialise the instance. This is the time to verify that everything required to perform it job.

Specified by:
init in interface FileSetCheck

destroy

public void destroy()
Cleans up the object.

Specified by:
destroy in interface FileSetCheck

beginProcessing

public void beginProcessing(String aCharset)
Called when about to be called to process a set of files.

Specified by:
beginProcessing in interface FileSetCheck
Parameters:
aCharset - the character set used to read the files.

process

public final TreeSet<LocalizedMessage> process(File aFile,
                                               List<String> aLines)
Request to process a file. The implementation should use the supplied contents and not read the contents again. This reduces the amount of file I/O.

The file set to process might contain files that are not interesting to the FileSetCheck. Such files should be ignored, no error message should be fired for them. For example a FileSetCheck that checks java files should ignore HTML or properties files.

The method should return the set of messages to be logged.

Specified by:
process in interface FileSetCheck
Parameters:
aFile - the file to be processed
aLines - an immutable list of the contents of the file.
Returns:
the list of messages to be logged.

finishProcessing

public void finishProcessing()
Called when all the files have been processed. This is the time to perform any checks that need to be done across a set of files. In this method, the implementation is responsible for the logging of messages.

Specified by:
finishProcessing in interface FileSetCheck

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.

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

public final void log(int aLine,
                      String aKey,
                      Object... aArgs)
Description copied from class: AbstractViolationReporter
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

public final void log(int aLineNo,
                      int aColNo,
                      String aKey,
                      Object... aArgs)
Description copied from class: AbstractViolationReporter
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


Copyright © 2001-2014. All Rights Reserved.