Class MultiFileRegexpHeaderCheck

All Implemented Interfaces:
Configurable, Contextualizable, ExternalResourceHolder, FileSetCheck

Checks the header of a source file against multiple header files that contain a pattern for each line of the source header.
  • Property fileExtensions - Specify the file extensions of the files to process. Type is java.lang.String[]. Default value is "".
  • Property 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. Type is java.lang.String. Default value is null.

Parent is com.puppycrawl.tools.checkstyle.Checker

Violation Message Keys:

  • multi.file.regexp.header.mismatch
  • multi.file.regexp.header.missing
Since:
10.24.0
  • Field Details

  • Constructor Details

  • Method Details

    • setHeaderFiles

      public void setHeaderFiles(String... headerFiles)
      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: ExternalResourceHolder
      Returns a set of external configuration resource locations which are used by the module. ATTENTION! If 'getExternalResourceLocations()' return null, there will be NullPointerException in Checker. 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 like TreeWalker.
      Specified by:
      getExternalResourceLocations in interface ExternalResourceHolder
      Returns:
      a set of external configuration resource locations which are used by the module.
    • processFiltered

      protected void processFiltered(File file, FileText fileText)
      Description copied from class: AbstractFileSetCheck
      Called to process a file that matches the specified file extensions.
      Specified by:
      processFiltered in class AbstractFileSetCheck
      Parameters:
      file - the file to be processed
      fileText - the contents of the file.
    • matchHeader

      Analyzes if the file text matches the header file patterns and generates a detailed result.
      Parameters:
      fileText - the text of the file being checked
      headerFile - the header file metadata to check against
      Returns:
      a MatchResult containing the result of the analysis
    • createMismatchResult

      Creates a MatchResult for a mismatch case.
      Parameters:
      headerFile - the header file metadata
      fileText - the text of the file being checked
      mismatchLine - the line number of the mismatch (0-based)
      Returns:
      a MatchResult representing the mismatch
    • getLines

      public static List<String> getLines(String headerFile, URI uri)
      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