Package com.puppycrawl.tools.checkstyle
Class JavadocPropertiesGenerator
java.lang.Object
com.puppycrawl.tools.checkstyle.JavadocPropertiesGenerator
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classHelper class encapsulating the command line options and positional parameters. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final PatternThis regexp is used to extract the first sentence from the text. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDon't create instance of this class, use themain(String[])method instead. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidformatHtmlElement(StringBuilder builder, DetailNode node) Concatenates the HTML text from AST of a JavadocTokenTypes.HTML_ELEMENT.private static voidformatInlineCodeTag(StringBuilder builder, DetailNode inlineTag) Converts inline code tag into HTML form.private static DetailASTgetClassBody(DetailAST top) Finds the class body of the first class in the DetailAST.private static StringExtracts the first sentence as HTML formatted text from the comment of an DetailAST.private static StringExtracts the first sentence as HTML formatted text from a DetailNode.private static StringExtracts the name of an ast.private static booleanChecks that the DetailAST is apublicstaticfinalintfield.private static voiditeratePublicStaticIntFields(DetailAST objBlock, Consumer<String> consumer) Walks over the type members and push the first javadoc sentence of everypublicstaticintfield to the consumer.static voidTokenTypes.properties generator entry point.private static voidCreates the .properties file from a .java file.
-
Field Details
-
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.
-
-
Constructor Details
-
JavadocPropertiesGenerator
private JavadocPropertiesGenerator()Don't create instance of this class, use themain(String[])method instead.
-
-
Method Details
-
main
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
-
writePropertiesFile
private static void writePropertiesFile(JavadocPropertiesGenerator.CliOptions options) throws CheckstyleException Creates the .properties file from a .java file.- Parameters:
options- the user-specified options- Throws:
CheckstyleException- if a javadoc comment can not be parsed
-
iteratePublicStaticIntFields
private static void iteratePublicStaticIntFields(DetailAST objBlock, Consumer<String> consumer) throws CheckstyleException Walks over the type members and push the first javadoc sentence of everypublicstaticintfield to the consumer.- Parameters:
objBlock- the OBJBLOCK of a class to iterate over its membersconsumer- first javadoc sentence consumer- Throws:
CheckstyleException- if failed to parse a javadoc comment
-
getClassBody
Finds the class body of the first class in the DetailAST.- Parameters:
top- AST to find the class body- Returns:
- OBJBLOCK token if found;
nullotherwise
-
isPublicStaticFinalIntField
Checks that the DetailAST is apublicstaticfinalintfield.- Parameters:
ast- to process- Returns:
trueif matches;falseotherwise
-
getName
Extracts the name of an ast.- Parameters:
ast- to extract the name- Returns:
- the text content of the inner
TokenTypes.IDENTnode
-
getFirstJavadocSentence
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_BEGINnode ornullif 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
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
nullif 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
-
formatInlineCodeTag
private static void formatInlineCodeTag(StringBuilder builder, DetailNode inlineTag) throws CheckstyleException Converts inline code tag into HTML form.- Parameters:
builder- to appendinlineTag- to format- Throws:
CheckstyleException- if the inline javadoc tag is not a literal nor a code tag
-
formatHtmlElement
Concatenates the HTML text from AST of a JavadocTokenTypes.HTML_ELEMENT.- Parameters:
builder- to appendnode- to format
-