From de7647391b97331e76fdafdba476843eee77cc4b Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Thu, 20 Aug 2020 17:35:27 +0800 Subject: [PATCH] [MJAVADOC-657] The fix operation duplicates annotations on private methods that have an annotation line between the method body and the javadoc comments. --- .../javadoc/AbstractFixJavadocMojo.java | 20 ++++-- .../main/java/fix/test/ClassWithJavadoc.java | 68 +++++++++++++++++++ .../java/fix/test/ClassWithNoJavadoc.java | 52 ++++++++++++++ src/test/resources/unit/fix-test/pom.xml | 4 +- .../main/java/fix/test/ClassWithJavadoc.java | 61 +++++++++++++++++ .../java/fix/test/ClassWithNoJavadoc.java | 36 ++++++++++ 6 files changed, 233 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java index 86831251..afca9540 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java @@ -1052,9 +1052,13 @@ else if ( lineNumber == javaClass.getLineNumber() ) { if ( lineNumber == method.getLineNumber() ) { - changeDetected |= fixMethodComment( stringWriter, originalContent, method, indent ); - - takeCareSingleComment( stringWriter, originalContent, method ); + final boolean commentUpdated = + fixMethodComment( stringWriter, originalContent, method, indent ); + if ( commentUpdated ) + { + takeCareSingleComment( stringWriter, originalContent, method ); + } + changeDetected |= commentUpdated; } } } @@ -1075,9 +1079,13 @@ else if ( lineNumber == javaClass.getLineNumber() ) if ( lineNumber == methodLineNumber ) { - changeDetected |= fixMethodComment( stringWriter, originalContent, method, indent ); - - takeCareSingleComment( stringWriter, originalContent, method ); + final boolean commentUpdated = + fixMethodComment( stringWriter, originalContent, method, indent ); + if ( commentUpdated ) + { + takeCareSingleComment( stringWriter, originalContent, method ); + } + changeDetected |= commentUpdated; } } diff --git a/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithJavadoc.java b/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithJavadoc.java index 8c5e8bd1..6ee727f9 100644 --- a/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithJavadoc.java +++ b/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithJavadoc.java @@ -25,6 +25,7 @@ * @author vsiveton@apache.org * @version $Id: $ */ +@SuppressWarnings("SameReturnValue") public class ClassWithJavadoc implements InterfaceWithJavadoc { @@ -44,6 +45,25 @@ public ClassWithJavadoc( String aString ) { } + /** + * public constructor with annotation + * + * @param b a {@link java.lang.Boolean} object. + * @since 1.1 + */ + @SuppressWarnings("SameReturnValue") + public ClassWithJavadoc( Boolean b ) + { + } + + /** + * private constructor with annotation + */ + @SuppressWarnings("SameReturnValue") + private ClassWithJavadoc( Integer i ) + { + } + /** * Spaces in tags. * @@ -298,4 +318,52 @@ public static class MyRuntimeException extends RuntimeException { } + + /** + * private method with annotation + */ + @SuppressWarnings("SameReturnValue") + private void t000() + { + return; + } + + /** + * private method with line comment + */ + //test comment + private void t001() + { + return; + } + + /** + * public method with annotation + * + * @since 1.1 + */ + @SuppressWarnings("SameReturnValue") + public void t010() + { + return; + } + + /** + * public method with annotation + * + * @since 1.1 + */ + //test comment + public void t011() + { + return; + } +} + +/** + * To test package class + */ +@SuppressWarnings("SameReturnValue") +class PrivateTestClassWithJavadoc +{ } diff --git a/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithNoJavadoc.java b/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithNoJavadoc.java index aba4206a..25d8f298 100644 --- a/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithNoJavadoc.java +++ b/src/test/resources/unit/fix-test/expected/src/main/java/fix/test/ClassWithNoJavadoc.java @@ -27,6 +27,7 @@ * @author vsiveton@apache.org * @version $Id: $ */ +@SuppressWarnings("SameReturnValue") public class ClassWithNoJavadoc implements InterfaceWithNoJavadoc { @@ -69,6 +70,22 @@ public ClassWithNoJavadoc( String aString ) { } + @SuppressWarnings("SameReturnValue") + /** + *

Constructor for ClassWithNoJavadoc.

+ * + * @param b a {@link java.lang.Boolean} object. + * @since 1.1 + */ + public ClassWithNoJavadoc( Boolean b ) + { + } + + @SuppressWarnings("SameReturnValue") + private ClassWithNoJavadoc( Integer i ) + { + } + // take care of primitive /** *

missingJavadocTagsForPrimitives.

@@ -154,4 +171,39 @@ public void nothing() { } } + + @SuppressWarnings("SameReturnValue") + private void t000() { + return; + } + + //test comment + private void t001() { + return; + } + + /** + *

t010.

+ * + * @since 1.1 + */ + @SuppressWarnings("SameReturnValue") + public void t010() { + return; + } + + //test comment + /** + *

t011.

+ * + * @since 1.1 + */ + public void t011() { + return; + } +} + +@SuppressWarnings("SameReturnValue") +class PrivateTestClassWithNoJavadoc +{ } diff --git a/src/test/resources/unit/fix-test/pom.xml b/src/test/resources/unit/fix-test/pom.xml index e7bba6c5..cb297750 100644 --- a/src/test/resources/unit/fix-test/pom.xml +++ b/src/test/resources/unit/fix-test/pom.xml @@ -27,8 +27,8 @@ jar - 1.4 - 1.4 + 1.5 + 1.5 diff --git a/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java b/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java index 8f72a2ea..4963ef3c 100644 --- a/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java +++ b/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithJavadoc.java @@ -22,6 +22,7 @@ /** * To add default class tags. */ +@SuppressWarnings("SameReturnValue") public class ClassWithJavadoc implements InterfaceWithJavadoc { @@ -39,6 +40,22 @@ public ClassWithJavadoc( String aString ) { } + /** + * public constructor with annotation + */ + @SuppressWarnings("SameReturnValue") + public ClassWithJavadoc( Boolean b ) + { + } + + /** + * private constructor with annotation + */ + @SuppressWarnings("SameReturnValue") + private ClassWithJavadoc( Integer i ) + { + } + /** * Spaces in tags. * @@ -282,4 +299,48 @@ public static class MyRuntimeException extends RuntimeException { } + + /** + * private method with annotation + */ + @SuppressWarnings("SameReturnValue") + private void t000() + { + return; + } + + /** + * private method with line comment + */ + //test comment + private void t001() + { + return; + } + + /** + * public method with annotation + */ + @SuppressWarnings("SameReturnValue") + public void t010() + { + return; + } + + /** + * public method with annotation + */ + //test comment + public void t011() + { + return; + } } + +/** + * To test package class + */ +@SuppressWarnings("SameReturnValue") +class PrivateTestClassWithJavadoc +{ +} \ No newline at end of file diff --git a/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithNoJavadoc.java b/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithNoJavadoc.java index eb71d29b..2b62ab50 100644 --- a/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithNoJavadoc.java +++ b/src/test/resources/unit/fix-test/src/main/java/fix/test/ClassWithNoJavadoc.java @@ -21,6 +21,7 @@ import java.util.Map; +@SuppressWarnings("SameReturnValue") public class ClassWithNoJavadoc implements InterfaceWithNoJavadoc { @@ -49,6 +50,16 @@ public ClassWithNoJavadoc( String aString ) { } + @SuppressWarnings("SameReturnValue") + public ClassWithNoJavadoc( Boolean b ) + { + } + + @SuppressWarnings("SameReturnValue") + private ClassWithNoJavadoc( Integer i ) + { + } + // take care of primitive public void missingJavadocTagsForPrimitives( int i, byte b, float f, char c, short s, long l, double d, boolean bb ) { @@ -106,4 +117,29 @@ public void nothing() { } } + + @SuppressWarnings("SameReturnValue") + private void t000() { + return; + } + + //test comment + private void t001() { + return; + } + + @SuppressWarnings("SameReturnValue") + public void t010() { + return; + } + + //test comment + public void t011() { + return; + } +} + +@SuppressWarnings("SameReturnValue") +class PrivateTestClassWithNoJavadoc +{ }