Skip to content

Commit

Permalink
Issue checkstyle#15434: fixed MissingJavadocMethod module in google_c…
Browse files Browse the repository at this point in the history
…hecks.xml to give warning for missing javadoc for protected methods
  • Loading branch information
Zopsss authored and romani committed Sep 11, 2024
1 parent 49ec4c0 commit 35d646d
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public void testMethod16() {
}
}

/** Some javadoc. */
protected JmenuItem createSubMenuItem(LogLevel level) {
final JmenuItem result = new JmenuItem(level.toString());
final LogLevel logLevel = level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void smallMethod1() {
foo2();
}

// ok, methods smaller than 2 lines does not require javadoc
/** some javadoc. */
protected void smallMethod2() {
foo2();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void smallMethod1() {
foo2();
}

// ok, methods smaller than 2 lines does not require javadoc
/** some javadoc. */
protected void smallMethod2() {
foo2();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void smallMethod1() {
foo2();
}

// ok, methods smaller than 2 lines does not require javadoc
/** some javadoc. */
protected void smallMethod2() {
foo2();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ public class InputMissingJavadocTypeCorrect {
int myOtherInt;

/** This is a Javadoc comment. */
public class InnerPublic implements MyInterfacePublic {}
public class InnerPublic implements MyInterfacePublic2 {
@Override
public void testPublicInterfaceMethod() {}

@Override
public void testPackagePrivateInterfaceMethod() {}
}

/** This is a Javadoc comment. */
public enum MyEnumPublic {}
Expand All @@ -21,18 +27,11 @@ class MyInterfaceClass {}
/** This is a Javadoc comment. */
public @interface MyAnnotationPublic {}

/** This is a Javadoc comment. */
protected class InnerProtected {}

/** This is a Javadoc comment. */
protected enum MyEnumProtected {}

/** This is a Javadoc comment. */
protected interface MyInterfaceProtected {}

/** This is a Javadoc comment. */
protected @interface MyAnnotationProtected {}

@interface MyAnnotationPackagePrivate {}

class Inner {}

enum MyEnum {}
Expand All @@ -53,4 +52,112 @@ private interface MyInterfacePrivate {}
public void myMethod() {
class MyMethodClass {}
}

/** some javadoc. */
protected int testProtectedMethod1() {
return 0;
}

/** some javadoc. */
protected void testProtectedMethod2() {}

/** some javadoc. */
public void testPublicMethod() {}

private void testPrivateMethod() {}

void testPackagePrivateMethod() {}

/** some javadoc. */
protected InputMissingJavadocTypeCorrect() {}

/** some javadoc. */
public InputMissingJavadocTypeCorrect(String arg) {}

private InputMissingJavadocTypeCorrect(int arg) {}

InputMissingJavadocTypeCorrect(double arg) {}

/** some javadoc. */
protected @interface ProtectedAnnotation {}

/** some javadoc. */
public @interface PublicAnnotation {}

private @interface PrivateAnnotation {}

@interface PackagePrivateAnnotation {}

/** some javadoc. */
protected class InnerProtected {
protected void testProtectedInnerMethod() {}

public void testPublicInnerMethod() {}

private void testPrivateInnerMethod() {}

void testPackagePrivateInnerMethod() {}

protected InnerProtected() {}

InnerProtected(String arg) {}

private InnerProtected(double arg) {}
}

/** some javadoc. */
public enum MyEnumPublic2 {
TEST;

/** some javadoc. */
public void testPublicEnumMethod() {}

/** some javadoc. */
protected void testProtectedEnumMethod() {}

private void testPrivateEnumMethod() {}

void testPackagePrivateEnumMethod() {}

private MyEnumPublic2() {}

MyEnumPublic2(String arg) {}
}

/** some javadoc. */
protected enum MyEnumProtected {
TEST;

public void testPublicEnumMethod() {}

protected void testProtectedEnumMethod() {}

private void testPrivateEnumMethod() {}

void testPackagePrivateEnumMethod() {}

private MyEnumProtected() {}

MyEnumProtected(String arg) {}
}

/** some javadoc. */
protected interface MyInterfaceProtected {
public void testPublicInterfaceMethod();

private void testPrivateInterfaceMethod() {}

void testPackagePrivateInterfaceMethod();
}

/** some javadoc. */
public interface MyInterfacePublic2 {
/** some javadoc. */
public void testPublicInterfaceMethod();

private void testPrivateInterfaceMethod() {}

/** some javadoc. */
void testPackagePrivateInterfaceMethod();
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,144 @@
package com.google.checkstyle.test.chapter7javadoc.rule73wherejavadocrequired;

public class InputMissingJavadocTypeIncorrect { // violation 'Missing a Javadoc comment.'
// violation below 'Missing a Javadoc comment.'
public class InputMissingJavadocTypeIncorrect {

public class Inner { // violation 'Missing a Javadoc comment.'
// violation below 'Missing a Javadoc comment.'
public class InnerPublic implements MyInterfacePublic {
@Override
public void testPublicInterfaceMethod() {}

@Override
public void testPackagePrivateInterfaceMethod() {}
}

public enum MyEnum { // violation 'Missing a Javadoc comment.'
// violation below 'Missing a Javadoc comment.'
public enum MyEnum {}

// violation below 'Missing a Javadoc comment.'
public interface MyInterface {
// violation below 'Missing a Javadoc comment.'
class MyInterfaceClass {}
}

public interface MyInterface { // violation 'Missing a Javadoc comment.'
class MyInterfaceClass {} // violation 'Missing a Javadoc comment.'
// violation below 'Missing a Javadoc comment.'
public @interface MyAnnotation {}

// violation below 'Missing a Javadoc comment.'
protected @interface MyAnnotationProtected {}

/** some javadoc. */
public void myMethod() {
class MyMethodClass {}
}

public @interface MyAnnotation { // violation 'Missing a Javadoc comment.'
// OK, not public
class AdditionalClass {}

// violation below 'Missing a Javadoc comment.'
protected int testProtectedMethod1() {
return 0;
}

protected class InnerProtected { // violation 'Missing a Javadoc comment.'
// violation below 'Missing a Javadoc comment.'
protected void testProtectedMethod2() {}

// violation below 'Missing a Javadoc comment.'
protected InputMissingJavadocTypeIncorrect() {}

// violation below 'Missing a Javadoc comment.'
public class InnerClass {
// violation below 'Missing a Javadoc comment.'
public void testPublicInnerMethod() {}

// violation below 'Missing a Javadoc comment.'
protected void testProtectedInnerMethod() {}

private void testPrivateInnerMethod() {}

void testPackagePrivateInnerMethod() {}

// violation below 'Missing a Javadoc comment.'
public InnerClass(int arg) {}

// violation below 'Missing a Javadoc comment.'
protected InnerClass() {}

InnerClass(String arg) {}

private InnerClass(double arg) {}
}

protected enum MyEnumProtected { // violation 'Missing a Javadoc comment.'
// violation below 'Missing a Javadoc comment.'
protected class InnerProtected {
protected void testProtectedInnerMethod() {}

public void testPublicInnerMethod() {}

private void testPrivateInnerMethod() {}

void testPackagePrivateInnerMethod() {}

protected InnerProtected() {}

InnerProtected(String arg) {}

private InnerProtected(double arg) {}
}

protected interface MyInterfaceProtected { // violation 'Missing a Javadoc comment.'
// violation below 'Missing a Javadoc comment.'
public enum MyEnumPublic {
TEST;

// violation below 'Missing a Javadoc comment.'
public void testPublicEnumMethod() {}

// violation below 'Missing a Javadoc comment.'
protected void testProtectedEnumMethod() {}

private void testPrivateEnumMethod() {}

void testPackagePrivateEnumMethod() {}

private MyEnumPublic() {}

MyEnumPublic(String arg) {}
}

protected @interface MyAnnotationProtected { // violation 'Missing a Javadoc comment.'
// violation below 'Missing a Javadoc comment.'
protected enum MyEnumProtected {
TEST;

public void testPublicEnumMethod() {}

protected void testProtectedEnumMethod() {}

private void testPrivateEnumMethod() {}

void testPackagePrivateEnumMethod() {}

private MyEnumProtected() {}

MyEnumProtected(String arg) {}
}

/** some javadoc. */
public void myMethod() {
class MyMethodClass {}
// violation below 'Missing a Javadoc comment.'
protected interface MyInterfaceProtected {
public void testPublicInterfaceMethod();

private void testPrivateInterfaceMethod() {}

void testPackagePrivateInterfaceMethod();
}

class AdditionalClass { // OK, not public
// violation below 'Missing a Javadoc comment.'
public interface MyInterfacePublic {
// violation below 'Missing a Javadoc comment.'
public void testPublicInterfaceMethod();

private void testPrivateInterfaceMethod() {}

// violation below 'Missing a Javadoc comment.'
void testPackagePrivateInterfaceMethod();
}
}
10 changes: 9 additions & 1 deletion src/main/resources/google_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,20 @@
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF, COMPACT_CTOR_DEF"/>
</module>
<module name="MissingJavadocMethod">
<property name="scope" value="public"/>
<property name="scope" value="protected"/>
<property name="allowMissingPropertyJavadoc" value="true"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF,
COMPACT_CTOR_DEF"/>
</module>
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="MissingJavadocMethod"/>
<property name="query" value="//*[self::METHOD_DEF or self::CTOR_DEF
or self::ANNOTATION_FIELD_DEF or self::COMPACT_CTOR_DEF]
[ancestor::*[self::INTERFACE_DEF or self::CLASS_DEF
or self::RECORD_DEF or self::ENUM_DEF]
[not(./MODIFIERS/LITERAL_PUBLIC)]]"/>
</module>
<module name="MissingJavadocType">
<property name="scope" value="protected"/>
<property name="tokens"
Expand Down
5 changes: 0 additions & 5 deletions src/xdocs/google_style.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2399,11 +2399,6 @@
alt="" />
</span>
<a href="checks/javadoc/javadocmethod.html#JavadocMethod">JavadocMethod</a>
<br/>
<br/>
"protected" methods are not detected for missing javadoc, it will be addressed at:
<a href="https://github.com/checkstyle/checkstyle/issues/15434">#15434</a>
<br/>
</td>
<td>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%20path%3A**%2Fgoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+MissingJavadocMethod">
Expand Down

0 comments on commit 35d646d

Please sign in to comment.