Class AbstractFileSetCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
-
- 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
,LineLengthCheck
,NewlineAtEndOfFileCheck
,OrderedPropertiesCheck
,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 Modifier and Type Class Description private static class
AbstractFileSetCheck.FileContext
The actual context holder.-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description private ThreadLocal<AbstractFileSetCheck.FileContext>
context
The check context.private static String
EXTENSION_SEPARATOR
The extension separator.private String[]
fileExtensions
Specify the file extensions of the files to process.private MessageDispatcher
messageDispatcher
The dispatcher errors are fired to.private int
tabWidth
The tab width for column reporting.
-
Constructor Summary
Constructors Constructor Description AbstractFileSetCheck()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addViolations(SortedSet<Violation> violations)
Adds the sorted set ofViolation
to the message collector.void
beginProcessing(String charset)
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 fileName)
Notify all listeners about the errors in a file.protected FileContents
getFileContents()
Returns the file contents associated with the file.String[]
getFileExtensions()
Makes copy of file extensions and returns them.protected MessageDispatcher
getMessageDispatcher()
A message dispatcher is used to fire violations to interested audit listeners.protected int
getTabWidth()
Get tab width to report audit events with.SortedSet<Violation>
getViolations()
Returns the sorted set ofViolation
.void
init()
Initialise the instance.void
log(int lineNo, int colNo, String key, Object... args)
Log a message that has column information.void
log(int line, String key, Object... args)
Log a message that has no column information.SortedSet<Violation>
process(File file, FileText fileText)
Request to process a file.protected abstract void
processFiltered(File file, FileText fileText)
Called to process a file that matches the specified file extensions.void
setFileContents(FileContents contents)
Set the file contents associated with the tree.void
setFileExtensions(String... extensions)
Setter to specify the file extensions of the files to process.void
setMessageDispatcher(MessageDispatcher messageDispatcher)
Sets the MessageDispatcher that is used to dispatch audit events to AuditListeners during processing.void
setTabWidth(int tabWidth)
Set the tab width to report audit events with.-
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.AbstractAutomaticBean
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
-
-
-
-
Field Detail
-
EXTENSION_SEPARATOR
private static final String EXTENSION_SEPARATOR
The extension separator.- See Also:
- Constant Field Values
-
context
private final ThreadLocal<AbstractFileSetCheck.FileContext> context
The check context.
-
messageDispatcher
private MessageDispatcher messageDispatcher
The dispatcher errors are fired to.
-
fileExtensions
private String[] fileExtensions
Specify the file extensions of the files to process. Default is uninitialized as the value is inherited from the parent module.
-
tabWidth
private int tabWidth
The tab width for column reporting. Default is uninitialized as the value is inherited from the parent module.
-
-
Constructor Detail
-
AbstractFileSetCheck
public AbstractFileSetCheck()
-
-
Method Detail
-
processFiltered
protected abstract void processFiltered(File file, FileText fileText) throws CheckstyleException
Called 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:FileSetCheck
Initialise the instance. This is the time to verify that everything required to perform its job.- Specified by:
init
in interfaceFileSetCheck
-
destroy
public void destroy()
Description copied from interface:FileSetCheck
Cleans up the object.- Specified by:
destroy
in interfaceFileSetCheck
-
beginProcessing
public void beginProcessing(String charset)
Description copied from interface:FileSetCheck
Called when about to be called to process a set of files.- Specified by:
beginProcessing
in interfaceFileSetCheck
- Parameters:
charset
- the character set used to read the files.
-
process
public final SortedSet<Violation> process(File file, FileText fileText) throws CheckstyleException
Description copied from interface:FileSetCheck
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 audit event 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 violations to be logged.
- Specified by:
process
in interfaceFileSetCheck
- Parameters:
file
- the file to be processedfileText
- the contents of the file.- Returns:
- the sorted set of violations to be logged.
- Throws:
CheckstyleException
- if error condition within Checkstyle occurs
-
finishProcessing
public void finishProcessing()
Description copied from interface:FileSetCheck
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 violations.- Specified by:
finishProcessing
in interfaceFileSetCheck
-
setMessageDispatcher
public final void setMessageDispatcher(MessageDispatcher messageDispatcher)
Description copied from interface:FileSetCheck
Sets the MessageDispatcher that is used to dispatch audit events to AuditListeners during processing.- Specified by:
setMessageDispatcher
in interfaceFileSetCheck
- Parameters:
messageDispatcher
- the dispatcher
-
getMessageDispatcher
protected final MessageDispatcher getMessageDispatcher()
A message dispatcher is used to fire violations to interested audit listeners.- Returns:
- the current MessageDispatcher.
-
getViolations
public SortedSet<Violation> getViolations()
Returns the sorted set ofViolation
.- Returns:
- the sorted set of
Violation
.
-
setFileContents
public final void setFileContents(FileContents contents)
Set the file contents associated with the tree.- Parameters:
contents
- the manager
-
getFileContents
protected final FileContents getFileContents()
Returns the file contents associated with the file.- Returns:
- the file contents
-
getFileExtensions
public 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(String... extensions)
Setter to specify the file extensions of the files to process.- Parameters:
extensions
- the set of file extensions. A missing initial '.' character of an extension is automatically added.- Throws:
IllegalArgumentException
- is argument is null
-
getTabWidth
protected final int getTabWidth()
Get tab width to report audit events with.- Returns:
- the tab width to report audit events with
-
setTabWidth
public final void setTabWidth(int tabWidth)
Set the tab width to report audit events with.- Parameters:
tabWidth
- anint
value
-
addViolations
protected void addViolations(SortedSet<Violation> violations)
Adds the sorted set ofViolation
to the message collector.- Parameters:
violations
- the sorted set ofViolation
.
-
log
public final void log(int line, String key, Object... args)
Description copied from class:AbstractViolationReporter
Log a message that has no column information.- Specified by:
log
in classAbstractViolationReporter
- Parameters:
line
- the line number where the audit event was foundkey
- the message that describes the audit eventargs
- the details of the message- See Also:
MessageFormat
-
log
public final void log(int lineNo, int colNo, String key, Object... args)
Description copied from class:AbstractViolationReporter
Log a message that has column information.- Specified by:
log
in classAbstractViolationReporter
- Parameters:
lineNo
- the line number where the audit event was foundcolNo
- the column number where the audit event was foundkey
- the message that describes the audit eventargs
- the details of the message- See Also:
MessageFormat
-
fireErrors
protected final void fireErrors(String fileName)
Notify all listeners about the errors in a file. CallsMessageDispatcher.fireErrors()
with all logged errors and then clears errors' list.- Parameters:
fileName
- the audited file
-
-