Class 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 is java.lang.String. Default value is the 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 is java.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 is java.lang.String. Default value is null.
  • Property headerFile - Specify the name of the file containing the required header. Type is java.net.URI. Default value is null.
  • Property multiLines - Specify the line numbers to repeat (zero or more times). Type is int[]. Default value is "".

Parent is com.puppycrawl.tools.checkstyle.Checker

Violation Message Keys:

  • header.mismatch
  • header.missing
Since:
6.9
  • Field Details

  • Constructor Details

  • Method Details

    • setMultiLines

      public void setMultiLines(int... list)
      Setter to specify the line numbers to repeat (zero or more times).
      Parameters:
      list - line numbers to repeat in header.
      Since:
      3.4
    • 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.
    • getHeaderLine

      private String getHeaderLine(int headerLineNo)
      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

      private void logFirstSinglelineLine(int startHeaderLine, int headerSize)
      Logs warning if any non-multiline lines left in header regexp.
      Parameters:
      startHeaderLine - header line number to start from
      headerSize - whole header size
    • isMatch

      private boolean isMatch(String line, int headerLineNo)
      Checks if a code line matches the required header line.
      Parameters:
      line - the code line
      headerLineNo - the header line number.
      Returns:
      true if and only if the line matches the required header line.
    • isMultiLine

      private boolean isMultiLine(int lineNo)
      Returns true if line is multiline header lines or false.
      Parameters:
      lineNo - a line number
      Returns:
      if lineNo is one of the repeat header lines.
    • postProcessHeaderLines

      protected void postProcessHeaderLines()
      Description copied from class: AbstractHeaderCheck
      Hook method for post-processing header lines. This implementation does nothing.
      Specified by:
      postProcessHeaderLines in class AbstractHeaderCheck
    • setHeader

      public void setHeader(String header)
      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:
      setHeader in class AbstractHeaderCheck
      Parameters:
      header - the header value to validate and set (in that order)
      Since:
      5.0