Class RegexpHeaderCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable, ExternalResourceHolder, FileSetCheck

    public class RegexpHeaderCheck
    extends AbstractHeaderCheck
    Checks the header of the source against a header file that contains a regular expression for each line of the source header. In default configuration, if header is not specified, the default value of header is set to null and the check does not rise any violations.
    • Field Detail

      • MSG_HEADER_MISSING

        public static final java.lang.String MSG_HEADER_MISSING
        A key is pointing to the warning message text in "messages.properties" file.
        See Also:
        Constant Field Values
      • MSG_HEADER_MISMATCH

        public static final java.lang.String MSG_HEADER_MISMATCH
        A key is pointing to the warning message text in "messages.properties" file.
        See Also:
        Constant Field Values
      • EMPTY_INT_ARRAY

        private static final int[] EMPTY_INT_ARRAY
        Empty array to avoid instantiations.
      • headerRegexps

        private final java.util.List<java.util.regex.Pattern> headerRegexps
        The compiled regular expressions.
      • multiLines

        private int[] multiLines
        The header lines to repeat (0 or more) in the check, sorted.
    • Constructor Detail

      • RegexpHeaderCheck

        public RegexpHeaderCheck()
    • Method Detail

      • setMultiLines

        public void setMultiLines​(int... list)
        Set the lines numbers to repeat in the header check.
        Parameters:
        list - comma separated list of line numbers to repeat in header.
      • processFiltered

        protected void processFiltered​(java.io.File file,
                                       java.util.List<java.lang.String> lines)
        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
        lines - an immutable list of the contents of the file.
      • 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​(java.lang.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.
      • setHeader

        public void setHeader​(java.lang.String header)
        Validates the header by compiling it with Pattern.compile(String) and throws IllegalArgumentException if header isn't a valid pattern.
        Overrides:
        setHeader in class AbstractHeaderCheck
        Parameters:
        header - the header value to validate and set (in that order)