Class JavadocMetadataScraper
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractCheck
com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
com.puppycrawl.tools.checkstyle.meta.JavadocMetadataScraper
- All Implemented Interfaces:
Configurable,Contextualizable
Class for scraping module metadata from the corresponding class' class-level javadoc.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final PatternRegular expression for property default value location in class-level javadocs.private static final PatternRegular expression for removal of @code{-} present at the beginning of texts.private static final PatternRegular expression for check example location in class-level javadocs.private intChild number of the example section node, where parent is the class level javadoc root node.private static final PatternRegular expression for file separator corresponding to the host OS.private static final StringJava file extension.private static final Map<String,ModuleDetails> Module details store used for testing.private ModuleDetailsModuleDetails instance for each module AST traversal.static final StringA key is pointing to the warning message text in "messages.properties" file.private static final PatternRegular expression for module parent location in class-level javadocs.private intChild number of the parent section node, where parent is the class level javadoc root node.private static final StringFormat for exception message for missing default value for check property.private static final StringFormat for exception message for missing type for check property.This set contains faulty property default value which should not be written to the XML metadata files.private static final PatternRegular expression for property location in class-level javadocs.private intChild number of the property section node, where parent is the class level javadoc root node.private static final PatternRegular expression for quotes.private DetailNodeDetailNode pointing to the root node of the class level javadoc of the class.private booleanBoolean variable which lets us know whether violation message section is being scraped currently.private static final PatternRegular expression for detecting ANTLR tokens(for e.g.private booleanBoolean variable which lets us know whether we should scan and scrape the current javadoc or not.private static final PatternRegular expression for property type location in class-level javadocs.private static final PatternRegular expression for property validation type location in class-level javadocs.private static final PatternRegular expression for module violation messages location in class-level javadocs.private booleanControl whether to write XML output or not.Fields inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
MSG_JAVADOC_MISSED_HTML_CLOSE, MSG_JAVADOC_PARSE_RULE_ERROR, MSG_JAVADOC_WRONG_SINGLETON_TAG, MSG_KEY_UNCLOSED_HTML_TAG -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringadjustCodeInlineTagChildToHtml(DetailNode codeChild) Adjusts child of@codeJavadoc inline tag to html format.voidbeginJavadocTree(DetailNode rootAst) Called before the starting to process a tree.private static StringcleanDefaultTokensText(String initialText) Clean up the default token text by removing hyperlinks, and only keeping token type text.static StringconstructSubTreeText(DetailNode node, int childLeftLimit, int childRightLimit) Performs a DFS of the subtree with a node as the root and constructs the text of that tree, ignoring JavadocToken texts.private static ModulePropertyDetailscreateProperties(DetailNode nodeLi) Create the modulePropertyDetails content.voidfinishJavadocTree(DetailNode rootAst) Called after finished processing a tree.int[]Returns the default javadoc token types a check is interested in.private StringCreate the description text with starting index as 0 and ending index would be the first valid non-zero index amongst in the order ofpropertySectionStartIdx,exampleSectionStartIdxandparentSectionStartIdx.private static Optional<DetailNode>getFirstChildOfMatchingText(DetailNode node, Pattern pattern) Get first child of parent node matching the provided pattern.private static Optional<DetailNode>getFirstChildOfType(DetailNode node, int tokenType, int offset) Returns the first child node which matches the providedTokenTypeand has the children index after the offset value.static Map<String,ModuleDetails> Getter method formoduleDetailsStore.private StringExtract simple file name from the whole file path name.private ModuleTypeGet module type(check/filter/filefilter) based on file name.private static StringgetPackageName(String filePath) Retrieve package name of module from the absolute file path.private static DetailASTReturns parent node, removing modifier/annotation nodes.static intgetParentIndexOf(DetailNode node) Traverse parents until we reach the root node (@code{JavadocTokenTypes.JAVADOC}) child and return its index.private static StringgetParentText(DetailNode nodeParagraph) Get module parent text from paragraph javadoc node.private static StringgetPropertyDefaultText(DetailNode nodeLi, DetailNode defaultValueNode) Create property default text, which is either normal property value or list of tokens.int[]The javadoc tokens that this check must be registered for.private static StringgetTagTextFromProperty(DetailNode nodeLi, DetailNode propertyMeta) Get tag text from property data.private static StringgetText(DetailNode parentNode) Get joined text from all text children nodes.private static StringgetTextFromTag(DetailNode nodeTag) Get text fromJavadocTokenTypes.JAVADOC_INLINE_TAG.private static StringgetViolationMessages(DetailNode nodeLi) Get the violation message text for a specific key from the list item.private static booleanisChildNodeTextMatches(DetailNode ast, Pattern pattern) Checks whether the first childJavadocTokenType.TEXTnode matches given pattern.private static booleanisContentToWrite(DetailNode detailNode) Checks whether selected Javadoc node is considered as something to write.private static booleanisExamplesText(DetailNode ast) Checks whether the paragraph node corresponds to the example section.static booleanisParentText(DetailNode nodeParagraph) Checks whether theJavadocTokenType.PARAGRAPHnode is referring to the parent javadoc segment.private static booleanisPropertyList(DetailNode nodeLi) Checks whether the list item node is part of a property list.private booleanCheck if the current javadoc block comment AST corresponds to the top-level class as we only want to scrape top-level class javadoc.private static booleanisViolationMessagesText(DetailNode nodeParagraph) Checks whether theJavadocTokenType.PARAGRAPHnode is referring to the violation message keys javadoc segment.static voidReset the module detail store of any previous information.private voidscrapeContent(DetailNode ast) Method containing the core logic of scraping.final voidsetWriteXmlOutput(boolean writeXmlOutput) Setter to control whether to write XML output or not.voidCalled to process a Javadoc token.Methods inherited from class com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck
acceptJavadocWithNonTightHtml, beginTree, destroy, finishTree, getAcceptableJavadocTokens, getAcceptableTokens, getBlockCommentAst, getDefaultTokens, getRequiredTokens, init, isCommentNodesRequired, leaveJavadocToken, setJavadocTokens, setViolateExecutionOnNonTightHtml, visitTokenMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
MSG_DESC_MISSING
A key is pointing to the warning message text in "messages.properties" file.- See Also:
-
MODULE_DETAILS_STORE
Module details store used for testing. -
PROPERTY_TAG
Regular expression for property location in class-level javadocs. -
TYPE_TAG
Regular expression for property type location in class-level javadocs. -
VALIDATION_TYPE_TAG
Regular expression for property validation type location in class-level javadocs. -
DEFAULT_VALUE_TAG
Regular expression for property default value location in class-level javadocs. -
EXAMPLES_TAG
Regular expression for check example location in class-level javadocs. -
PARENT_TAG
Regular expression for module parent location in class-level javadocs. -
VIOLATION_MESSAGES_TAG
Regular expression for module violation messages location in class-level javadocs. -
TOKEN_TEXT_PATTERN
Regular expression for detecting ANTLR tokens(for e.g. CLASS_DEF). -
DESC_CLEAN
Regular expression for removal of @code{-} present at the beginning of texts. -
FILE_SEPARATOR_PATTERN
Regular expression for file separator corresponding to the host OS. -
QUOTE_PATTERN
Regular expression for quotes. -
JAVA_FILE_EXTENSION
Java file extension.- See Also:
-
PROPERTIES_TO_NOT_WRITE
This set contains faulty property default value which should not be written to the XML metadata files. -
PROP_TYPE_MISSING
Format for exception message for missing type for check property.- See Also:
-
PROP_DEFAULT_VALUE_MISSING
Format for exception message for missing default value for check property.- See Also:
-
moduleDetails
ModuleDetails instance for each module AST traversal. -
scrapingViolationMessageList
Boolean variable which lets us know whether violation message section is being scraped currently. -
toScan
Boolean variable which lets us know whether we should scan and scrape the current javadoc or not. Since we need only class level javadoc, it becomes true at its root and false after encounteringJavadocTokenTypes.SINCE_LITERAL. -
rootNode
DetailNode pointing to the root node of the class level javadoc of the class. -
propertySectionStartIdx
Child number of the property section node, where parent is the class level javadoc root node. -
exampleSectionStartIdx
Child number of the example section node, where parent is the class level javadoc root node. -
parentSectionStartIdx
Child number of the parent section node, where parent is the class level javadoc root node. -
writeXmlOutput
Control whether to write XML output or not.
-
-
Constructor Details
-
JavadocMetadataScraper
public JavadocMetadataScraper()
-
-
Method Details
-
setWriteXmlOutput
Setter to control whether to write XML output or not.- Parameters:
writeXmlOutput- whether to write XML output or not.
-
getDefaultJavadocTokens
Description copied from class:AbstractJavadocCheckReturns the default javadoc token types a check is interested in.- Specified by:
getDefaultJavadocTokensin classAbstractJavadocCheck- Returns:
- the default javadoc token types
- See Also:
-
getRequiredJavadocTokens
Description copied from class:AbstractJavadocCheckThe javadoc tokens that this check must be registered for.- Overrides:
getRequiredJavadocTokensin classAbstractJavadocCheck- Returns:
- the javadoc token set this must be registered for.
- See Also:
-
beginJavadocTree
Description copied from class:AbstractJavadocCheckCalled before the starting to process a tree.- Overrides:
beginJavadocTreein classAbstractJavadocCheck- Parameters:
rootAst- the root of the tree
-
visitJavadocToken
Description copied from class:AbstractJavadocCheckCalled to process a Javadoc token.- Specified by:
visitJavadocTokenin classAbstractJavadocCheck- Parameters:
ast- the token to process
-
finishJavadocTree
Description copied from class:AbstractJavadocCheckCalled after finished processing a tree.- Overrides:
finishJavadocTreein classAbstractJavadocCheck- Parameters:
rootAst- the root of the tree
-
scrapeContent
Method containing the core logic of scraping. This keeps track and decides which phase of scraping we are in, and accordingly call other subroutines.- Parameters:
ast- javadoc ast
-
createProperties
Create the modulePropertyDetails content.- Parameters:
nodeLi- list item javadoc node- Returns:
- modulePropertyDetail object for the corresponding property
-
getTagTextFromProperty
Get tag text from property data.- Parameters:
nodeLi- javadoc li item nodepropertyMeta- property javadoc node- Returns:
- property metadata text
-
cleanDefaultTokensText
Clean up the default token text by removing hyperlinks, and only keeping token type text.- Parameters:
initialText- unclean text- Returns:
- clean text
-
constructSubTreeText
Performs a DFS of the subtree with a node as the root and constructs the text of that tree, ignoring JavadocToken texts.- Parameters:
node- root node of subtreechildLeftLimit- the left index of root children from where to scanchildRightLimit- the right index of root children till where to scan- Returns:
- constructed text of subtree
-
isContentToWrite
Checks whether selected Javadoc node is considered as something to write.- Parameters:
detailNode- javadoc node to check.- Returns:
- whether javadoc node is something to write.
-
adjustCodeInlineTagChildToHtml
Adjusts child of@codeJavadoc inline tag to html format.- Parameters:
codeChild-@codechild to convert.- Returns:
- converted
@codechild element, otherwise just the original text.
-
getDescriptionText
Create the description text with starting index as 0 and ending index would be the first valid non-zero index amongst in the order ofpropertySectionStartIdx,exampleSectionStartIdxandparentSectionStartIdx.- Returns:
- description text
-
getPropertyDefaultText
Create property default text, which is either normal property value or list of tokens.- Parameters:
nodeLi- list item javadoc nodedefaultValueNode- default value node- Returns:
- default property text
-
getViolationMessages
Get the violation message text for a specific key from the list item.- Parameters:
nodeLi- list item javadoc node- Returns:
- violation message key text
-
getTextFromTag
Get text fromJavadocTokenTypes.JAVADOC_INLINE_TAG.- Parameters:
nodeTag- target javadoc tag- Returns:
- text contained by the tag
-
getFirstChildOfType
Returns the first child node which matches the providedTokenTypeand has the children index after the offset value.- Parameters:
node- parent nodetokenType- token type to matchoffset- children array index offset- Returns:
- the first child satisfying the conditions
-
getText
Get joined text from all text children nodes.- Parameters:
parentNode- parent node- Returns:
- the joined text of node
-
getFirstChildOfMatchingText
Get first child of parent node matching the provided pattern.- Parameters:
node- parent nodepattern- pattern to match against- Returns:
- the first child node matching the condition
-
getParent
Returns parent node, removing modifier/annotation nodes.- Parameters:
commentBlock- child node.- Returns:
- parent node.
-
getParentIndexOf
Traverse parents until we reach the root node (@code{JavadocTokenTypes.JAVADOC}) child and return its index.- Parameters:
node- subtree child node- Returns:
- root node child index
-
getParentText
Get module parent text from paragraph javadoc node.- Parameters:
nodeParagraph- paragraph javadoc node- Returns:
- parent text
-
getModuleType
Get module type(check/filter/filefilter) based on file name.- Returns:
- module type
-
getModuleSimpleName
Extract simple file name from the whole file path name.- Returns:
- simple module name
-
getPackageName
Retrieve package name of module from the absolute file path.- Parameters:
filePath- absolute file path- Returns:
- package name
-
getModuleDetailsStore
Getter method formoduleDetailsStore.- Returns:
- map containing module details of supplied checks.
-
resetModuleDetailsStore
Reset the module detail store of any previous information. -
isTopLevelClassJavadoc
Check if the current javadoc block comment AST corresponds to the top-level class as we only want to scrape top-level class javadoc.- Returns:
- true if the current AST corresponds to top level class
-
isExamplesText
Checks whether the paragraph node corresponds to the example section.- Parameters:
ast- javadoc paragraph node- Returns:
- true if the section matches the example section marker
-
isPropertyList
Checks whether the list item node is part of a property list.- Parameters:
nodeLi-JavadocTokenType.LInode- Returns:
- true if the node is part of a property list
-
isViolationMessagesText
Checks whether theJavadocTokenType.PARAGRAPHnode is referring to the violation message keys javadoc segment.- Parameters:
nodeParagraph- paragraph javadoc node- Returns:
- true if paragraph node contains the violation message keys text
-
isParentText
Checks whether theJavadocTokenType.PARAGRAPHnode is referring to the parent javadoc segment.- Parameters:
nodeParagraph- paragraph javadoc node- Returns:
- true if paragraph node contains the parent text
-
isChildNodeTextMatches
Checks whether the first childJavadocTokenType.TEXTnode matches given pattern.- Parameters:
ast- parent javadoc nodepattern- pattern to match- Returns:
- true if one of child text nodes matches pattern
-