Fix false positives in JavaDocTagContinuationIndentationCheck #323

This commit is contained in:
maxvetrenko 2014-10-22 17:32:49 +04:00 committed by Roman Ivanov
parent 7564e8ca85
commit ca34984cc3
4 changed files with 69 additions and 22 deletions

View File

@ -69,15 +69,22 @@ public class JavaDocTagContinuationIndentationCheck extends AbstractJavadocCheck
@Override
public void visitJavadocToken(DetailNode aAst)
{
final List<DetailNode> textNodes = getAllTextNodes(aAst);
for (DetailNode textNode : textNodes.subList(1, textNodes.size())) {
final DetailNode whitespaceNode = JavadocUtils.getFirstChild(textNode);
if (whitespaceNode.getType() == JavadocTokenTypes.WS
&& whitespaceNode.getText().length() - 1 != mOffset)
final List<DetailNode> textNodes = getAllNewlineNodes(aAst);
if (isInlineDescription(aAst)) {
return;
}
for (DetailNode newlineNode : textNodes) {
final DetailNode textNode = JavadocUtils.getNextSibling(JavadocUtils
.getNextSibling(newlineNode));
if (textNode != null && textNode.getType() == JavadocTokenTypes.TEXT
&& textNode.getChildren().length > 1)
{
log(textNode.getLineNumber(), "tag.continuation.indent", mOffset);
final DetailNode whitespace = JavadocUtils.getFirstChild(textNode);
if (whitespace.getType() == JavadocTokenTypes.WS
&& whitespace.getText().length() - 1 < mOffset)
{
log(textNode.getLineNumber(), "tag.continuation.indent", mOffset);
}
}
}
}
@ -87,16 +94,33 @@ public class JavaDocTagContinuationIndentationCheck extends AbstractJavadocCheck
* @param aDescriptionNode Some javadoc.
* @return Some javadoc.
*/
private List<DetailNode> getAllTextNodes(DetailNode aDescriptionNode)
private List<DetailNode> getAllNewlineNodes(DetailNode aDescriptionNode)
{
final List<DetailNode> textNodes = new ArrayList<DetailNode>();
DetailNode node = JavadocUtils.getFirstChild(aDescriptionNode);
while (JavadocUtils.getNextSibling(node) != null) {
if (node.getType() == JavadocTokenTypes.TEXT) {
if (node.getType() == JavadocTokenTypes.NEWLINE) {
textNodes.add(node);
}
node = JavadocUtils.getNextSibling(node);
}
return textNodes;
}
/**
* Some javadoc.
* @param aDescription Some javadoc.
* @return Some javadoc.
*/
private boolean isInlineDescription(DetailNode aDescription)
{
DetailNode inlineTag = aDescription.getParent();
while (inlineTag != null) {
if (inlineTag.getType() == JavadocTokenTypes.JAVADOC_INLINE_TAG) {
return true;
}
inlineTag = inlineTag.getParent();
}
return false;
}
}

View File

@ -26,6 +26,16 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public class JavaDocTagContinuationIndentationCheckTest
extends BaseCheckTestSupport
{
@Test
public void testFP() throws Exception
{
final DefaultConfiguration checkConfig =
createCheckConfig(JavaDocTagContinuationIndentationCheck.class);
final String[] expected = {
};
verify(checkConfig, getPath("javadoc/GuavaFP.java"), expected);
}
@Test
public void testCheck() throws Exception
{

View File

@ -0,0 +1,13 @@
class Foo {
/**
* This class implements the GWT serialization of {@link HashMultimap}.
*
* @author Jord Sonneveld
*
*/
public static <T extends Enum<T>> Function<String, T> valueOfFunction(
Class<T> enumClass) {
return new ValueOfFunction<T>(enumClass);
}
}

View File

@ -44,7 +44,7 @@ class JavaDocTagContinuationIndentation implements Serializable
* @return Some text.
* @serialData Some javadoc.
* @deprecated Some text.
* Some javadoc. // warn
* Some javadoc. // warn
* @throws Exception Some text.
*/
String method(String aString) throws Exception
@ -106,10 +106,10 @@ class JavaDocTagContinuationIndentation implements Serializable
* Some text.
* @param aString Some text.
* @return Some text.
* Some javadoc. // warn
* Some javadoc. // warn
* @serialData Some javadoc.
* @param aInt Some text.
* Some javadoc. // warn
* Some javadoc. // warn
* @throws Exception Some text.
* @param aBoolean Some text.
* @deprecated Some text.
@ -200,10 +200,10 @@ class JavaDocTagContinuationIndentation implements Serializable
* @param aString Some text.
* @return Some text.
* @param aInt Some text.
* Some javadoc. // warn
* Some javadoc. // warn
* @throws Exception Some text.
* @param aBoolean Some text.
* Some javadoc. // warn
* Some javadoc. // warn
* @deprecated Some text.
*/
String method6(String aString, int aInt, boolean aBoolean) throws Exception
@ -218,9 +218,9 @@ class JavaDocTagContinuationIndentation implements Serializable
* Some text.
* @throws Exception Some text.
* @param aString Some text.
* Some javadoc. // warn
* Some javadoc. // warn
* @serialData Some javadoc.
* Some javadoc. // warn
* Some javadoc. // warn
* @deprecated Some text.
* @return Some text.
*/
@ -282,12 +282,12 @@ class JavaDocTagContinuationIndentation implements Serializable
* Some text.
* Some javadoc. // warn
* @param aString Some text.
* Some javadoc. // warn
* Some javadoc. // warn
* @return Some text.
* @param aInt Some text.
* Some javadoc. // warn
* Some javadoc. // warn
* @throws Exception Some text.
* Some javadoc. // warn
* Some javadoc. // warn
* @param aBoolean Some text.
* @deprecated Some text.
*/
@ -307,7 +307,7 @@ class JavaDocTagContinuationIndentation implements Serializable
* Some javadoc.
* Some javadoc.
* @see Some javadoc.
* Some javadoc. // warn
* Some javadoc. // warn
* @author max
*/
enum Foo {}
@ -319,7 +319,7 @@ enum Foo {}
* @since Some javadoc.
* Some javadoc.
* @serialData Some javadoc.
* Some javadoc. // warn
* Some javadoc. // warn
* @author max
*/
interface FooIn {}