diff --git a/src/share/classes/com/sun/tools/doclint/Checker.java b/src/share/classes/com/sun/tools/doclint/Checker.java index ece896cc6b42dc32daca9419793c76e5e9f6f318..9b75c83abf1e1380fdca5902b632f7d0c049ff93 100644 --- a/src/share/classes/com/sun/tools/doclint/Checker.java +++ b/src/share/classes/com/sun/tools/doclint/Checker.java @@ -141,10 +141,27 @@ public class Checker extends DocTreePathScanner { boolean isOverridingMethod = !env.currOverriddenMethods.isEmpty(); - if (tree == null) { - if (!isSynthetic() && !isOverridingMethod) - reportMissing("dc.missing.comment"); - return null; + if (p.getLeaf() == p.getCompilationUnit()) { + // If p points to a compilation unit, the implied declaration is the + // package declaration (if any) for the compilation unit. + // Handle this case specially, because doc comments are only + // expected in package-info files. + JavaFileObject fo = p.getCompilationUnit().getSourceFile(); + boolean isPkgInfo = fo.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE); + if (tree == null) { + if (isPkgInfo) + reportMissing("dc.missing.comment"); + return null; + } else { + if (!isPkgInfo) + reportReference("dc.unexpected.comment"); + } + } else { + if (tree == null) { + if (!isSynthetic() && !isOverridingMethod) + reportMissing("dc.missing.comment"); + return null; + } } tagStack.clear(); @@ -187,6 +204,10 @@ public class Checker extends DocTreePathScanner { env.messages.report(MISSING, Kind.WARNING, env.currPath.getLeaf(), code, args); } + private void reportReference(String code, Object... args) { + env.messages.report(REFERENCE, Kind.WARNING, env.currPath.getLeaf(), code, args); + } + @Override public Void visitDocComment(DocCommentTree tree, Void ignore) { super.visitDocComment(tree, ignore); diff --git a/src/share/classes/com/sun/tools/doclint/DocLint.java b/src/share/classes/com/sun/tools/doclint/DocLint.java index ca448ebe2a8905b8bd73a1e1bb3bf7a4689c9c8e..20151d1f36005b6a21a5e709e75058e70f823342 100644 --- a/src/share/classes/com/sun/tools/doclint/DocLint.java +++ b/src/share/classes/com/sun/tools/doclint/DocLint.java @@ -32,8 +32,6 @@ import java.util.ArrayList; import java.util.List; import javax.lang.model.element.Name; -import javax.tools.Diagnostic; -import javax.tools.JavaFileObject; import javax.tools.StandardLocation; import com.sun.source.doctree.DocCommentTree; @@ -152,18 +150,6 @@ public class DocLint implements Plugin { TreePath p = getCurrentPath(); DocCommentTree dc = env.trees.getDocCommentTree(p); - if (p.getLeaf() == p.getCompilationUnit()) { - JavaFileObject fo = p.getCompilationUnit().getSourceFile(); - boolean pkgInfo = fo.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE); - if (!pkgInfo) { - if (dc == null) - return; - env.setCurrent(p, dc); - env.messages.report(Messages.Group.REFERENCE, Diagnostic.Kind.WARNING, p.getLeaf(), - "dc.unexpected.comment"); - } - } - checker.scan(dc, p); } }; diff --git a/test/tools/doclint/packageTests/bad/Test.java b/test/tools/doclint/packageTests/bad/Test.java index 25ce3621acb81100a938816927a7ce80ac2509f2..83706d30fd54a1169e43cfe962239a403272bbaf 100644 --- a/test/tools/doclint/packageTests/bad/Test.java +++ b/test/tools/doclint/packageTests/bad/Test.java @@ -1,14 +1,16 @@ /* * @test /nodynamiccopyright/ - * @bug 8020664 + * @bug 8020664 8021215 * @summary doclint gives incorrect warnings on normal package statements * @library ../.. * @build DocLintTester * @run main DocLintTester -ref Test.out Test.java + * @compile/fail/ref=Test.javac.out -XDrawDiagnostics -Werror -Xdoclint:all Test.java */ /** Unexpected comment */ package bad; +/** */ class Test { } diff --git a/test/tools/doclint/packageTests/bad/Test.javac.out b/test/tools/doclint/packageTests/bad/Test.javac.out new file mode 100644 index 0000000000000000000000000000000000000000..0967f4de35a47cfe4d694e12947795e5e800d47e --- /dev/null +++ b/test/tools/doclint/packageTests/bad/Test.javac.out @@ -0,0 +1,4 @@ +Test.java:12:1: compiler.warn.proc.messager: documentation comment not expected here +- compiler.err.warnings.and.werror +1 error +1 warning diff --git a/test/tools/doclint/packageTests/bad/Test.out b/test/tools/doclint/packageTests/bad/Test.out index de980ea002867fda99de79b1cbd79fd66e408713..76a5512195697ec9db6b2378d8117175ee625e69 100644 --- a/test/tools/doclint/packageTests/bad/Test.out +++ b/test/tools/doclint/packageTests/bad/Test.out @@ -1,4 +1,4 @@ -Test.java:11: warning: documentation comment not expected here +Test.java:12: warning: documentation comment not expected here package bad; ^ 1 warning diff --git a/test/tools/doclint/packageTests/bad/package-info.java b/test/tools/doclint/packageTests/bad/package-info.java index 9ebdbbc990f4185eb334df70072affe5e6ea8512..2653c89b8b58632adb5dda754562cd8bdba34612 100644 --- a/test/tools/doclint/packageTests/bad/package-info.java +++ b/test/tools/doclint/packageTests/bad/package-info.java @@ -1,10 +1,11 @@ /* * @test /nodynamiccopyright/ - * @bug 8020664 + * @bug 8020664 8021215 * @summary doclint gives incorrect warnings on normal package statements * @library ../.. * @build DocLintTester * @run main DocLintTester -ref package-info.out package-info.java + * @compile/fail/ref=package-info.javac.out -XDrawDiagnostics -Werror -Xdoclint:all package-info.java */ // missing comment diff --git a/test/tools/doclint/packageTests/bad/package-info.javac.out b/test/tools/doclint/packageTests/bad/package-info.javac.out new file mode 100644 index 0000000000000000000000000000000000000000..184eb41d017b4a20cf9a58d6abc8e9cb81b596ca --- /dev/null +++ b/test/tools/doclint/packageTests/bad/package-info.javac.out @@ -0,0 +1,4 @@ +package-info.java:12:1: compiler.warn.proc.messager: no comment +- compiler.err.warnings.and.werror +1 error +1 warning diff --git a/test/tools/doclint/packageTests/bad/package-info.out b/test/tools/doclint/packageTests/bad/package-info.out index fd4377caadb2b4ce8d726176ac6c4d44cf683282..1d07cd65ba0200668f2bd6caebd4450b96c37dd2 100644 --- a/test/tools/doclint/packageTests/bad/package-info.out +++ b/test/tools/doclint/packageTests/bad/package-info.out @@ -1,4 +1,4 @@ -package-info.java:11: warning: no comment +package-info.java:12: warning: no comment package bad; ^ 1 warning diff --git a/test/tools/doclint/packageTests/good/Test.java b/test/tools/doclint/packageTests/good/Test.java index 84db8d5ee8ecd200d46eee0c51998665a9650084..223d89a3bf32d671c9f970fb66837b2f00dc3ea3 100644 --- a/test/tools/doclint/packageTests/good/Test.java +++ b/test/tools/doclint/packageTests/good/Test.java @@ -23,15 +23,17 @@ /* * @test /nodynamiccopyright/ - * @bug 8020664 + * @bug 8020664 8021215 * @summary doclint gives incorrect warnings on normal package statements * @library ../.. * @build DocLintTester * @run main DocLintTester Test.java + * @compile -Xdoclint:all Test.java */ // no doc comment package good; +/** */ class Test { } diff --git a/test/tools/doclint/packageTests/good/package-info.java b/test/tools/doclint/packageTests/good/package-info.java index 598feaed23cca38bf087f15572e75736267ff82f..d60412d91eefe5c4d7eba6404db5f1ed753eb229 100644 --- a/test/tools/doclint/packageTests/good/package-info.java +++ b/test/tools/doclint/packageTests/good/package-info.java @@ -23,11 +23,12 @@ /* * @test /nodynamiccopyright/ - * @bug 8020664 + * @bug 8020664 8021215 * @summary doclint gives incorrect warnings on normal package statements * @library ../.. * @build DocLintTester * @run main DocLintTester package-info.java + * @compile -Xdoclint:all package-info.java */ /** Description. */