Package com.puppycrawl.tools.checkstyle
Class JavadocPropertiesGenerator
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
JavadocPropertiesGenerator.CliOptions
Helper class encapsulating the command line options and positional parameters.
-
Field Summary
Fields Modifier and Type Field Description private static Pattern
END_OF_SENTENCE_PATTERN
This regexp is used to extract the first sentence from the text.
-
Constructor Summary
Constructors Modifier Constructor Description private
JavadocPropertiesGenerator()
Don't create instance of this class, use themain(String[])
method instead.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private 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
getFirstJavadocSentence(DetailAST ast)
Extracts the first sentence as HTML formatted text from the comment of an DetailAST.private static String
getFirstJavadocSentence(DetailNode tree)
Extracts the first sentence as HTML formatted text from a DetailNode.private static String
getName(DetailAST ast)
Extracts the name of an ast.private static boolean
isPublicStaticFinalIntField(DetailAST ast)
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
main(String... args)
TokenTypes.properties generator entry point.private static void
writePropertiesFile(JavadocPropertiesGenerator.CliOptions options)
Creates the .properties file from a .java file.
-
-
-
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.
-
-
Constructor Detail
-
JavadocPropertiesGenerator
private JavadocPropertiesGenerator()
Don't create instance of this class, use themain(String[])
method instead.
-
-
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
-
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
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 apublic
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 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
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
-
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
private static void formatHtmlElement(StringBuilder builder, DetailNode node)
Concatenates the HTML text from AST of a JavadocTokenTypes.HTML_ELEMENT.- Parameters:
builder
- to appendnode
- to format
-
-