Class AbstractFileSetCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
-
- All Implemented Interfaces:
Configurable,Contextualizable,FileSetCheck
- Direct Known Subclasses:
AbstractHeaderCheck,FileLengthCheck,FileTabCharacterCheck,JavadocPackageCheck,NewlineAtEndOfFileCheck,RegexpMultilineCheck,RegexpOnFilenameCheck,RegexpSinglelineCheck,TranslationCheck,TreeWalker,UniquePropertiesCheck
public abstract class AbstractFileSetCheck extends AbstractViolationReporter implements FileSetCheck
Provides common functionality for many FileSetChecks.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
AutomaticBean.OutputStreamOptions
-
-
Constructor Summary
Constructors Constructor Description AbstractFileSetCheck()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static voidaddMessages(java.util.SortedSet<LocalizedMessage> messages)Adds the sorted set ofLocalizedMessageto the message collector.voidbeginProcessing(java.lang.String charset)Called when about to be called to process a set of files.voiddestroy()Cleans up the object.voidfinishProcessing()Called when all the files have been processed.protected voidfireErrors(java.lang.String fileName)Notify all listeners about the errors in a file.java.lang.String[]getFileExtensions()Makes copy of file extensions and returns them.protected MessageDispatchergetMessageDispatcher()A message dispatcher is used to fire violation messages to interested audit listeners.voidinit()Initialise the instance.voidlog(int lineNo, int colNo, java.lang.String key, java.lang.Object... args)Log a message that has column information.voidlog(int line, java.lang.String key, java.lang.Object... args)Log a message that has no column information.java.util.SortedSet<LocalizedMessage>process(java.io.File file, FileText fileText)Request to process a file.protected abstract voidprocessFiltered(java.io.File file, FileText fileText)Called to process a file that matches the specified file extensions.voidsetFileExtensions(java.lang.String... extensions)Sets the file extensions that identify the files that pass the filter of this FileSetCheck.voidsetMessageDispatcher(MessageDispatcher messageDispatcher)Sets the MessageDispatcher that is used to dispatch error messages to AuditListeners during processing.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, 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
-
-
-
-
Method Detail
-
processFiltered
protected abstract void processFiltered(java.io.File file, FileText fileText) throws CheckstyleExceptionCalled to process a file that matches the specified file extensions.- Parameters:
file- the file to be processedfileText- the contents of the file.- Throws:
CheckstyleException- if error condition within Checkstyle occurs.
-
init
public void init()
Description copied from interface:FileSetCheckInitialise the instance. This is the time to verify that everything required to perform it job.- Specified by:
initin interfaceFileSetCheck
-
destroy
public void destroy()
Description copied from interface:FileSetCheckCleans up the object.- Specified by:
destroyin interfaceFileSetCheck
-
beginProcessing
public void beginProcessing(java.lang.String charset)
Description copied from interface:FileSetCheckCalled when about to be called to process a set of files.- Specified by:
beginProcessingin interfaceFileSetCheck- Parameters:
charset- the character set used to read the files.
-
process
public final java.util.SortedSet<LocalizedMessage> process(java.io.File file, FileText fileText) throws CheckstyleException
Description copied from interface:FileSetCheckRequest 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:
processin interfaceFileSetCheck- Parameters:
file- the file to be processedfileText- the contents of the file.- Returns:
- the sorted set of messages to be logged.
- Throws:
CheckstyleException- if error condition within Checkstyle occurs
-
finishProcessing
public void finishProcessing()
Description copied from interface:FileSetCheckCalled 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:
finishProcessingin interfaceFileSetCheck
-
setMessageDispatcher
public final void setMessageDispatcher(MessageDispatcher messageDispatcher)
Description copied from interface:FileSetCheckSets the MessageDispatcher that is used to dispatch error messages to AuditListeners during processing.- Specified by:
setMessageDispatcherin interfaceFileSetCheck- Parameters:
messageDispatcher- the dispatcher
-
getMessageDispatcher
protected final MessageDispatcher getMessageDispatcher()
A message dispatcher is used to fire violation messages to interested audit listeners.- Returns:
- the current MessageDispatcher.
-
getFileExtensions
public java.lang.String[] getFileExtensions()
Makes copy of file extensions and returns them.- Returns:
- file extensions that identify the files that pass the filter of this FileSetCheck.
-
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.- Throws:
java.lang.IllegalArgumentException- is argument is null
-
addMessages
protected static void addMessages(java.util.SortedSet<LocalizedMessage> messages)
Adds the sorted set ofLocalizedMessageto the message collector.- Parameters:
messages- the sorted set ofLocalizedMessage.
-
log
public final void log(int line, java.lang.String key, java.lang.Object... args)Description copied from class:AbstractViolationReporterLog a message that has no column information.- Specified by:
login classAbstractViolationReporter- Parameters:
line- the line number where the error was foundkey- the message that describes the errorargs- the details of the message- See Also:
MessageFormat
-
log
public final void log(int lineNo, int colNo, java.lang.String key, java.lang.Object... args)Description copied from class:AbstractViolationReporterLog a message that has column information.- Specified by:
login classAbstractViolationReporter- Parameters:
lineNo- the line number where the error was foundcolNo- the column number where the error was foundkey- the message that describes the errorargs- the details of the message- See Also:
MessageFormat
-
fireErrors
protected final void fireErrors(java.lang.String fileName)
Notify all listeners about the errors in a file. CallsMessageDispatcher.fireErrors()with all logged errors and than clears errors' list.- Parameters:
fileName- the audited file
-
-