Tue, 23 Jul 2013 16:06:11 -0700
8021215: javac gives incorrect doclint warnings on normal package statements
Reviewed-by: darcy
1.1 --- a/src/share/classes/com/sun/tools/doclint/Checker.java Fri Jul 19 07:22:53 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclint/Checker.java Tue Jul 23 16:06:11 2013 -0700 1.3 @@ -141,10 +141,27 @@ 1.4 1.5 boolean isOverridingMethod = !env.currOverriddenMethods.isEmpty(); 1.6 1.7 - if (tree == null) { 1.8 - if (!isSynthetic() && !isOverridingMethod) 1.9 - reportMissing("dc.missing.comment"); 1.10 - return null; 1.11 + if (p.getLeaf() == p.getCompilationUnit()) { 1.12 + // If p points to a compilation unit, the implied declaration is the 1.13 + // package declaration (if any) for the compilation unit. 1.14 + // Handle this case specially, because doc comments are only 1.15 + // expected in package-info files. 1.16 + JavaFileObject fo = p.getCompilationUnit().getSourceFile(); 1.17 + boolean isPkgInfo = fo.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE); 1.18 + if (tree == null) { 1.19 + if (isPkgInfo) 1.20 + reportMissing("dc.missing.comment"); 1.21 + return null; 1.22 + } else { 1.23 + if (!isPkgInfo) 1.24 + reportReference("dc.unexpected.comment"); 1.25 + } 1.26 + } else { 1.27 + if (tree == null) { 1.28 + if (!isSynthetic() && !isOverridingMethod) 1.29 + reportMissing("dc.missing.comment"); 1.30 + return null; 1.31 + } 1.32 } 1.33 1.34 tagStack.clear(); 1.35 @@ -187,6 +204,10 @@ 1.36 env.messages.report(MISSING, Kind.WARNING, env.currPath.getLeaf(), code, args); 1.37 } 1.38 1.39 + private void reportReference(String code, Object... args) { 1.40 + env.messages.report(REFERENCE, Kind.WARNING, env.currPath.getLeaf(), code, args); 1.41 + } 1.42 + 1.43 @Override 1.44 public Void visitDocComment(DocCommentTree tree, Void ignore) { 1.45 super.visitDocComment(tree, ignore);
2.1 --- a/src/share/classes/com/sun/tools/doclint/DocLint.java Fri Jul 19 07:22:53 2013 -0700 2.2 +++ b/src/share/classes/com/sun/tools/doclint/DocLint.java Tue Jul 23 16:06:11 2013 -0700 2.3 @@ -32,8 +32,6 @@ 2.4 import java.util.List; 2.5 2.6 import javax.lang.model.element.Name; 2.7 -import javax.tools.Diagnostic; 2.8 -import javax.tools.JavaFileObject; 2.9 import javax.tools.StandardLocation; 2.10 2.11 import com.sun.source.doctree.DocCommentTree; 2.12 @@ -152,18 +150,6 @@ 2.13 TreePath p = getCurrentPath(); 2.14 DocCommentTree dc = env.trees.getDocCommentTree(p); 2.15 2.16 - if (p.getLeaf() == p.getCompilationUnit()) { 2.17 - JavaFileObject fo = p.getCompilationUnit().getSourceFile(); 2.18 - boolean pkgInfo = fo.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE); 2.19 - if (!pkgInfo) { 2.20 - if (dc == null) 2.21 - return; 2.22 - env.setCurrent(p, dc); 2.23 - env.messages.report(Messages.Group.REFERENCE, Diagnostic.Kind.WARNING, p.getLeaf(), 2.24 - "dc.unexpected.comment"); 2.25 - } 2.26 - } 2.27 - 2.28 checker.scan(dc, p); 2.29 } 2.30 };
3.1 --- a/test/tools/doclint/packageTests/bad/Test.java Fri Jul 19 07:22:53 2013 -0700 3.2 +++ b/test/tools/doclint/packageTests/bad/Test.java Tue Jul 23 16:06:11 2013 -0700 3.3 @@ -1,14 +1,16 @@ 3.4 /* 3.5 * @test /nodynamiccopyright/ 3.6 - * @bug 8020664 3.7 + * @bug 8020664 8021215 3.8 * @summary doclint gives incorrect warnings on normal package statements 3.9 * @library ../.. 3.10 * @build DocLintTester 3.11 * @run main DocLintTester -ref Test.out Test.java 3.12 + * @compile/fail/ref=Test.javac.out -XDrawDiagnostics -Werror -Xdoclint:all Test.java 3.13 */ 3.14 3.15 /** Unexpected comment */ 3.16 package bad; 3.17 3.18 +/** */ 3.19 class Test { } 3.20
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/tools/doclint/packageTests/bad/Test.javac.out Tue Jul 23 16:06:11 2013 -0700 4.3 @@ -0,0 +1,4 @@ 4.4 +Test.java:12:1: compiler.warn.proc.messager: documentation comment not expected here 4.5 +- compiler.err.warnings.and.werror 4.6 +1 error 4.7 +1 warning
5.1 --- a/test/tools/doclint/packageTests/bad/Test.out Fri Jul 19 07:22:53 2013 -0700 5.2 +++ b/test/tools/doclint/packageTests/bad/Test.out Tue Jul 23 16:06:11 2013 -0700 5.3 @@ -1,4 +1,4 @@ 5.4 -Test.java:11: warning: documentation comment not expected here 5.5 +Test.java:12: warning: documentation comment not expected here 5.6 package bad; 5.7 ^ 5.8 1 warning
6.1 --- a/test/tools/doclint/packageTests/bad/package-info.java Fri Jul 19 07:22:53 2013 -0700 6.2 +++ b/test/tools/doclint/packageTests/bad/package-info.java Tue Jul 23 16:06:11 2013 -0700 6.3 @@ -1,10 +1,11 @@ 6.4 /* 6.5 * @test /nodynamiccopyright/ 6.6 - * @bug 8020664 6.7 + * @bug 8020664 8021215 6.8 * @summary doclint gives incorrect warnings on normal package statements 6.9 * @library ../.. 6.10 * @build DocLintTester 6.11 * @run main DocLintTester -ref package-info.out package-info.java 6.12 + * @compile/fail/ref=package-info.javac.out -XDrawDiagnostics -Werror -Xdoclint:all package-info.java 6.13 */ 6.14 6.15 // missing comment
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/doclint/packageTests/bad/package-info.javac.out Tue Jul 23 16:06:11 2013 -0700 7.3 @@ -0,0 +1,4 @@ 7.4 +package-info.java:12:1: compiler.warn.proc.messager: no comment 7.5 +- compiler.err.warnings.and.werror 7.6 +1 error 7.7 +1 warning
8.1 --- a/test/tools/doclint/packageTests/bad/package-info.out Fri Jul 19 07:22:53 2013 -0700 8.2 +++ b/test/tools/doclint/packageTests/bad/package-info.out Tue Jul 23 16:06:11 2013 -0700 8.3 @@ -1,4 +1,4 @@ 8.4 -package-info.java:11: warning: no comment 8.5 +package-info.java:12: warning: no comment 8.6 package bad; 8.7 ^ 8.8 1 warning
9.1 --- a/test/tools/doclint/packageTests/good/Test.java Fri Jul 19 07:22:53 2013 -0700 9.2 +++ b/test/tools/doclint/packageTests/good/Test.java Tue Jul 23 16:06:11 2013 -0700 9.3 @@ -23,15 +23,17 @@ 9.4 9.5 /* 9.6 * @test /nodynamiccopyright/ 9.7 - * @bug 8020664 9.8 + * @bug 8020664 8021215 9.9 * @summary doclint gives incorrect warnings on normal package statements 9.10 * @library ../.. 9.11 * @build DocLintTester 9.12 * @run main DocLintTester Test.java 9.13 + * @compile -Xdoclint:all Test.java 9.14 */ 9.15 9.16 // no doc comment 9.17 package good; 9.18 9.19 +/** */ 9.20 class Test { } 9.21
10.1 --- a/test/tools/doclint/packageTests/good/package-info.java Fri Jul 19 07:22:53 2013 -0700 10.2 +++ b/test/tools/doclint/packageTests/good/package-info.java Tue Jul 23 16:06:11 2013 -0700 10.3 @@ -23,11 +23,12 @@ 10.4 10.5 /* 10.6 * @test /nodynamiccopyright/ 10.7 - * @bug 8020664 10.8 + * @bug 8020664 8021215 10.9 * @summary doclint gives incorrect warnings on normal package statements 10.10 * @library ../.. 10.11 * @build DocLintTester 10.12 * @run main DocLintTester package-info.java 10.13 + * @compile -Xdoclint:all package-info.java 10.14 */ 10.15 10.16 /** Description. */