Class JavadocPropertiesGenerator


  • public final class JavadocPropertiesGenerator
    extends Object
    This class is used internally in the build process to write a property file with short descriptions (the first sentences) of TokenTypes constants. Request: 724871 For IDE plugins (like the eclipse plugin) it would be useful to have programmatic access to the first sentence of the TokenType constants, so they can use them in their configuration gui.
    • Field Detail

      • END_OF_SENTENCE_PATTERN

        private static final Pattern END_OF_SENTENCE_PATTERN
        This regexp is used to extract the first sentence from the text. The end of the sentence is determined by the symbol "period", "exclamation mark" or "question mark", followed by a space or the end of the text.
    • Method Detail

      • main

        public static void main​(String... args)
                         throws CheckstyleException
        TokenTypes.properties generator entry point.
        Parameters:
        args - the command line arguments
        Throws:
        CheckstyleException - if parser or lexer failed or if there is an IO problem
      • iteratePublicStaticIntFields

        private static void iteratePublicStaticIntFields​(DetailAST objBlock,
                                                         Consumer<String> consumer)
                                                  throws CheckstyleException
        Walks over the type members and push the first javadoc sentence of every public static int field to the consumer.
        Parameters:
        objBlock - the OBJBLOCK of a class to iterate over its members
        consumer - first javadoc sentence consumer
        Throws:
        CheckstyleException - if failed to parse a javadoc comment
      • getClassBody

        private static DetailAST getClassBody​(DetailAST top)
        Finds the class body of the first class in the DetailAST.
        Parameters:
        top - AST to find the class body
        Returns:
        OBJBLOCK token if found; null otherwise
      • isPublicStaticFinalIntField

        private static boolean isPublicStaticFinalIntField​(DetailAST ast)
        Checks that the DetailAST is a public static final int field.
        Parameters:
        ast - to process
        Returns:
        true if matches; false otherwise
      • getName

        private static String getName​(DetailAST ast)
        Extracts the name of an ast.
        Parameters:
        ast - to extract the name
        Returns:
        the text content of the inner TokenTypes.IDENT node
      • getFirstJavadocSentence

        private static String getFirstJavadocSentence​(DetailAST ast)
                                               throws CheckstyleException
        Extracts the first sentence as HTML formatted text from the comment of an DetailAST. The end of the sentence is determined by the symbol "period", "exclamation mark" or "question mark", followed by a space or the end of the text. Inline tags @code and @literal are converted to HTML code.
        Parameters:
        ast - to extract the first sentence
        Returns:
        the first sentence of the inner TokenTypes.BLOCK_COMMENT_BEGIN node or null if the first sentence is absent or malformed (does not end with period)
        Throws:
        CheckstyleException - if a javadoc comment can not be parsed or an unsupported inline tag found
      • getFirstJavadocSentence

        private static String getFirstJavadocSentence​(DetailNode tree)
                                               throws CheckstyleException
        Extracts the first sentence as HTML formatted text from a DetailNode. The end of the sentence is determined by the symbol "period", "exclamation mark" or "question mark", followed by a space or the end of the text. Inline tags @code and @literal are converted to HTML code.
        Parameters:
        tree - to extract the first sentence
        Returns:
        the first sentence of the node or null if the first sentence is absent or malformed (does not end with any of the end-of-sentence markers)
        Throws:
        CheckstyleException - if an unsupported inline tag found
      • formatHtmlElement

        private static void formatHtmlElement​(StringBuilder builder,
                                              DetailNode node)
        Concatenates the HTML text from AST of a JavadocTokenTypes.HTML_ELEMENT.
        Parameters:
        builder - to append
        node - to format