diff --git a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java index 71cfb8f28..f43ea482d 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/CheckerTest.java @@ -305,7 +305,8 @@ public class CheckerTest filepath + ":69: method is missing a Javadoc comment.", filepath + ":74: method is missing a Javadoc comment.", filepath + ":79: method is missing a Javadoc comment.", - filepath + ":84: method is missing a Javadoc comment." + filepath + ":84: method is missing a Javadoc comment.", + filepath + ":94: Expected @param tag for 'aA'." }; verify(c, filepath, expected); } @@ -313,7 +314,7 @@ public class CheckerTest public void testNoJavadoc() throws Exception { - mConfig.setIgnoreJavadoc(true); + mConfig.setJavadocScope(Scope.NOTHING); final Checker c = createChecker(); final String filepath = getPath("InputPublicOnly.java"); assertNotNull(c); @@ -325,20 +326,16 @@ public class CheckerTest verify(c, filepath, expected); } + // pre 1.4 relaxed mode is roughly equivalent with check=protected public void testRelaxedJavadoc() throws Exception { - mConfig.setRelaxJavadoc(true); + mConfig.setJavadocScope(Scope.PROTECTED); final Checker c = createChecker(); final String filepath = getPath("InputPublicOnly.java"); assertNotNull(c); final String[] expected = { filepath + ":7: type is missing a Javadoc comment.", - filepath + ":9: type is missing a Javadoc comment.", - filepath + ":11: variable 'CONST' missing Javadoc.", - filepath + ":12: method is missing a Javadoc comment.", - filepath + ":14: type is missing a Javadoc comment.", - filepath + ":34: type is missing a Javadoc comment.", filepath + ":44: variable 'mLen' must be private and have accessor methods.", filepath + ":45: variable 'mDeer' missing Javadoc.", filepath + ":45: variable 'mDeer' must be private and have accessor methods.", @@ -352,6 +349,80 @@ public class CheckerTest verify(c, filepath, expected); } + + public void testScopeInnerInterfacesPublic() + throws Exception + { + mConfig.setJavadocScope(Scope.PUBLIC); + final Checker c = createChecker(); + final String filepath = getPath("InputScopeInnerInterfaces.java"); + assertNotNull(c); + final String[] expected = { + filepath + ":7: type is missing a Javadoc comment.", + filepath + ":38: type is missing a Javadoc comment.", + filepath + ":40: variable 'CA' missing Javadoc.", + filepath + ":41: variable 'CB' missing Javadoc.", + filepath + ":43: method is missing a Javadoc comment.", + filepath + ":44: method is missing a Javadoc comment." + }; + verify(c, filepath, expected); + } + + public void testScopeInnerClassesPackage() + throws Exception + { + mConfig.setJavadocScope(Scope.PACKAGE); + final Checker c = createChecker(); + final String filepath = getPath("InputScopeInnerClasses.java"); + assertNotNull(c); + final String[] expected = { + filepath + ":18: type is missing a Javadoc comment.", + filepath + ":20: type is missing a Javadoc comment.", + filepath + ":22: type is missing a Javadoc comment." + }; + verify(c, filepath, expected); + } + + public void testScopeInnerClassesPublic() + throws Exception + { + mConfig.setJavadocScope(Scope.PUBLIC); + final Checker c = createChecker(); + final String filepath = getPath("InputScopeInnerClasses.java"); + assertNotNull(c); + final String[] expected = { + filepath + ":18: type is missing a Javadoc comment.", + }; + verify(c, filepath, expected); + } + + public void testScopeAnonInnerPrivate() + throws Exception + { + mConfig.setJavadocScope(Scope.PRIVATE); + final Checker c = createChecker(); + final String filepath = getPath("InputScopeAnonInner.java"); + assertNotNull(c); + final String[] expected = { + }; + verify(c, filepath, expected); + } + + public void testScopeAnonInnerAnonInner() + throws Exception + { + mConfig.setJavadocScope(Scope.ANONINNER); + final Checker c = createChecker(); + final String filepath = getPath("InputScopeAnonInner.java"); + assertNotNull(c); + final String[] expected = { + filepath + ":26: method is missing a Javadoc comment.", + filepath + ":39: method is missing a Javadoc comment.", + filepath + ":53: method is missing a Javadoc comment." + }; + verify(c, filepath, expected); + } + public void testHeader() throws Exception { diff --git a/src/tests/com/puppycrawl/tools/checkstyle/InputPublicOnly.java b/src/tests/com/puppycrawl/tools/checkstyle/InputPublicOnly.java index dc81835f5..a42cbe47f 100644 --- a/src/tests/com/puppycrawl/tools/checkstyle/InputPublicOnly.java +++ b/src/tests/com/puppycrawl/tools/checkstyle/InputPublicOnly.java @@ -4,14 +4,14 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle; -class InputPublicOnly // ignore - need javadoc +public class InputPublicOnly // ignore - need javadoc { - private interface InnerInterface // ignore -- need javadoc + private interface InnerInterface // ignore - when not relaxed about Javadoc { - String CONST = "InnerInterface"; // ignore -- need javadoc - void method(); // ignore -- need javadoc + String CONST = "InnerInterface"; // ignore - w.n.r.a.j + void method(); // ignore - when not relaxed about Javadoc - class InnerInnerClass // ignore -- need javadoc + class InnerInnerClass // ignore - when not relaxed about Javadoc { private int mData; // ignore - when not relaxed about Javadoc @@ -84,4 +84,15 @@ class InputPublicOnly // ignore - need javadoc public void method(StringBuffer aA) { } + + + /** + A param tag should not be required here when relaxed about Javadoc. + Writing a little documentation should not be worse than not + writing any documentation at all. + */ + private void method(String aA) + { + } + } diff --git a/src/tests/com/puppycrawl/tools/checkstyle/InputScopeAnonInner.java b/src/tests/com/puppycrawl/tools/checkstyle/InputScopeAnonInner.java new file mode 100644 index 000000000..10e696684 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/InputScopeAnonInner.java @@ -0,0 +1,59 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle; + +import java.awt.event.MouseEvent; +import java.awt.event.MouseAdapter; +import javax.swing.JButton; + +/** + * Tests for anonymous inner types + * @author Lars Kühne + **/ +public class InputScopeAnonInner +{ + /** + button. + */ + private JButton mButton = new JButton(); + + /** + anon inner in member variable initialization. + */ + private Runnable mRunnable = new Runnable() { + public void run() // should not have to be documented, class is anon. + { + System.out.println("running"); + } + }; + + /** + anon inner in constructor. + */ + InputScopeAnonInner() + { + mButton.addMouseListener( new MouseAdapter() + { + public void mouseClicked( MouseEvent aEv ) + { + System.out.println("click"); + } + } ); + } + + /** + anon inner in method + */ + public void addInputAnonInner() + { + mButton.addMouseListener( new MouseAdapter() + { + public void mouseClicked( MouseEvent aEv ) + { + System.out.println("click"); + } + } ); + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/InputScopeInnerClasses.java b/src/tests/com/puppycrawl/tools/checkstyle/InputScopeInnerClasses.java new file mode 100644 index 000000000..3f359fd69 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/InputScopeInnerClasses.java @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle; + +/** + Checks javadoc scoping for inner classes. + + Once the Javadoc Check Scope has been left, + all inner elements should not be reported as error, + even if they belong to the checkscope if isolated. + + @author lkuehne + */ +public class InputScopeInnerClasses +{ + public class InnerPublic + { + protected class InnerProtected + { + class InnerPackage + { + private class InnerPrivate + { + // no javadoc required for package scope + class PrivateHiddenPackage + { + } + + protected class PrivateHiddenProtected + { + } + + public class PrivateHiddenPublic + { + } + } + } + } + } +} diff --git a/src/tests/com/puppycrawl/tools/checkstyle/InputScopeInnerInterfaces.java b/src/tests/com/puppycrawl/tools/checkstyle/InputScopeInnerInterfaces.java new file mode 100644 index 000000000..90731e1e3 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/InputScopeInnerInterfaces.java @@ -0,0 +1,47 @@ +//////////////////////////////////////////////////////////////////////////////// +// Test case file for checkstyle. +// Created: 2001 +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle; + +public class InputScopeInnerInterfaces +{ + // inner interfaces with different scopes + + private interface PrivateInterface + { + public String CA = "CONST A"; + String CB = "CONST b"; + + public void ma(); + void mb(); + } + + interface PackageInnerInterface + { + public String CA = "CONST A"; + String CB = "CONST b"; + + public void ma(); + void mb(); + } + + protected interface ProtectedInnerInterface + { + public String CA = "CONST A"; + String CB = "CONST b"; + + public void ma(); + void mb(); + } + + public interface PublicInnerInterface + { + public String CA = "CONST A"; + String CB = "CONST b"; + + public void ma(); + void mb(); + } + +}