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 class
Helper class encapsulating the command line options and positional parameters. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Pattern
This regexp is used to extract the first sentence from the text. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Don't create instance of this class, use themain(String[])
method instead. -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
formatHtmlElement
(StringBuilder builder, DetailNode node) Concatenates the HTML text from AST of a JavadocTokenTypes.HTML_ELEMENT.private static void
formatInlineCodeTag
(StringBuilder builder, DetailNode inlineTag) Converts inline code tag into HTML form.private static DetailAST
getClassBody
(DetailAST top) Finds the class body of the first class in the DetailAST.private static String
Extracts the first sentence as HTML formatted text from the comment of an DetailAST.private static String
Extracts the first sentence as HTML formatted text from a DetailNode.private static String
Extracts the name of an ast.private static boolean
Checks that the DetailAST is apublic
static
final
int
field.private static void
iteratePublicStaticIntFields
(DetailAST objBlock, Consumer<String> consumer) Walks over the type members and push the first javadoc sentence of everypublic
static
int
field to the consumer.static void
TokenTypes.properties generator entry point.private static void
Creates 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 everypublic
static
int
field 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;
null
otherwise
-
isPublicStaticFinalIntField
Checks that the DetailAST is apublic
static
final
int
field.- Parameters:
ast
- to process- Returns:
true
if matches;false
otherwise
-
getName
Extracts the name of an ast.- Parameters:
ast
- to extract the name- Returns:
- the text content of the inner
TokenTypes.IDENT
node
-
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_BEGIN
node ornull
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
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
-
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
-