public final class MissingDeprecatedCheck extends AbstractJavadocCheck
Verifies that the annotation @Deprecated and the Javadoc tag
@deprecated are both present when either of them is present.
Both ways of flagging deprecation serve their own purpose. The @Deprecated annotation is used for compilers and development tools. The @deprecated javadoc tag is used to document why something is deprecated and what, if any, alternatives exist.
In order to properly mark something as deprecated both forms of deprecation should be present.
Package deprecation is a exception to the rule of always using the javadoc tag and annotation to deprecate. It is not clear if the javadoc tool will support it or not as newer versions keep flip flopping on if it is supported or will cause an error. See JDK-8160601. The deprecated javadoc tag is currently the only way to say why the package is deprecated and what to use instead. Until this is resolved, if you don't want to print violations on package-info, you can use a filter to ignore these files until the javadoc tool faithfully supports it. An example config using SuppressionSingleFilter is:
<!-- required till https://bugs.openjdk.java.net/browse/JDK-8160601 -->
<module name="SuppressionSingleFilter">
<property name="checks" value="MissingDeprecatedCheck"/>
<property name="files" value="package-info\.java"/>
</module>
violateExecutionOnNonTightHtml - Control when to
print violations if the Javadoc being examined by this check violates the
tight html rules defined at
Tight-HTML Rules.
Type is boolean.
Default value is false.
To configure the check:
<module name="MissingDeprecated"/>
Example:
@Deprecated public static final int MY_CONST = 13; // ok /** This javadoc is missing deprecated tag. */ @Deprecated public static final int COUNTER = 10; // violation /** * @deprecated * <p></p> */ @Deprecated public static final int NUM = 123456; // ok /** * @deprecated * <p> */ @Deprecated public static final int CONST = 12; // ok
To configure the check such that it prints violation messages if tight HTML rules are not obeyed
<module name="MissingDeprecated"> <property name="violateExecutionOnNonTightHtml" value="true"/> </module>
Example:
@Deprecated public static final int MY_CONST = 13; // ok /** This javadoc is missing deprecated tag. */ @Deprecated public static final int COUNTER = 10; // violation /** * @deprecated * <p></p> */ @Deprecated public static final int NUM = 123456; // ok /** * @deprecated * <p> */ @Deprecated public static final int CONST = 12; // violation, tight HTML rules not obeyed
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
annotation.missing.deprecated
javadoc.duplicateTag
javadoc.missed.html.close
javadoc.parse.rule.error
javadoc.wrong.singleton.html.tag
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
DEPRECATED
Deprecated annotation name. |
private static java.lang.String |
FQ_DEPRECATED
Fully-qualified
Deprecated annotation name. |
static java.lang.String |
MSG_KEY_ANNOTATION_MISSING_DEPRECATED
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_KEY_JAVADOC_DUPLICATE_TAG
A key is pointing to the warning message text in "messages.properties"
file.
|
private static java.util.Set<java.lang.Integer> |
TYPES_HASH_SET
List of token types to find parent of.
|
MSG_JAVADOC_MISSED_HTML_CLOSE, MSG_JAVADOC_PARSE_RULE_ERROR, MSG_JAVADOC_WRONG_SINGLETON_TAG| Constructor and Description |
|---|
MissingDeprecatedCheck() |
| Modifier and Type | Method and Description |
|---|---|
private boolean |
containsDeprecatedTag(DetailNode javadoc)
Checks to see if the javadoc contains a deprecated tag.
|
int[] |
getDefaultJavadocTokens()
Returns the default javadoc token types a check is interested in.
|
private static DetailAST |
getParent(DetailAST commentBlock)
Returns the parent node of the comment.
|
int[] |
getRequiredJavadocTokens()
The javadoc tokens that this check must be registered for.
|
void |
visitJavadocToken(DetailNode ast)
Called to process a Javadoc token.
|
acceptJavadocWithNonTightHtml, beginJavadocTree, beginTree, destroy, finishJavadocTree, 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_KEY_ANNOTATION_MISSING_DEPRECATED
public static final java.lang.String MSG_KEY_JAVADOC_DUPLICATE_TAG
private static final java.lang.String DEPRECATED
Deprecated annotation name.private static final java.lang.String FQ_DEPRECATED
Deprecated annotation name.private static final java.util.Set<java.lang.Integer> TYPES_HASH_SET
public MissingDeprecatedCheck()
public int[] getDefaultJavadocTokens()
AbstractJavadocCheckgetDefaultJavadocTokens in class AbstractJavadocCheckJavadocTokenTypespublic int[] getRequiredJavadocTokens()
AbstractJavadocCheckgetRequiredJavadocTokens in class AbstractJavadocCheckJavadocTokenTypespublic void visitJavadocToken(DetailNode ast)
AbstractJavadocCheckvisitJavadocToken in class AbstractJavadocCheckast - the token to processprivate boolean containsDeprecatedTag(DetailNode javadoc)
javadoc - the javadoc of the ASTCopyright © 2001-2022. All Rights Reserved.