Skip to content

Commit

Permalink
Merge pull request #52 from XenoAmess/fix_bug_about_annotation_in_ope…
Browse files Browse the repository at this point in the history
…ration_fix

[MJAVADOC-657] The fix operation duplicates annotations on private methods that have an annotation line between the method body and the javadoc comments.
  • Loading branch information
elharo committed Aug 21, 2020
2 parents 7541ac7 + de76473 commit ba2c180
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 8 deletions.
Expand Up @@ -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;
}
}
}
Expand All @@ -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;
}
}

Expand Down
Expand Up @@ -25,6 +25,7 @@
* @author <a href="mailto:vsiveton@apache.org">vsiveton@apache.org</a>
* @version $Id: $
*/
@SuppressWarnings("SameReturnValue")
public class ClassWithJavadoc
implements InterfaceWithJavadoc
{
Expand All @@ -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.
*
Expand Down Expand Up @@ -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
{
}
Expand Up @@ -27,6 +27,7 @@
* @author <a href="mailto:vsiveton@apache.org">vsiveton@apache.org</a>
* @version $Id: $
*/
@SuppressWarnings("SameReturnValue")
public class ClassWithNoJavadoc
implements InterfaceWithNoJavadoc
{
Expand Down Expand Up @@ -69,6 +70,22 @@ public ClassWithNoJavadoc( String aString )
{
}

@SuppressWarnings("SameReturnValue")
/**
* <p>Constructor for ClassWithNoJavadoc.</p>
*
* @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
/**
* <p>missingJavadocTagsForPrimitives.</p>
Expand Down Expand Up @@ -154,4 +171,39 @@ public void nothing()
{
}
}

@SuppressWarnings("SameReturnValue")
private void t000() {
return;
}

//test comment
private void t001() {
return;
}

/**
* <p>t010.</p>
*
* @since 1.1
*/
@SuppressWarnings("SameReturnValue")
public void t010() {
return;
}

//test comment
/**
* <p>t011.</p>
*
* @since 1.1
*/
public void t011() {
return;
}
}

@SuppressWarnings("SameReturnValue")
class PrivateTestClassWithNoJavadoc
{
}
4 changes: 2 additions & 2 deletions src/test/resources/unit/fix-test/pom.xml
Expand Up @@ -27,8 +27,8 @@
<packaging>jar</packaging>

<properties>
<maven.compiler.source>1.4</maven.compiler.source>
<maven.compiler.target>1.4</maven.compiler.target>
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>
</properties>

<build>
Expand Down
Expand Up @@ -22,6 +22,7 @@
/**
* To add default class tags.
*/
@SuppressWarnings("SameReturnValue")
public class ClassWithJavadoc
implements InterfaceWithJavadoc
{
Expand All @@ -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.
*
Expand Down Expand Up @@ -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
{
}
Expand Up @@ -21,6 +21,7 @@

import java.util.Map;

@SuppressWarnings("SameReturnValue")
public class ClassWithNoJavadoc
implements InterfaceWithNoJavadoc
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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
{
}

0 comments on commit ba2c180

Please sign in to comment.