Issue #2889: Adds skipNoJavadoc option to MissingDeprecated check
This commit is contained in:
parent
e091384b4f
commit
d4791bca40
|
|
@ -70,6 +70,30 @@ import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
|
|||
* <module name="JavadocDeprecated"/>
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* In addition you can configure this check with skipNoJavadoc
|
||||
* option to allow it to ignore cases when JavaDoc is missing,
|
||||
* but still warns when JavaDoc is present but either
|
||||
* {@link Deprecated Deprecated} is missing from JavaDoc or
|
||||
* {@link Deprecated Deprecated} is missing from the element.
|
||||
* To configure this check to allow it use:
|
||||
* </p>
|
||||
*
|
||||
* <pre> <property name="skipNoJavadoc" value="true" /></pre>
|
||||
*
|
||||
* <p>Examples of validating source code with skipNoJavadoc:</p>
|
||||
*
|
||||
* <pre>
|
||||
* <code>
|
||||
* {@literal @}deprecated
|
||||
* public static final int MY_CONST = 123456; // no violation
|
||||
*
|
||||
* /** This javadoc is missing deprecated tag. */
|
||||
* {@literal @}deprecated
|
||||
* public static final int COUNTER = 10; // violation as javadoc exists
|
||||
* </code>
|
||||
* </pre>
|
||||
*
|
||||
* @author Travis Schneeberger
|
||||
*/
|
||||
public final class MissingDeprecatedCheck extends AbstractCheck {
|
||||
|
|
@ -116,6 +140,17 @@ public final class MissingDeprecatedCheck extends AbstractCheck {
|
|||
/** Multiline finished at next Javadoc. */
|
||||
private static final String NEXT_TAG = "@";
|
||||
|
||||
/** Is deprecated element valid without javadoc. */
|
||||
private boolean skipNoJavadoc;
|
||||
|
||||
/**
|
||||
* Set skipJavadoc value.
|
||||
* @param skipNoJavadoc user's value of skipJavadoc
|
||||
*/
|
||||
public void setSkipNoJavadoc(boolean skipNoJavadoc) {
|
||||
this.skipNoJavadoc = skipNoJavadoc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getDefaultTokens() {
|
||||
return getAcceptableTokens();
|
||||
|
|
@ -152,7 +187,7 @@ public final class MissingDeprecatedCheck extends AbstractCheck {
|
|||
|
||||
final boolean containsJavadocTag = containsJavadocTag(javadoc);
|
||||
|
||||
if (containsAnnotation ^ containsJavadocTag) {
|
||||
if (containsAnnotation ^ containsJavadocTag && !(skipNoJavadoc && javadoc == null)) {
|
||||
log(ast.getLineNo(), MSG_KEY_ANNOTATION_MISSING_DEPRECATED);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -169,4 +169,17 @@ public class MissingDeprecatedCheckTest extends BaseCheckTestSupport {
|
|||
|
||||
verify(checkConfig, getPath("InputMissingDeprecated2.java"), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipNoJavadocOption() throws Exception {
|
||||
final DefaultConfiguration checkConfig = createCheckConfig(MissingDeprecatedCheck.class);
|
||||
checkConfig.addAttribute("skipNoJavadoc", "true");
|
||||
|
||||
final String[] expected = {
|
||||
"10: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
|
||||
"26: " + getCheckMessage(MSG_KEY_ANNOTATION_MISSING_DEPRECATED),
|
||||
};
|
||||
|
||||
verify(checkConfig, getPath("InputMissingDeprecatedSkipNoJavadoc.java"), expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package com.puppycrawl.tools.checkstyle.checks.annotation;
|
||||
|
||||
public class InputMissingDeprecatedSkipNoJavadoc {
|
||||
@Deprecated
|
||||
public static final int MY_CONST = 123456;
|
||||
|
||||
/**
|
||||
* Useless comment.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final int MY_CONST2 = 234567;
|
||||
|
||||
/**
|
||||
* Useless comment.
|
||||
*
|
||||
* @deprecated Not for public use.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final int MY_CONST3 = 345678;
|
||||
|
||||
/**
|
||||
* Useless comment.
|
||||
*
|
||||
* @deprecated Not for public use.
|
||||
*/
|
||||
public static final int MY_CONST4 = 345678;
|
||||
}
|
||||
|
|
@ -313,9 +313,45 @@ public String getNameIfPresent() { ... }
|
|||
present and the @deprecated Javadoc tag is present when
|
||||
either is present.</p>
|
||||
</subsection>
|
||||
<subsection name="Properties">
|
||||
<table>
|
||||
<tr>
|
||||
<th>name</th>
|
||||
<th>description</th>
|
||||
<th>type</th>
|
||||
<th>default value</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>skipNoJavadoc</td>
|
||||
<td>When this property is set to true check ignore cases
|
||||
when JavaDoc is missing, but still warns when JavaDoc is
|
||||
present but either @deprecated is missing from JavaDoc or
|
||||
@deprecated is missing from the element.
|
||||
</td>
|
||||
<td><a href="property_types.html#boolean">boolean</a></td>
|
||||
<td>false</td>
|
||||
</tr>
|
||||
</table>
|
||||
</subsection>
|
||||
<subsection name="Examples">
|
||||
<p> To configure the check:</p>
|
||||
<source> <module name="MissingDeprecated"/>
|
||||
<source>
|
||||
<module name="MissingDeprecated"/>
|
||||
</source>
|
||||
<p> In addition you can configure this check with skipNoJavadoc option: </p>
|
||||
<source>
|
||||
<module name="MissingDeprecated">
|
||||
<property name="skipNoJavadoc" value="true" />
|
||||
</module>
|
||||
</source>
|
||||
<p>Examples of validating source code with skipNoJavadoc:</p>
|
||||
<source>
|
||||
@deprecated
|
||||
public static final int MY_CONST = 123456; // no violation
|
||||
|
||||
/** This javadoc is missing deprecated tag. */
|
||||
@deprecated
|
||||
public static final int COUNTER = 10; // violation as javadoc exists
|
||||
</source>
|
||||
</subsection>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue