Class AbstractHeaderCheck

    • Field Detail

      • ESCAPED_LINE_FEED_PATTERN

        private static final java.util.regex.Pattern ESCAPED_LINE_FEED_PATTERN
        Pattern to detect occurrences of '\n' in text.
      • readerLines

        private final java.util.List<java.lang.String> readerLines
        The lines of the header file.
      • headerFile

        private java.net.URI headerFile
        Specify the name of the file containing the required header.
      • charset

        private java.nio.charset.Charset charset
        Specify the character encoding to use when reading the headerFile.
    • Method Detail

      • postProcessHeaderLines

        protected abstract void postProcessHeaderLines()
        Hook method for post-processing header lines. This implementation does nothing.
      • getHeaderLines

        protected java.util.List<java.lang.String> getHeaderLines()
        Return the header lines to check against.
        Returns:
        the header lines to check against.
      • setCharset

        public void setCharset​(java.lang.String charset)
        Setter to specify the charset to use when reading the headerFile.
        Parameters:
        charset - the charset name to use for loading the header from a file
      • setHeaderFile

        public void setHeaderFile​(java.net.URI uri)
                           throws CheckstyleException
        Setter to specify the name of the file containing the required header..
        Parameters:
        uri - the uri of the header to load.
        Throws:
        CheckstyleException - if fileName is empty.
      • checkHeaderNotInitialized

        private void checkHeaderNotInitialized()
        Called before initializing the header.
        Throws:
        java.lang.IllegalArgumentException - if header has already been set
      • createCharset

        private static java.nio.charset.Charset createCharset​(java.lang.String name)
        Creates charset by name.
        Parameters:
        name - charset name
        Returns:
        created charset
        Throws:
        java.nio.charset.UnsupportedCharsetException - if charset is unsupported
      • setHeader

        public void setHeader​(java.lang.String header)
        Set the header to check against. Individual lines in the header must be separated by '\n' characters.
        Parameters:
        header - header content to check against.
        Throws:
        java.lang.IllegalArgumentException - if the header cannot be interpreted
      • loadHeader

        private void loadHeader​(java.io.Reader headerReader)
                         throws java.io.IOException
        Load header to check against from a Reader into readerLines.
        Parameters:
        headerReader - delivers the header to check against
        Throws:
        java.io.IOException - if
      • getExternalResourceLocations

        public java.util.Set<java.lang.String> 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.