Class MultiFileRegexpHeaderCheck
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.MultiFileRegexpHeaderCheck
- All Implemented Interfaces:
Configurable,Contextualizable,ExternalResourceHolder,FileSetCheck
public class MultiFileRegexpHeaderCheck
extends AbstractFileSetCheck
implements ExternalResourceHolder
Checks the header of a source file against multiple header files that contain a
pattern for each line of the source header.
- Since:
- 10.24.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classMetadata holder for a header file, storing its URI, compiled patterns, and line contents.private static final classRepresents the result of a header match check, containing information about any mismatch.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.private StringSpecify a comma-separated list of files containing the required headers.private final List<MultiFileRegexpHeaderCheck.HeaderFileMetadata>List of metadata objects for each configured header file, containing patterns and line contents.static final intConstant indicating that no header line mismatch was found.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. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static MultiFileRegexpHeaderCheck.MatchResultcreateMismatchResult(MultiFileRegexpHeaderCheck.HeaderFileMetadata headerFile, FileText fileText, int mismatchLine) Creates a MatchResult for a mismatch case.Returns a comma-separated string of all configured header file paths.Returns a set of external configuration resource locations which are used by the module.Reads all lines from the specified header file URI.private static MultiFileRegexpHeaderCheck.MatchResultmatchHeader(FileText fileText, MultiFileRegexpHeaderCheck.HeaderFileMetadata headerFile) Analyzes if the file text matches the header file patterns and generates a detailed result.protected voidprocessFiltered(File file, FileText fileText) Called to process a file that matches the specified file extensions.voidsetHeaderFiles(String... headerFiles) Setter to specify a comma-separated list of files containing the required headers.Methods 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
finishLocalSetup, 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
-
MISMATCH_CODE
Constant indicating that no header line mismatch was found.- See Also:
-
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. -
headerFilesMetadata
List of metadata objects for each configured header file, containing patterns and line contents. -
headerFiles
Specify a comma-separated list of files containing the required headers. If a file's header matches none, the violation references the first file in this list. Users can order files to set a preferred header for such reporting.
-
-
Constructor Details
-
MultiFileRegexpHeaderCheck
public MultiFileRegexpHeaderCheck()
-
-
Method Details
-
setHeaderFiles
Setter to specify a comma-separated list of files containing the required headers. If a file's header matches none, the violation references the first file in this list. Users can order files to set a preferred header for such reporting.- Parameters:
headerFiles- comma-separated list of header files- Throws:
IllegalArgumentException- if headerFiles is null or empty- Since:
- 10.24.0
-
getConfiguredHeaderPaths
Returns a comma-separated string of all configured header file paths.- Returns:
- A comma-separated string of all configured header file paths, or an empty string if no header files are configured or none have valid paths.
-
getExternalResourceLocations
Description copied from interface:ExternalResourceHolderReturns a set of external configuration resource locations which are used by the module. ATTENTION! If 'getExternalResourceLocations()' return null, there will beNullPointerExceptioninChecker. Such behaviour will signal that your module (check or filter) is designed incorrectly. It makes sense to return an empty set from 'getExternalResourceLocations()' only for composite modules likeTreeWalker.- Specified by:
getExternalResourceLocationsin interfaceExternalResourceHolder- Returns:
- a set of external configuration resource locations which are used by the module.
-
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.
-
matchHeader
private static MultiFileRegexpHeaderCheck.MatchResult matchHeader(FileText fileText, MultiFileRegexpHeaderCheck.HeaderFileMetadata headerFile) Analyzes if the file text matches the header file patterns and generates a detailed result.- Parameters:
fileText- the text of the file being checkedheaderFile- the header file metadata to check against- Returns:
- a MatchResult containing the result of the analysis
-
createMismatchResult
private static MultiFileRegexpHeaderCheck.MatchResult createMismatchResult(MultiFileRegexpHeaderCheck.HeaderFileMetadata headerFile, FileText fileText, int mismatchLine) Creates a MatchResult for a mismatch case.- Parameters:
headerFile- the header file metadatafileText- the text of the file being checkedmismatchLine- the line number of the mismatch (0-based)- Returns:
- a MatchResult representing the mismatch
-
getLines
Reads all lines from the specified header file URI.- Parameters:
headerFile- path to the header file (for error messages)uri- URI of the header file- Returns:
- list of lines read from the header file
- Throws:
IllegalArgumentException- if the file cannot be read or is empty
-