diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavaDocTagContinuationIndentationCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavaDocTagContinuationIndentationCheck.java index fa8fb8bf2..2ab17e288 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavaDocTagContinuationIndentationCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavaDocTagContinuationIndentationCheck.java @@ -69,15 +69,22 @@ public class JavaDocTagContinuationIndentationCheck extends AbstractJavadocCheck @Override public void visitJavadocToken(DetailNode aAst) { - final List 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 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 getAllTextNodes(DetailNode aDescriptionNode) + private List getAllNewlineNodes(DetailNode aDescriptionNode) { final List textNodes = new ArrayList(); 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; + } } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavaDocTagContinuationIndentationCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavaDocTagContinuationIndentationCheckTest.java index 37bc3a084..1b1c0a20d 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavaDocTagContinuationIndentationCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavaDocTagContinuationIndentationCheckTest.java @@ -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 { diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/javadoc/GuavaFP.java b/src/test/resources/com/puppycrawl/tools/checkstyle/javadoc/GuavaFP.java new file mode 100644 index 000000000..7ee142c2a --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/javadoc/GuavaFP.java @@ -0,0 +1,13 @@ +class Foo { + + /** + * This class implements the GWT serialization of {@link HashMultimap}. + * + * @author Jord Sonneveld + * + */ + public static > Function valueOfFunction( + Class enumClass) { + return new ValueOfFunction(enumClass); + } +} \ No newline at end of file diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/javadoc/InputJavaDocTagContinuationIndentation.java b/src/test/resources/com/puppycrawl/tools/checkstyle/javadoc/InputJavaDocTagContinuationIndentation.java index cfceec419..a0f73c2f9 100644 --- a/src/test/resources/com/puppycrawl/tools/checkstyle/javadoc/InputJavaDocTagContinuationIndentation.java +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/javadoc/InputJavaDocTagContinuationIndentation.java @@ -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 {} \ No newline at end of file