Class JavadocDetailNodeParser

    • Method Detail

      • createJavadocParser

        private static com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocParser createJavadocParser​(String blockComment,
                                                                                                         JavadocDetailNodeParser.DescriptiveErrorListener errorListener)
        Parses block comment content as javadoc comment.
        Parameters:
        blockComment - block comment content.
        errorListener - custom error listener
        Returns:
        parse tree
      • convertParseTreeToDetailNode

        private DetailNode convertParseTreeToDetailNode​(org.antlr.v4.runtime.tree.ParseTree parseTreeNode)
        Converts ParseTree (that is generated by ANTLRv4) to DetailNode tree.
        Parameters:
        parseTreeNode - root node of ParseTree
        Returns:
        root of DetailNode tree
      • insertChildrenNodes

        private void insertChildrenNodes​(JavadocNodeImpl[] nodes,
                                         org.antlr.v4.runtime.tree.ParseTree parseTreeParent)
        Creates child nodes for each node from 'nodes' array.
        Parameters:
        nodes - array of JavadocNodeImpl nodes
        parseTreeParent - original ParseTree parent node
      • createChildrenNodes

        private JavadocNodeImpl[] createChildrenNodes​(DetailNode parentJavadocNode,
                                                      org.antlr.v4.runtime.tree.ParseTree parseTreeNode)
        Creates children Javadoc nodes base on ParseTree node's children.
        Parameters:
        parentJavadocNode - node that will be parent for created children
        parseTreeNode - original ParseTree node
        Returns:
        array of Javadoc nodes
      • createRootJavadocNode

        private JavadocNodeImpl createRootJavadocNode​(org.antlr.v4.runtime.tree.ParseTree parseTreeNode)
        Creates root JavadocNodeImpl node base on ParseTree root node.
        Parameters:
        parseTreeNode - ParseTree root node
        Returns:
        root Javadoc node
      • createJavadocNode

        private JavadocNodeImpl createJavadocNode​(org.antlr.v4.runtime.tree.ParseTree parseTree,
                                                  DetailNode parent,
                                                  int index)
        Creates JavadocNodeImpl node on base of ParseTree node.
        Parameters:
        parseTree - ParseTree node
        parent - DetailNode that will be parent of new node
        index - child index that has new node
        Returns:
        JavadocNodeImpl node on base of ParseTree node.
      • adjustFirstLineToJavadocIndent

        private void adjustFirstLineToJavadocIndent​(DetailNode tree,
                                                    int javadocColumnNumber)
        Adjust first line nodes to javadoc indent.
        Parameters:
        tree - DetailNode tree root
        javadocColumnNumber - javadoc indent
      • getLine

        private static int getLine​(org.antlr.v4.runtime.tree.ParseTree tree)
        Gets line number from ParseTree node.
        Parameters:
        tree - ParseTree node
        Returns:
        line number
      • getColumn

        private static int getColumn​(org.antlr.v4.runtime.tree.ParseTree tree)
        Gets column number from ParseTree node.
        Parameters:
        tree - ParseTree node
        Returns:
        column number
      • getNextSibling

        private static org.antlr.v4.runtime.tree.ParseTree getNextSibling​(org.antlr.v4.runtime.tree.ParseTree node)
        Gets next sibling of ParseTree node.
        Parameters:
        node - ParseTree node
        Returns:
        next sibling of ParseTree node.
      • getTokenType

        private static int getTokenType​(org.antlr.v4.runtime.tree.ParseTree node)
        Gets token type of ParseTree node from JavadocTokenTypes class.
        Parameters:
        node - ParseTree node.
        Returns:
        token type from JavadocTokenTypes
      • getFormattedNodeClassNameWithoutContext

        private static String getFormattedNodeClassNameWithoutContext​(org.antlr.v4.runtime.tree.ParseTree node)
        Gets class name of ParseTree node and removes 'Context' postfix at the end and formats it.
        Parameters:
        node - ParseTree node whose class name is to be formatted and returned
        Returns:
        uppercased class name without the word 'Context' and with appropriately inserted underscores
      • getNodeClassNameWithoutContext

        private static String getNodeClassNameWithoutContext​(org.antlr.v4.runtime.tree.ParseTree node)
        Gets class name of ParseTree node and removes 'Context' postfix at the end.
        Parameters:
        node - ParseTree node.
        Returns:
        class name without 'Context'
      • getMissedHtmlTag

        private static org.antlr.v4.runtime.Token getMissedHtmlTag​(org.antlr.v4.runtime.RecognitionException exception)
        Method to get the missed HTML tag to generate more informative error message for the user. This method doesn't concern itself with void elements since it is forbidden to close them. Missed HTML tags for the following tags will not generate an error message from ANTLR: <p> <li> <tr> <td> <th> <body> <colgroup> <dd> <dt> <head> <html> <option> <tbody> <thead> <tfoot>
        Parameters:
        exception - NoViableAltException object catched while parsing javadoc
        Returns:
        returns appropriate Token if a HTML close tag is missed; null otherwise
      • getFirstNonTightHtmlTag

        private static org.antlr.v4.runtime.Token getFirstNonTightHtmlTag​(com.puppycrawl.tools.checkstyle.grammar.javadoc.JavadocParser javadocParser,
                                                                          int javadocLineOffset)
        This method is used to get the first non-tight HTML tag encountered while parsing javadoc. This shall eventually be reflected by the JavadocDetailNodeParser.ParseStatus object returned by parseJavadocAsDetailNode(DetailAST) method via the instance member JavadocDetailNodeParser.ParseStatus.firstNonTightHtmlTag, and checks not supposed to process non-tight HTML or the ones which are supposed to log violation for non-tight javadocs can utilize that.
        Parameters:
        javadocParser - The ANTLR recognizer instance which has been used to parse the javadoc
        javadocLineOffset - The line number of beginning of the Javadoc comment
        Returns:
        First non-tight HTML tag if one exists; null otherwise
      • convertUpperCamelToUpperUnderscore

        private static String convertUpperCamelToUpperUnderscore​(String text)
        Converts the given text from camel case to all upper case with underscores separating each word.
        Parameters:
        text - The string to convert.
        Returns:
        The result of the conversion.