public class JavadocMetadataScraper extends AbstractJavadocCheck
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
private static java.util.regex.Pattern |
DEFAULT_VALUE_TAG
Regular expression for property default value location in class-level javadocs.
|
private static java.util.regex.Pattern |
DESC_CLEAN
Regular expression for removal of @code{-} present at the beginning of texts.
|
private static java.util.regex.Pattern |
EXAMPLES_TAG
Regular expression for check example location in class-level javadocs.
|
private int |
exampleSectionStartIdx
Child number of the example section node, where parent is the class level javadoc root
node.
|
private static java.util.regex.Pattern |
FILE_SEPARATOR_PATTERN
Regular expression for file separator corresponding to the host OS.
|
private static java.lang.String |
JAVA_FILE_EXTENSION
Java file extension.
|
private static java.util.Map<java.lang.String,ModuleDetails> |
MODULE_DETAILS_STORE
Module details store used for testing.
|
private ModuleDetails |
moduleDetails
ModuleDetails instance for each module AST traversal.
|
static java.lang.String |
MSG_DESC_MISSING
A key is pointing to the warning message text in "messages.properties"
file.
|
private static java.util.regex.Pattern |
PARENT_TAG
Regular expression for module parent location in class-level javadocs.
|
private int |
parentSectionStartIdx
Child number of the parent section node, where parent is the class level javadoc root
node.
|
private static java.lang.String |
PROP_DEFAULT_VALUE_MISSING
Format for exception message for missing default value for check property.
|
private static java.lang.String |
PROP_TYPE_MISSING
Format for exception message for missing type for check property.
|
private static java.util.Set<java.lang.String> |
PROPERTIES_TO_NOT_WRITE
This set contains faulty property default value which should not be written to the XML
metadata files.
|
private static java.util.regex.Pattern |
PROPERTY_TAG
Regular expression for property location in class-level javadocs.
|
private int |
propertySectionStartIdx
Child number of the property section node, where parent is the class level javadoc root
node.
|
private static java.util.regex.Pattern |
QUOTE_PATTERN
Regular expression for quotes.
|
private DetailNode |
rootNode
DetailNode pointing to the root node of the class level javadoc of the class.
|
private boolean |
scrapingViolationMessageList
Boolean variable which lets us know whether violation message section is being scraped
currently.
|
private static java.util.regex.Pattern |
TOKEN_TEXT_PATTERN
Regular expression for detecting ANTLR tokens(for e.g.
|
private boolean |
toScan
Boolean variable which lets us know whether we should scan and scrape the current javadoc
or not.
|
private static java.util.regex.Pattern |
TYPE_TAG
Regular expression for property type location in class-level javadocs.
|
private static java.util.regex.Pattern |
VALIDATION_TYPE_TAG
Regular expression for property validation type location in class-level javadocs.
|
private static java.util.regex.Pattern |
VIOLATION_MESSAGES_TAG
Regular expression for module violation messages location in class-level javadocs.
|
private boolean |
writeXmlOutput
Control whether to write XML output or not.
|
MSG_JAVADOC_MISSED_HTML_CLOSE, MSG_JAVADOC_PARSE_RULE_ERROR, MSG_JAVADOC_WRONG_SINGLETON_TAG| Constructor and Description |
|---|
JavadocMetadataScraper() |
| Modifier and Type | Method and Description |
|---|---|
void |
beginJavadocTree(DetailNode rootAst)
Called before the starting to process a tree.
|
private static java.lang.String |
cleanDefaultTokensText(java.lang.String initialText)
Clean up the default token text by removing hyperlinks, and only keeping token type text.
|
private static java.lang.String |
constructSubTreeText(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 ModulePropertyDetails |
createProperties(DetailNode nodeLi)
Create the modulePropertyDetails content.
|
void |
finishJavadocTree(DetailNode rootAst)
Called after finished processing a tree.
|
int[] |
getDefaultJavadocTokens()
Returns the default javadoc token types a check is interested in.
|
private java.lang.String |
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 of
propertySectionStartIdx,
exampleSectionStartIdx and parentSectionStartIdx. |
private static java.util.Optional<DetailNode> |
getFirstChildOfMatchingText(DetailNode node,
java.util.regex.Pattern pattern)
Get first child of parent node matching the provided pattern.
|
private static java.util.Optional<DetailNode> |
getFirstChildOfType(DetailNode node,
int tokenType,
int offset)
Returns the first child node which matches the provided
TokenType and has the
children index after the offset value. |
static java.util.Map<java.lang.String,ModuleDetails> |
getModuleDetailsStore()
Getter method for
moduleDetailsStore. |
private java.lang.String |
getModuleSimpleName()
Extract simple file name from the whole file path name.
|
private ModuleType |
getModuleType()
Get module type(check/filter/filefilter) based on file name.
|
private static java.lang.String |
getPackageName(java.lang.String filePath)
Retrieve package name of module from the absolute file path.
|
private static DetailAST |
getParent(DetailAST commentBlock)
Returns parent node, removing modifier/annotation nodes.
|
private static int |
getParentIndexOf(DetailNode node)
Traverse parents until we reach the root node (@code{JavadocTokenTypes.JAVADOC})
child and return its index.
|
private static java.lang.String |
getParentText(DetailNode nodeParagraph)
Get module parent text from paragraph javadoc node.
|
private static java.lang.String |
getPropertyDefaultText(DetailNode nodeLi,
DetailNode defaultValueNode)
Create property default text, which is either normal property value or list of tokens.
|
int[] |
getRequiredJavadocTokens()
The javadoc tokens that this check must be registered for.
|
private static java.lang.String |
getTagTextFromProperty(DetailNode nodeLi,
DetailNode propertyMeta)
Get tag text from property data.
|
private static java.lang.String |
getText(DetailNode parentNode)
Get joined text from all text children nodes.
|
private static java.lang.String |
getTextFromTag(DetailNode nodeTag)
Get text from
JavadocTokenTypes.JAVADOC_INLINE_TAG. |
private static java.lang.String |
getViolationMessages(DetailNode nodeLi)
Get the violation message text for a specific key from the list item.
|
private static boolean |
isChildNodeTextMatches(DetailNode ast,
java.util.regex.Pattern pattern)
Checks whether the first child
JavadocTokenType.TEXT node matches given pattern. |
private static boolean |
isExamplesText(DetailNode ast)
Checks whether the paragraph node corresponds to the example section.
|
private static boolean |
isParentText(DetailNode nodeParagraph)
Checks whether the
JavadocTokenType.PARAGRAPH node is referring to the parent
javadoc segment. |
private static boolean |
isPropertyList(DetailNode nodeLi)
Checks whether the list item node is part of a property list.
|
private boolean |
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.
|
private static boolean |
isViolationMessagesText(DetailNode nodeParagraph)
Checks whether the
JavadocTokenType.PARAGRAPH node is referring to the violation
message keys javadoc segment. |
static void |
resetModuleDetailsStore()
Reset the module detail store of any previous information.
|
private void |
scrapeContent(DetailNode ast)
Method containing the core logic of scraping.
|
void |
setWriteXmlOutput(boolean writeXmlOutput)
Setter to control whether to write XML output or not.
|
void |
visitJavadocToken(DetailNode ast)
Called to process a Javadoc token.
|
acceptJavadocWithNonTightHtml, beginTree, destroy, finishTree, getAcceptableJavadocTokens, getAcceptableTokens, getBlockCommentAst, getDefaultTokens, getRequiredTokens, init, isCommentNodesRequired, leaveJavadocToken, setJavadocTokens, setViolateExecutionOnNonTightHtml, visitTokenclearViolations, getFileContents, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final java.lang.String MSG_DESC_MISSING
private static final java.util.Map<java.lang.String,ModuleDetails> MODULE_DETAILS_STORE
private static final java.util.regex.Pattern PROPERTY_TAG
private static final java.util.regex.Pattern TYPE_TAG
private static final java.util.regex.Pattern VALIDATION_TYPE_TAG
private static final java.util.regex.Pattern DEFAULT_VALUE_TAG
private static final java.util.regex.Pattern EXAMPLES_TAG
private static final java.util.regex.Pattern PARENT_TAG
private static final java.util.regex.Pattern VIOLATION_MESSAGES_TAG
private static final java.util.regex.Pattern TOKEN_TEXT_PATTERN
private static final java.util.regex.Pattern DESC_CLEAN
private static final java.util.regex.Pattern FILE_SEPARATOR_PATTERN
private static final java.util.regex.Pattern QUOTE_PATTERN
private static final java.lang.String JAVA_FILE_EXTENSION
private static final java.util.Set<java.lang.String> PROPERTIES_TO_NOT_WRITE
private static final java.lang.String PROP_TYPE_MISSING
private static final java.lang.String PROP_DEFAULT_VALUE_MISSING
private ModuleDetails moduleDetails
private boolean scrapingViolationMessageList
private boolean toScan
JavadocTokenTypes.SINCE_LITERAL.private DetailNode rootNode
private int propertySectionStartIdx
private int exampleSectionStartIdx
private int parentSectionStartIdx
private boolean writeXmlOutput
public JavadocMetadataScraper()
public final void setWriteXmlOutput(boolean writeXmlOutput)
writeXmlOutput - whether to write XML output or not.public int[] getDefaultJavadocTokens()
AbstractJavadocCheckgetDefaultJavadocTokens in class AbstractJavadocCheckJavadocTokenTypespublic int[] getRequiredJavadocTokens()
AbstractJavadocCheckgetRequiredJavadocTokens in class AbstractJavadocCheckJavadocTokenTypespublic void beginJavadocTree(DetailNode rootAst)
AbstractJavadocCheckbeginJavadocTree in class AbstractJavadocCheckrootAst - the root of the treepublic void visitJavadocToken(DetailNode ast)
AbstractJavadocCheckvisitJavadocToken in class AbstractJavadocCheckast - the token to processpublic void finishJavadocTree(DetailNode rootAst)
AbstractJavadocCheckfinishJavadocTree in class AbstractJavadocCheckrootAst - the root of the treeprivate void scrapeContent(DetailNode ast)
ast - javadoc astprivate static ModulePropertyDetails createProperties(DetailNode nodeLi)
nodeLi - list item javadoc nodeprivate static java.lang.String getTagTextFromProperty(DetailNode nodeLi, DetailNode propertyMeta)
nodeLi - javadoc li item nodepropertyMeta - property javadoc nodeprivate static java.lang.String cleanDefaultTokensText(java.lang.String initialText)
initialText - unclean textprivate static java.lang.String constructSubTreeText(DetailNode node, int childLeftLimit, int childRightLimit)
node - root node of subtreechildLeftLimit - the left index of root children from where to scanchildRightLimit - the right index of root children till where to scanprivate java.lang.String getDescriptionText()
propertySectionStartIdx,
exampleSectionStartIdx and parentSectionStartIdx.private static java.lang.String getPropertyDefaultText(DetailNode nodeLi, DetailNode defaultValueNode)
nodeLi - list item javadoc nodedefaultValueNode - default value nodeprivate static java.lang.String getViolationMessages(DetailNode nodeLi)
nodeLi - list item javadoc nodeprivate static java.lang.String getTextFromTag(DetailNode nodeTag)
JavadocTokenTypes.JAVADOC_INLINE_TAG.nodeTag - target javadoc tagprivate static java.util.Optional<DetailNode> getFirstChildOfType(DetailNode node, int tokenType, int offset)
TokenType and has the
children index after the offset value.node - parent nodetokenType - token type to matchoffset - children array index offsetprivate static java.lang.String getText(DetailNode parentNode)
parentNode - parent nodeprivate static java.util.Optional<DetailNode> getFirstChildOfMatchingText(DetailNode node, java.util.regex.Pattern pattern)
node - parent nodepattern - pattern to match againstprivate static DetailAST getParent(DetailAST commentBlock)
commentBlock - child node.private static int getParentIndexOf(DetailNode node)
node - subtree child nodeprivate static java.lang.String getParentText(DetailNode nodeParagraph)
nodeParagraph - paragraph javadoc nodeprivate ModuleType getModuleType()
private java.lang.String getModuleSimpleName()
private static java.lang.String getPackageName(java.lang.String filePath)
filePath - absolute file pathpublic static java.util.Map<java.lang.String,ModuleDetails> getModuleDetailsStore()
moduleDetailsStore.public static void resetModuleDetailsStore()
private boolean isTopLevelClassJavadoc()
private static boolean isExamplesText(DetailNode ast)
ast - javadoc paragraph nodeprivate static boolean isPropertyList(DetailNode nodeLi)
nodeLi - JavadocTokenType.LI nodeprivate static boolean isViolationMessagesText(DetailNode nodeParagraph)
JavadocTokenType.PARAGRAPH node is referring to the violation
message keys javadoc segment.nodeParagraph - paragraph javadoc nodeprivate static boolean isParentText(DetailNode nodeParagraph)
JavadocTokenType.PARAGRAPH node is referring to the parent
javadoc segment.nodeParagraph - paragraph javadoc nodeprivate static boolean isChildNodeTextMatches(DetailNode ast, java.util.regex.Pattern pattern)
JavadocTokenType.TEXT node matches given pattern.ast - parent javadoc nodepattern - pattern to matchCopyright © 2001-2022. All Rights Reserved.