diff --git a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4822declaredwhenneeded/InputDeclaredWhenNeeded.java b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4822declaredwhenneeded/InputDeclaredWhenNeeded.java index 1ca6f222984..9a214996a45 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4822declaredwhenneeded/InputDeclaredWhenNeeded.java +++ b/src/it/resources/com/google/checkstyle/test/chapter4formatting/rule4822declaredwhenneeded/InputDeclaredWhenNeeded.java @@ -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; diff --git a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodAndMissingJavadocMethod.java b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodAndMissingJavadocMethod.java index e876e44ed32..10f65b6eb56 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodAndMissingJavadocMethod.java +++ b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule731selfexplanatory/InputJavadocMethodAndMissingJavadocMethod.java @@ -62,7 +62,7 @@ public void smallMethod1() { foo2(); } - // ok, methods smaller than 2 lines does not require javadoc + /** some javadoc. */ protected void smallMethod2() { foo2(); } diff --git a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule732exceptionoverrides/InputJavadocMethodAndMissingJavadocMethod.java b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule732exceptionoverrides/InputJavadocMethodAndMissingJavadocMethod.java index dd298c626ce..c0fe8eedd59 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule732exceptionoverrides/InputJavadocMethodAndMissingJavadocMethod.java +++ b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule732exceptionoverrides/InputJavadocMethodAndMissingJavadocMethod.java @@ -62,7 +62,7 @@ public void smallMethod1() { foo2(); } - // ok, methods smaller than 2 lines does not require javadoc + /** some javadoc. */ protected void smallMethod2() { foo2(); } diff --git a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputJavadocMethodAndMissingJavadocMethod.java b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputJavadocMethodAndMissingJavadocMethod.java index 862e32a41fd..8d8be95a2c8 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputJavadocMethodAndMissingJavadocMethod.java +++ b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputJavadocMethodAndMissingJavadocMethod.java @@ -62,7 +62,7 @@ public void smallMethod1() { foo2(); } - // ok, methods smaller than 2 lines does not require javadoc + /** some javadoc. */ protected void smallMethod2() { foo2(); } diff --git a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputMissingJavadocTypeCorrect.java b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputMissingJavadocTypeCorrect.java index 6a0853ecaf7..d3d34616546 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputMissingJavadocTypeCorrect.java +++ b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputMissingJavadocTypeCorrect.java @@ -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 {} @@ -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 {} @@ -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(); + } } diff --git a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputMissingJavadocTypeIncorrect.java b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputMissingJavadocTypeIncorrect.java index 41eb0a9268a..71e2e5568d0 100644 --- a/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputMissingJavadocTypeIncorrect.java +++ b/src/it/resources/com/google/checkstyle/test/chapter7javadoc/rule73wherejavadocrequired/InputMissingJavadocTypeIncorrect.java @@ -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(); } } diff --git a/src/main/resources/google_checks.xml b/src/main/resources/google_checks.xml index 8e39637f9bd..991c433a566 100644 --- a/src/main/resources/google_checks.xml +++ b/src/main/resources/google_checks.xml @@ -347,12 +347,20 @@ - + + + + + JavadocMethod -
-
- "protected" methods are not detected for missing javadoc, it will be addressed at: - #15434 -