diff -r 0a9f5cbe37d9 -r 129751018061 src/share/classes/com/sun/tools/doclint/Checker.java --- a/src/share/classes/com/sun/tools/doclint/Checker.java Fri Jul 19 07:22:53 2013 -0700 +++ b/src/share/classes/com/sun/tools/doclint/Checker.java Tue Jul 23 16:06:11 2013 -0700 @@ -141,10 +141,27 @@ 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 @@ 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);