Class AbstractHeaderCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
-
- com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
-
- com.puppycrawl.tools.checkstyle.checks.header.AbstractHeaderCheck
-
- All Implemented Interfaces:
Configurable
,Contextualizable
,ExternalResourceHolder
,FileSetCheck
- Direct Known Subclasses:
HeaderCheck
,RegexpHeaderCheck
public abstract class AbstractHeaderCheck extends AbstractFileSetCheck implements ExternalResourceHolder
Abstract super class for header checks. Provides support for header and headerFile properties.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
charset
Name of a charset to use for loading the header from a file.private static java.util.regex.Pattern
ESCAPED_LINE_FEED_PATTERN
Pattern to detect occurrences of '\n' in text.private java.net.URI
headerFile
The file that contains the header to check against.private java.util.List<java.lang.String>
readerLines
The lines of the header file.
-
Constructor Summary
Constructors Constructor Description AbstractHeaderCheck()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private void
checkHeaderNotInitialized()
Called before initializing the header.protected void
finishLocalSetup()
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.java.util.Set<java.lang.String>
getExternalResourceLocations()
Returns a set of external configuration resource locations which are used by the module.protected java.util.List<java.lang.String>
getHeaderLines()
Return the header lines to check against.private void
loadHeader(java.io.Reader headerReader)
Load header to check against from a Reader into readerLines.private void
loadHeaderFile()
Load the header from a file.protected abstract void
postProcessHeaderLines()
Hook method for post processing header lines.void
setCharset(java.lang.String charset)
Set the charset to use for loading the header from a file.void
setHeader(java.lang.String header)
Set the header to check against.void
setHeaderFile(java.net.URI uri)
Set the header file to check against.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
beginProcessing, destroy, finishProcessing, fireErrors, getFileExtensions, getMessageCollector, getMessageDispatcher, init, log, log, process, processFiltered, setFileExtensions, setMessageDispatcher
-
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, 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
-
ESCAPED_LINE_FEED_PATTERN
private static final java.util.regex.Pattern ESCAPED_LINE_FEED_PATTERN
Pattern to detect occurrences of '\n' in text.
-
readerLines
private final java.util.List<java.lang.String> readerLines
The lines of the header file.
-
headerFile
private java.net.URI headerFile
The file that contains the header to check against.
-
charset
private java.lang.String charset
Name of a charset to use for loading the header from a file.
-
-
Method Detail
-
postProcessHeaderLines
protected abstract void postProcessHeaderLines()
Hook method for post processing header lines. This implementation does nothing.
-
getHeaderLines
protected java.util.List<java.lang.String> getHeaderLines()
Return the header lines to check against.- Returns:
- the header lines to check against.
-
setCharset
public void setCharset(java.lang.String charset) throws java.io.UnsupportedEncodingException
Set the charset to use for loading the header from a file.- Parameters:
charset
- the charset to use for loading the header from a file- Throws:
java.io.UnsupportedEncodingException
- if charset is unsupported
-
setHeaderFile
public void setHeaderFile(java.net.URI uri) throws CheckstyleException
Set the header file to check against.- Parameters:
uri
- the uri of the header to load.- Throws:
CheckstyleException
- if fileName is empty.
-
loadHeaderFile
private void loadHeaderFile() throws CheckstyleException
Load the header from a file.- Throws:
CheckstyleException
- if the file cannot be loaded
-
checkHeaderNotInitialized
private void checkHeaderNotInitialized()
Called before initializing the header.- Throws:
java.lang.IllegalArgumentException
- if header has already been set
-
setHeader
public void setHeader(java.lang.String header)
Set the header to check against. Individual lines in the header must be separated by '\n' characters.- Parameters:
header
- header content to check against.- Throws:
java.lang.IllegalArgumentException
- if the header cannot be interpreted
-
loadHeader
private void loadHeader(java.io.Reader headerReader) throws java.io.IOException
Load header to check against from a Reader into readerLines.- Parameters:
headerReader
- delivers the header to check against- Throws:
java.io.IOException
- if
-
finishLocalSetup
protected final void finishLocalSetup() throws CheckstyleException
Description copied from class:AutomaticBean
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.The default implementation does nothing.
- Overrides:
finishLocalSetup
in classAutomaticBean
- Throws:
CheckstyleException
- if there is a configuration error.
-
getExternalResourceLocations
public java.util.Set<java.lang.String> getExternalResourceLocations()
Description copied from interface:ExternalResourceHolder
Returns a set of external configuration resource locations which are used by the module. ATTENTION! If 'getExternalResourceLocations()' return null, there will beNullPointerException
inChecker
. Such behaviour will signal that your module (check or filter) is designed incorrectly. It make sense to return an empty set from 'getExternalResourceLocations()' only for composite modules likeTreeWalker
.- Specified by:
getExternalResourceLocations
in interfaceExternalResourceHolder
- Returns:
- a set of external configuration resource locations which are used by the module.
-
-