Class AbstractJavadocCheck
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- 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
,JavadocParagraphCheck
,JavadocTagContinuationIndentationCheck
,NonEmptyAtclauseDescriptionCheck
,SingleLineJavadocCheck
,SummaryJavadocCheck
public abstract class AbstractJavadocCheck extends AbstractCheck
Base class for Checks that process Javadoc comments.
-
-
Field Summary
Fields Modifier and Type Field Description private DetailAST
blockCommentAst
DetailAST node of considered Javadoc comment that is just a block comment in Java language syntax tree.private java.util.Set<java.lang.Integer>
javadocTokens
The javadoc tokens the check is interested in.static java.lang.String
MSG_JAVADOC_MISSED_HTML_CLOSE
Message key of error message.static java.lang.String
MSG_JAVADOC_PARSE_RULE_ERROR
Parse error while rule recognition.static java.lang.String
MSG_JAVADOC_WRONG_SINGLETON_TAG
Message key of error message.static java.lang.String
MSG_KEY_PARSE_ERROR
Error message key for common javadoc errors.static java.lang.String
MSG_KEY_UNRECOGNIZED_ANTLR_ERROR
Unrecognized error from antlr parser.private JavadocDetailNodeParser
parser
Parses content of Javadoc comment as DetailNode tree.private static java.lang.ThreadLocal<java.util.Map<java.lang.String,JavadocDetailNodeParser.ParseStatus>>
TREE_CACHE
Key is "line:column".
-
Constructor Summary
Constructors Constructor Description AbstractJavadocCheck()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
beginJavadocTree(DetailNode rootAst)
Called before the starting to process a tree.void
beginTree(DetailAST rootAST)
Called before the starting to process a tree.void
finishJavadocTree(DetailNode rootAst)
Called after finished processing a tree.void
finishTree(DetailAST rootAST)
Called after finished processing a tree.int[]
getAcceptableJavadocTokens()
The configurable javadoc token set.int[]
getAcceptableTokens()
The configurable token set.protected DetailAST
getBlockCommentAst()
Getter for block comment in Java language syntax tree.abstract int[]
getDefaultJavadocTokens()
Returns the default javadoc token types a check is interested in.int[]
getDefaultTokens()
Defined final to not allow JavadocChecks to change default tokens.int[]
getRequiredJavadocTokens()
The javadoc tokens that this check must be registered for.int[]
getRequiredTokens()
The tokens that this check must be registered for.void
init()
Initialize the check.boolean
isCommentNodesRequired()
Defined final because all JavadocChecks require comment nodes.void
leaveJavadocToken(DetailNode ast)
Called after all the child nodes have been process.private void
processTree(DetailNode root)
Processes JavadocAST tree notifying Check.void
setJavadocTokens(java.lang.String... strRep)
Adds a set of tokens the check is interested in.private boolean
shouldBeProcessed(DetailNode curNode)
Checks whether the current node should be processed by the check.private void
validateDefaultJavadocTokens()
Validates that check's required javadoc tokens are subset of default javadoc tokens.abstract void
visitJavadocToken(DetailNode ast)
Called to process a Javadoc token.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
destroy, getClassLoader, getFileContents, getLine, getLines, getTabWidth, getTokenNames, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
-
-
-
-
Field Detail
-
MSG_JAVADOC_MISSED_HTML_CLOSE
public static final java.lang.String 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:
- Constant Field Values
-
MSG_JAVADOC_WRONG_SINGLETON_TAG
public static final java.lang.String MSG_JAVADOC_WRONG_SINGLETON_TAG
Message key of error message.- See Also:
- Constant Field Values
-
MSG_JAVADOC_PARSE_RULE_ERROR
public static final java.lang.String MSG_JAVADOC_PARSE_RULE_ERROR
Parse error while rule recognition.- See Also:
- Constant Field Values
-
MSG_KEY_PARSE_ERROR
public static final java.lang.String MSG_KEY_PARSE_ERROR
Error message key for common javadoc errors.- See Also:
- Constant Field Values
-
MSG_KEY_UNRECOGNIZED_ANTLR_ERROR
public static final java.lang.String MSG_KEY_UNRECOGNIZED_ANTLR_ERROR
Unrecognized error from antlr parser.- See Also:
- Constant Field Values
-
TREE_CACHE
private static final java.lang.ThreadLocal<java.util.Map<java.lang.String,JavadocDetailNodeParser.ParseStatus>> TREE_CACHE
Key is "line:column". Value isDetailNode
tree. Map is stored inThreadLocal
to guarantee basic thread safety and avoid shared, mutable state when not necessary.
-
parser
private final JavadocDetailNodeParser parser
Parses content of Javadoc comment as DetailNode tree.
-
javadocTokens
private final java.util.Set<java.lang.Integer> javadocTokens
The javadoc tokens the check is interested in.
-
blockCommentAst
private DetailAST blockCommentAst
DetailAST node of considered Javadoc comment that is just a block comment in Java language syntax tree.
-
-
Method Detail
-
getDefaultJavadocTokens
public abstract int[] getDefaultJavadocTokens()
Returns the default javadoc token types a check is interested in.- Returns:
- the default javadoc token types
- See Also:
JavadocTokenTypes
-
visitJavadocToken
public abstract void visitJavadocToken(DetailNode ast)
Called to process a Javadoc token.- Parameters:
ast
- the token to process
-
getAcceptableJavadocTokens
public int[] 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:
JavadocTokenTypes
-
getRequiredJavadocTokens
public int[] getRequiredJavadocTokens()
The javadoc tokens that this check must be registered for.- Returns:
- the javadoc token set this must be registered for.
- See Also:
JavadocTokenTypes
-
setJavadocTokens
public final void setJavadocTokens(java.lang.String... strRep)
Adds a set of tokens the check is interested in.- Parameters:
strRep
- the string representation of the tokens interested in
-
init
public void init()
Description copied from class:AbstractCheck
Initialize the check. This is the time to verify that the check has everything required to perform it job.- Overrides:
init
in classAbstractCheck
-
validateDefaultJavadocTokens
private void validateDefaultJavadocTokens()
Validates that check's required javadoc tokens are subset of default javadoc tokens.- Throws:
java.lang.IllegalStateException
- when validation of default javadoc tokens fails
-
beginJavadocTree
public void beginJavadocTree(DetailNode rootAst)
Called before the starting to process a tree.- Parameters:
rootAst
- the root of the tree
-
finishJavadocTree
public void finishJavadocTree(DetailNode rootAst)
Called after finished processing a tree.- Parameters:
rootAst
- the root of the tree
-
leaveJavadocToken
public void leaveJavadocToken(DetailNode ast)
Called after all the child nodes have been process.- Parameters:
ast
- the token leaving
-
getDefaultTokens
public final int[] getDefaultTokens()
Defined final to not allow JavadocChecks to change default tokens.- Specified by:
getDefaultTokens
in classAbstractCheck
- Returns:
- default tokens
- See Also:
TokenTypes
-
getAcceptableTokens
public final int[] 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:
TokenTypes
-
getRequiredTokens
public final int[] 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:
TokenTypes
-
isCommentNodesRequired
public final boolean isCommentNodesRequired()
Defined final because all JavadocChecks require comment nodes.- Overrides:
isCommentNodesRequired
in classAbstractCheck
- Returns:
- true
-
beginTree
public final void beginTree(DetailAST rootAST)
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
public final void finishTree(DetailAST rootAST)
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
public final void visitToken(DetailAST blockCommentNode)
Description copied from class:AbstractCheck
Called to process a token.- Overrides:
visitToken
in classAbstractCheck
- Parameters:
blockCommentNode
- the token to process
-
getBlockCommentAst
protected DetailAST getBlockCommentAst()
Getter for block comment in Java language syntax tree.- Returns:
- A block comment in the syntax tree.
-
processTree
private void processTree(DetailNode root)
Processes JavadocAST tree notifying Check.- Parameters:
root
- root of JavadocAST tree.
-
walk
private void walk(DetailNode root)
Processes a node calling Check at interested nodes.- Parameters:
root
- the root of tree for process
-
shouldBeProcessed
private boolean shouldBeProcessed(DetailNode curNode)
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.
-
-