Class AbstractJavadocCheck
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
- All Implemented Interfaces:
Configurable
,Contextualizable
- Direct Known Subclasses:
AtclauseOrderCheck
,ClassAndPropertiesSettersJavadocScraper
,JavadocBlockTagLocationCheck
,JavadocLeadingAsteriskAlignCheck
,JavadocMetadataScraper
,JavadocMissingLeadingAsteriskCheck
,JavadocMissingWhitespaceAfterAsteriskCheck
,JavadocParagraphCheck
,JavadocTagContinuationIndentationCheck
,MissingDeprecatedCheck
,NonEmptyAtclauseDescriptionCheck
,RequireEmptyLineBeforeBlockTagGroupCheck
,SingleLineJavadocCheck
,SummaryJavadocCheck
Base class for Checks that process Javadoc comments.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
The file context holder.Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ThreadLocal<AbstractJavadocCheck.FileContext>
The file context.The javadoc tokens the check is interested in.static final String
Message key of error message.static final String
Parse error while rule recognition.static final String
Message key of error message.static final String
Message key of error message.private static final ThreadLocal<Map<Integer,
JavadocDetailNodeParser.ParseStatus>> Key is the block comment node "lineNo".private boolean
This property determines if a check should log a violation upon encountering javadoc with non-tight html. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
This method determines if a check should process javadoc containing non-tight html tags.void
beginJavadocTree
(DetailNode rootAst) Called before the starting to process a tree.final void
Called before the starting to process a tree.void
destroy()
Destroy the check.void
finishJavadocTree
(DetailNode rootAst) Called after finished processing a tree.final void
finishTree
(DetailAST rootAST) Called after finished processing a tree.int[]
The configurable javadoc token set.final int[]
The configurable token set.protected DetailAST
Getter for block comment in Java language syntax tree.abstract int[]
Returns the default javadoc token types a check is interested in.final int[]
Defined final to not allow JavadocChecks to change default tokens.int[]
The javadoc tokens that this check must be registered for.final int[]
The tokens that this check must be registered for.void
init()
Initialize the check.final boolean
Defined final because all JavadocChecks require comment nodes.void
Called after all the child nodes have been process.private void
processTree
(DetailNode root) Processes JavadocAST tree notifying Check.final void
setJavadocTokens
(String... strRep) Adds a set of tokens the check is interested in.final void
setViolateExecutionOnNonTightHtml
(boolean shouldReportViolation) Setter to control when to print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules.private boolean
shouldBeProcessed
(DetailNode curNode) Checks whether the current node should be processed by the check.private void
Validates that check's required javadoc tokens are subset of default javadoc tokens.abstract void
Called to process a Javadoc token.final void
visitToken
(DetailAST blockCommentNode) Called to process a token.private void
walk
(DetailNode root) Processes a node calling Check at interested nodes.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
clearViolations, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, leaveToken, log, log, log, setFileContents, setTabWidth, setTokens
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
MSG_JAVADOC_MISSED_HTML_CLOSE
Message key of error message. Missed close HTML tag breaks structure of parse tree, so parser stops parsing and generates such error message. This case is special because parser prints error like"no viable alternative at input 'b \n *\n'"
and it is not clear that error is about missed close HTML tag.- See Also:
-
MSG_JAVADOC_WRONG_SINGLETON_TAG
Message key of error message.- See Also:
-
MSG_JAVADOC_PARSE_RULE_ERROR
Parse error while rule recognition.- See Also:
-
MSG_KEY_UNCLOSED_HTML_TAG
Message key of error message.- See Also:
-
TREE_CACHE
Key is the block comment node "lineNo". Value isDetailNode
tree. Map is stored inThreadLocal
to guarantee basic thread safety and avoid shared, mutable state when not necessary. -
context
The file context. -
javadocTokens
The javadoc tokens the check is interested in. -
violateExecutionOnNonTightHtml
This property determines if a check should log a violation upon encountering javadoc with non-tight html. The default return value for this method is set to false since checks generally tend to be fine with non-tight html. It can be set through config file if a check is to log violation upon encountering non-tight HTML in javadoc.
-
-
Constructor Details
-
AbstractJavadocCheck
public AbstractJavadocCheck()
-
-
Method Details
-
getDefaultJavadocTokens
Returns the default javadoc token types a check is interested in.- Returns:
- the default javadoc token types
- See Also:
-
visitJavadocToken
Called to process a Javadoc token.- Parameters:
ast
- the token to process
-
getAcceptableJavadocTokens
The configurable javadoc token set. Used to protect Checks against malicious users who specify an unacceptable javadoc token set in the configuration file. The default implementation returns the check's default javadoc tokens.- Returns:
- the javadoc token set this check is designed for.
- See Also:
-
getRequiredJavadocTokens
The javadoc tokens that this check must be registered for.- Returns:
- the javadoc token set this must be registered for.
- See Also:
-
acceptJavadocWithNonTightHtml
This method determines if a check should process javadoc containing non-tight html tags. This method must be overridden in checks extendingAbstractJavadocCheck
which are not supposed to process javadoc containing non-tight html tags.- Returns:
- true if the check should or can process javadoc containing non-tight html tags; false otherwise
- See Also:
-
setViolateExecutionOnNonTightHtml
Setter to control when to print violations if the Javadoc being examined by this check violates the tight html rules defined at Tight-HTML Rules.- Parameters:
shouldReportViolation
- value to which the field shall be set to- Since:
- 8.3
-
setJavadocTokens
Adds a set of tokens the check is interested in.- Parameters:
strRep
- the string representation of the tokens interested in
-
init
Description copied from class:AbstractCheck
Initialize the check. This is the time to verify that the check has everything required to perform its job.- Overrides:
init
in classAbstractCheck
-
validateDefaultJavadocTokens
Validates that check's required javadoc tokens are subset of default javadoc tokens.- Throws:
IllegalStateException
- when validation of default javadoc tokens fails
-
beginJavadocTree
Called before the starting to process a tree.- Parameters:
rootAst
- the root of the tree
-
finishJavadocTree
Called after finished processing a tree.- Parameters:
rootAst
- the root of the tree
-
leaveJavadocToken
Called after all the child nodes have been process.- Parameters:
ast
- the token leaving
-
getDefaultTokens
Defined final to not allow JavadocChecks to change default tokens.- Specified by:
getDefaultTokens
in classAbstractCheck
- Returns:
- default tokens
- See Also:
-
getAcceptableTokens
Description copied from class:AbstractCheck
The configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.- Specified by:
getAcceptableTokens
in classAbstractCheck
- Returns:
- the token set this check is designed for.
- See Also:
-
getRequiredTokens
Description copied from class:AbstractCheck
The tokens that this check must be registered for.- Specified by:
getRequiredTokens
in classAbstractCheck
- Returns:
- the token set this must be registered for.
- See Also:
-
isCommentNodesRequired
Defined final because all JavadocChecks require comment nodes.- Overrides:
isCommentNodesRequired
in classAbstractCheck
- Returns:
- true
-
beginTree
Description copied from class:AbstractCheck
Called before the starting to process a tree. Ideal place to initialize information that is to be collected whilst processing a tree.- Overrides:
beginTree
in classAbstractCheck
- Parameters:
rootAST
- the root of the tree
-
finishTree
Description copied from class:AbstractCheck
Called after finished processing a tree. Ideal place to report on information collected whilst processing a tree.- Overrides:
finishTree
in classAbstractCheck
- Parameters:
rootAST
- the root of the tree
-
visitToken
Description copied from class:AbstractCheck
Called to process a token.- Overrides:
visitToken
in classAbstractCheck
- Parameters:
blockCommentNode
- the token to process
-
getBlockCommentAst
Getter for block comment in Java language syntax tree.- Returns:
- A block comment in the syntax tree.
-
processTree
Processes JavadocAST tree notifying Check.- Parameters:
root
- root of JavadocAST tree.
-
walk
Processes a node calling Check at interested nodes.- Parameters:
root
- the root of tree for process
-
shouldBeProcessed
Checks whether the current node should be processed by the check.- Parameters:
curNode
- current node.- Returns:
- true if the current node should be processed by the check.
-
destroy
Description copied from class:AbstractCheck
Destroy the check. It is being retired from service.- Overrides:
destroy
in classAbstractCheck
-