From 3dafe0180e5b2fe5103ebd1fcf7d3d9775acb82e Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Sat, 22 Aug 2020 13:01:19 +0800 Subject: [PATCH] [MJAVADOC-658] The fix operation wrongly delete generic functions's generic-class javadoc if exist, and add it if lack, and will not create it if param part of javadoc be empty --- .../javadoc/AbstractFixJavadocMojo.java | 109 +----------------- .../main/java/fix/test/ClassWithJavadoc.java | 39 +++++++ .../java/fix/test/ClassWithNoJavadoc.java | 25 +++- .../main/java/fix/test/ClassWithJavadoc.java | 31 +++++ .../java/fix/test/ClassWithNoJavadoc.java | 17 ++- 5 files changed, 108 insertions(+), 113 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 afca9540..21480695 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java @@ -1635,11 +1635,7 @@ private void updateJavadocComment( final StringWriter stringWriter, final String return; } - boolean isJavaExecutable = false; - if ( entity instanceof JavaExecutable ) - { - isJavaExecutable = true; - } + boolean isJavaExecutable = entity instanceof JavaExecutable; StringBuilder sb = new StringBuilder(); @@ -1740,14 +1736,7 @@ private void updateJavadocComment( final StringWriter stringWriter, final String } // tags - if ( entity.getTags() != null && !entity.getTags().isEmpty() ) - { - updateJavadocTags( sb, originalContent, entity, indent, isJavaExecutable ); - } - else - { - addDefaultJavadocTags( sb, entity, indent, isJavaExecutable ); - } + updateJavadocTags( sb, originalContent, entity, indent, isJavaExecutable ); sb = new StringBuilder( removeLastEmptyJavadocLines( sb.toString() ) ).append( EOL ); @@ -2074,7 +2063,7 @@ private void writeParamTag( final StringBuilder sb, final JavaExecutable javaExe List> typeParams = javaExecutable.getTypeParameters(); for ( JavaTypeVariable typeParam : typeParams ) { - if ( typeParam.getGenericValue().equals( paramName ) ) + if ( ( "<" + typeParam.getName() + ">" ).equals( paramName ) ) { found = true; } @@ -2346,96 +2335,6 @@ else if ( entity instanceof JavaClass } } - /** - * @param sb not null - * @param entity not null - * @param indent not null - * @param isJavaExecutable - * @throws MojoExecutionException if any - */ - private void addDefaultJavadocTags( final StringBuilder sb, final JavaAnnotatedElement entity, - final String indent, final boolean isJavaExecutable ) - throws MojoExecutionException - { - boolean separatorAdded = false; - if ( isJavaExecutable ) - { - JavaExecutable javaExecutable = (JavaExecutable) entity; - - if ( fixTag( PARAM_TAG ) && javaExecutable.getParameters() != null ) - { - for ( JavaParameter javaParameter : javaExecutable.getParameters() ) - { - separatorAdded = appendDefaultParamTag( sb, indent, separatorAdded, javaParameter ); - } - } - - if ( javaExecutable instanceof JavaMethod && fixTag( RETURN_TAG ) ) - { - JavaMethod javaMethod = (JavaMethod) javaExecutable; - if ( javaMethod.getReturns() != null && !javaMethod.getReturns().isVoid() ) - { - separatorAdded = appendDefaultReturnTag( sb, indent, separatorAdded, javaMethod ); - } - } - - if ( fixTag( THROWS_TAG ) && javaExecutable.getExceptions() != null ) - { - for ( JavaType exception : javaExecutable.getExceptions() ) - { - separatorAdded = appendDefaultThrowsTag( sb, indent, separatorAdded, exception ); - } - } - } - else - { - separatorAdded = appendDefaultAuthorTag( sb, indent, separatorAdded ); - - separatorAdded = appendDefaultVersionTag( sb, indent, separatorAdded ); - } - - if ( fixTag( SINCE_TAG ) ) - { - if ( !isJavaExecutable ) - { - JavaClass javaClass = (JavaClass) entity; - - if ( !ignoreClirr ) - { - if ( isNewClassFromLastVersion( javaClass ) ) - { - separatorAdded = appendDefaultSinceTag( sb, indent, separatorAdded ); - } - } - else - { - separatorAdded = appendDefaultSinceTag( sb, indent, separatorAdded ); - - addSinceClasses( javaClass ); - } - } - else - { - JavaExecutable javaExecutable = (JavaExecutable) entity; - - if ( !ignoreClirr ) - { - if ( isNewMethodFromLastRevision( javaExecutable ) ) - { - separatorAdded = appendDefaultSinceTag( sb, indent, separatorAdded ); - } - } - else - { - if ( sinceClasses != null && !sinceClassesContains( javaExecutable.getDeclaringClass() ) ) - { - separatorAdded = appendDefaultSinceTag( sb, indent, separatorAdded ); - } - } - } - } - } - /** * @param sb not null * @param indent not null @@ -2875,7 +2774,7 @@ private String getDefaultJavadocForType( JavaClass clazz ) private String getDefaultJavadocForType( JavaTypeVariable typeParameter ) { - return "a " + typeParameter.getName() + " object."; + return "a " + typeParameter.getName() + " class."; } /** 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 6ee727f9..8de0cbd8 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 @@ -358,6 +358,45 @@ public void t011() { return; } + + /** + * test generic function (with only head javadoc) + * + * @param tClass a {@link java.lang.Class} object. + * @param o a {@link java.lang.Object} object. + * @param a T class. + * @since 1.1 + */ + public void testGeneric0(Class tClass, Object o) + { + return; + } + + /** + * test generic function (with full javadoc) + * + * @param tClass a {@link java.lang.Class} object. + * @param o a {@link java.lang.Object} object. + * @param a T class. + * @since 1.1 + */ + public void testGeneric1(Class tClass, Object o) + { + return; + } + + /** + * test generic function (with full javadoc, except generic docs) + * + * @param tClass a {@link java.lang.Class} object. + * @param o a {@link java.lang.Object} object. + * @param a T class. + * @since 1.1 + */ + public void testGeneric2(Class tClass, Object o) + { + return; + } } /** 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 25d8f298..8b7196ec 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 @@ -173,12 +173,14 @@ public void nothing() } @SuppressWarnings("SameReturnValue") - private void t000() { + private void t000() + { return; } //test comment - private void t001() { + private void t001() + { return; } @@ -188,7 +190,8 @@ private void t001() { * @since 1.1 */ @SuppressWarnings("SameReturnValue") - public void t010() { + public void t010() + { return; } @@ -198,7 +201,21 @@ public void t010() { * * @since 1.1 */ - public void t011() { + public void t011() + { + return; + } + + /** + *

testGeneric3.

+ * + * @param tClass a {@link java.lang.Class} object. + * @param o a {@link java.lang.Object} object. + * @param a T class. + * @since 1.1 + */ + public void testGeneric3(Class tClass, Object o) + { return; } } 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 4963ef3c..e6413f88 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 @@ -335,6 +335,37 @@ public void t011() { return; } + + /** + * test generic function (with only head javadoc) + */ + public void testGeneric0(Class tClass, Object o) + { + return; + } + + /** + * test generic function (with full javadoc) + * + * @param tClass a {@link java.lang.Class} object. + * @param o a {@link java.lang.Object} object. + * @param a T class. + */ + public void testGeneric1(Class tClass, Object o) + { + return; + } + + /** + * test generic function (with full javadoc, except generic docs) + * + * @param tClass a {@link java.lang.Class} object. + * @param o a {@link java.lang.Object} object. + */ + public void testGeneric2(Class tClass, Object o) + { + return; + } } /** 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 2b62ab50..3704dfb8 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 @@ -119,22 +119,31 @@ public void nothing() } @SuppressWarnings("SameReturnValue") - private void t000() { + private void t000() + { return; } //test comment - private void t001() { + private void t001() + { return; } @SuppressWarnings("SameReturnValue") - public void t010() { + public void t010() + { return; } //test comment - public void t011() { + public void t011() + { + return; + } + + public void testGeneric3(Class tClass, Object o) + { return; } }