Class RegexpHeaderCheck
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
com.puppycrawl.tools.checkstyle.checks.header.AbstractHeaderCheck
com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheck
- All Implemented Interfaces:
Configurable,Contextualizable,ExternalResourceHolder,FileSetCheck
Checks the header of a source file against a header that contains a
pattern for each line of the source header.
-
Property
charset- Specify the character encoding to use when reading the headerFile. Type isjava.lang.String. Default value isthe charset property of the parent <a href="https://checkstyle.org/config.html#Checker">Checker</a> module. -
Property
fileExtensions- Specify the file extensions of the files to process. Type isjava.lang.String[]. Default value is"". -
Property
header- Define the required header specified inline. Individual header lines must be separated by the string"\n"(even on platforms with a different line separator). For header lines containing"\n\n"checkstyle will forcefully expect an empty line to exist. See examples below. Regular expressions must not span multiple lines. Type isjava.lang.String. Default value isnull. -
Property
headerFile- Specify the name of the file containing the required header. Type isjava.net.URI. Default value isnull. -
Property
multiLines- Specify the line numbers to repeat (zero or more times). Type isint[]. Default value is"".
Parent is com.puppycrawl.tools.checkstyle.Checker
Violation Message Keys:
-
header.mismatch -
header.missing
- Since:
- 3.2
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final PatternCompiled regex pattern for a blank line.private static final StringRegex pattern for a blank line.The compiled regular expressions.static final StringA key is pointing to the warning message text in "messages.properties" file.static final StringA key is pointing to the warning message text in "messages.properties" file.private BitSetSpecify the line numbers to repeat (zero or more times). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate StringgetHeaderLine(int headerLineNo) Returns the line from the header.private booleanChecks if a code line matches the required header line.private booleanisMultiLine(int lineNo) Returns true if line is multiline header lines or false.private voidlogFirstSinglelineLine(int startHeaderLine, int headerSize) Logs warning if any non-multiline lines left in header regexp.protected voidHook method for post-processing header lines.protected voidprocessFiltered(File file, FileText fileText) Called to process a file that matches the specified file extensions.voidSetter to define the required header specified inline.voidsetMultiLines(int... list) Setter to specify the line numbers to repeat (zero or more times).Methods inherited from class com.puppycrawl.tools.checkstyle.checks.header.AbstractHeaderCheck
finishLocalSetup, getExternalResourceLocations, getHeaderLines, setCharset, setHeaderFileMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck
addViolations, beginProcessing, destroy, finishProcessing, fireErrors, getFileContents, getFileExtensions, getMessageDispatcher, getTabWidth, getViolations, init, log, log, process, setFileContents, setFileExtensions, setMessageDispatcher, setTabWidthMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChildMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.puppycrawl.tools.checkstyle.api.Configurable
configureMethods inherited from interface com.puppycrawl.tools.checkstyle.api.Contextualizable
contextualize
-
Field Details
-
MSG_HEADER_MISSING
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
MSG_HEADER_MISMATCH
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
EMPTY_LINE_PATTERN
Regex pattern for a blank line.- See Also:
-
BLANK_LINE
Compiled regex pattern for a blank line. -
headerRegexps
The compiled regular expressions. -
multiLines
Specify the line numbers to repeat (zero or more times).
-
-
Constructor Details
-
RegexpHeaderCheck
public RegexpHeaderCheck()
-
-
Method Details
-
setMultiLines
Setter to specify the line numbers to repeat (zero or more times).- Parameters:
list- line numbers to repeat in header.- Since:
- 3.4
-
processFiltered
Description copied from class:AbstractFileSetCheckCalled to process a file that matches the specified file extensions.- Specified by:
processFilteredin classAbstractFileSetCheck- Parameters:
file- the file to be processedfileText- the contents of the file.
-
getHeaderLine
Returns the line from the header. Where the line is blank return the regexp pattern for a blank line.- Parameters:
headerLineNo- header line number to return- Returns:
- the line from the header
-
logFirstSinglelineLine
Logs warning if any non-multiline lines left in header regexp.- Parameters:
startHeaderLine- header line number to start fromheaderSize- whole header size
-
isMatch
Checks if a code line matches the required header line.- Parameters:
line- the code lineheaderLineNo- the header line number.- Returns:
- true if and only if the line matches the required header line.
-
isMultiLine
Returns true if line is multiline header lines or false.- Parameters:
lineNo- a line number- Returns:
- if
lineNois one of the repeat header lines.
-
postProcessHeaderLines
Description copied from class:AbstractHeaderCheckHook method for post-processing header lines. This implementation does nothing.- Specified by:
postProcessHeaderLinesin classAbstractHeaderCheck
-
setHeader
Setter to define the required header specified inline. Individual header lines must be separated by the string"\n"(even on platforms with a different line separator). For header lines containing"\n\n"checkstyle will forcefully expect an empty line to exist. See examples below. Regular expressions must not span multiple lines.- Overrides:
setHeaderin classAbstractHeaderCheck- Parameters:
header- the header value to validate and set (in that order)- Since:
- 5.0
-