Wed, 17 Jul 2013 19:16:12 -0700
8020664: doclint gives incorrect warnings on normal package statements
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/doclint/DocLint.java Wed Jul 17 19:12:03 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclint/DocLint.java Wed Jul 17 19:16:12 2013 -0700 1.3 @@ -30,9 +30,10 @@ 1.4 import java.io.PrintWriter; 1.5 import java.util.ArrayList; 1.6 import java.util.List; 1.7 -import java.util.regex.Pattern; 1.8 1.9 import javax.lang.model.element.Name; 1.10 +import javax.tools.Diagnostic; 1.11 +import javax.tools.JavaFileObject; 1.12 import javax.tools.StandardLocation; 1.13 1.14 import com.sun.source.doctree.DocCommentTree; 1.15 @@ -151,6 +152,18 @@ 1.16 TreePath p = getCurrentPath(); 1.17 DocCommentTree dc = env.trees.getDocCommentTree(p); 1.18 1.19 + if (p.getLeaf() == p.getCompilationUnit()) { 1.20 + JavaFileObject fo = p.getCompilationUnit().getSourceFile(); 1.21 + boolean pkgInfo = fo.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE); 1.22 + if (!pkgInfo) { 1.23 + if (dc == null) 1.24 + return; 1.25 + env.setCurrent(p, dc); 1.26 + env.messages.report(Messages.Group.REFERENCE, Diagnostic.Kind.WARNING, p.getLeaf(), 1.27 + "dc.unexpected.comment"); 1.28 + } 1.29 + } 1.30 + 1.31 checker.scan(dc, p); 1.32 } 1.33 }; 1.34 @@ -166,8 +179,8 @@ 1.35 } 1.36 1.37 void processArgs(String... args) throws BadArgs { 1.38 - javacOpts = new ArrayList<String>(); 1.39 - javacFiles = new ArrayList<File>(); 1.40 + javacOpts = new ArrayList<>(); 1.41 + javacFiles = new ArrayList<>(); 1.42 1.43 if (args.length == 0) 1.44 needHelp = true; 1.45 @@ -214,7 +227,7 @@ 1.46 } 1.47 1.48 List<File> splitPath(String path) { 1.49 - List<File> files = new ArrayList<File>(); 1.50 + List<File> files = new ArrayList<>(); 1.51 for (String f: path.split(File.pathSeparator)) { 1.52 if (f.length() > 0) 1.53 files.add(new File(f)); 1.54 @@ -279,7 +292,6 @@ 1.55 TaskListener tl = new TaskListener() { 1.56 @Override 1.57 public void started(TaskEvent e) { 1.58 - return; 1.59 } 1.60 1.61 @Override
2.1 --- a/src/share/classes/com/sun/tools/doclint/resources/doclint.properties Wed Jul 17 19:12:03 2013 -0700 2.2 +++ b/src/share/classes/com/sun/tools/doclint/resources/doclint.properties Wed Jul 17 19:16:12 2013 -0700 2.3 @@ -67,6 +67,7 @@ 2.4 dc.tag.start.unmatched = end tag missing: </{0}> 2.5 dc.tag.unknown = unknown tag: {0} 2.6 dc.text.not.allowed = text not allowed in <{0}> element 2.7 +dc.unexpected.comment=documentation comment not expected here 2.8 2.9 dc.main.ioerror=IO error: {0} 2.10 dc.main.no.files.given=No files given
3.1 --- a/test/tools/doclint/BadPackageCommentTest.out Wed Jul 17 19:12:03 2013 -0700 3.2 +++ b/test/tools/doclint/BadPackageCommentTest.out Wed Jul 17 19:16:12 2013 -0700 3.3 @@ -1,3 +1,6 @@ 3.4 +BadPackageCommentTest.java:13: warning: documentation comment not expected here 3.5 +package p; 3.6 +^ 3.7 BadPackageCommentTest.java:11: error: no tag name after @ 3.8 * @@@ 3.9 ^ 3.10 @@ -8,3 +11,4 @@ 3.11 * @@@ 3.12 ^ 3.13 3 errors 3.14 +1 warning
4.1 --- a/test/tools/doclint/DocLintTester.java Wed Jul 17 19:12:03 2013 -0700 4.2 +++ b/test/tools/doclint/DocLintTester.java Wed Jul 17 19:16:12 2013 -0700 4.3 @@ -123,7 +123,7 @@ 4.4 private static final Pattern dirFileLine = Pattern.compile( 4.5 "(?m)" // multi-line mode 4.6 + "^(.*?)" // directory part of file name 4.7 - + "([A-Za-z0-9.]+:[0-9]+:)"); // file name and line number 4.8 + + "([-A-Za-z0-9.]+:[0-9]+:)"); // file name and line number 4.9 4.10 String removeFileNames(String s) { 4.11 Matcher m = dirFileLine.matcher(s);
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/test/tools/doclint/packageTests/bad/Test.java Wed Jul 17 19:16:12 2013 -0700 5.3 @@ -0,0 +1,14 @@ 5.4 +/* 5.5 + * @test /nodynamiccopyright/ 5.6 + * @bug 8020664 5.7 + * @summary doclint gives incorrect warnings on normal package statements 5.8 + * @library ../.. 5.9 + * @build DocLintTester 5.10 + * @run main DocLintTester -ref Test.out Test.java 5.11 + */ 5.12 + 5.13 +/** Unexpected comment */ 5.14 +package bad; 5.15 + 5.16 +class Test { } 5.17 +
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/test/tools/doclint/packageTests/bad/Test.out Wed Jul 17 19:16:12 2013 -0700 6.3 @@ -0,0 +1,4 @@ 6.4 +Test.java:11: warning: documentation comment not expected here 6.5 +package bad; 6.6 +^ 6.7 +1 warning
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/test/tools/doclint/packageTests/bad/package-info.java Wed Jul 17 19:16:12 2013 -0700 7.3 @@ -0,0 +1,11 @@ 7.4 +/* 7.5 + * @test /nodynamiccopyright/ 7.6 + * @bug 8020664 7.7 + * @summary doclint gives incorrect warnings on normal package statements 7.8 + * @library ../.. 7.9 + * @build DocLintTester 7.10 + * @run main DocLintTester -ref package-info.out package-info.java 7.11 + */ 7.12 + 7.13 +// missing comment 7.14 +package bad;
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/test/tools/doclint/packageTests/bad/package-info.out Wed Jul 17 19:16:12 2013 -0700 8.3 @@ -0,0 +1,4 @@ 8.4 +package-info.java:11: warning: no comment 8.5 +package bad; 8.6 +^ 8.7 +1 warning
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/test/tools/doclint/packageTests/good/Test.java Wed Jul 17 19:16:12 2013 -0700 9.3 @@ -0,0 +1,37 @@ 9.4 +/* 9.5 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.7 + * 9.8 + * This code is free software; you can redistribute it and/or modify it 9.9 + * under the terms of the GNU General Public License version 2 only, as 9.10 + * published by the Free Software Foundation. 9.11 + * 9.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 9.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 9.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 9.15 + * version 2 for more details (a copy is included in the LICENSE file that 9.16 + * accompanied this code). 9.17 + * 9.18 + * You should have received a copy of the GNU General Public License version 9.19 + * 2 along with this work; if not, write to the Free Software Foundation, 9.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 9.21 + * 9.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 9.23 + * or visit www.oracle.com if you need additional information or have any 9.24 + * questions. 9.25 + */ 9.26 + 9.27 +/* 9.28 + * @test /nodynamiccopyright/ 9.29 + * @bug 8020664 9.30 + * @summary doclint gives incorrect warnings on normal package statements 9.31 + * @library ../.. 9.32 + * @build DocLintTester 9.33 + * @run main DocLintTester Test.java 9.34 + */ 9.35 + 9.36 +// no doc comment 9.37 +package good; 9.38 + 9.39 +class Test { } 9.40 +
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/test/tools/doclint/packageTests/good/package-info.java Wed Jul 17 19:16:12 2013 -0700 10.3 @@ -0,0 +1,34 @@ 10.4 +/* 10.5 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 + * 10.8 + * This code is free software; you can redistribute it and/or modify it 10.9 + * under the terms of the GNU General Public License version 2 only, as 10.10 + * published by the Free Software Foundation. 10.11 + * 10.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 10.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.15 + * version 2 for more details (a copy is included in the LICENSE file that 10.16 + * accompanied this code). 10.17 + * 10.18 + * You should have received a copy of the GNU General Public License version 10.19 + * 2 along with this work; if not, write to the Free Software Foundation, 10.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.21 + * 10.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 10.23 + * or visit www.oracle.com if you need additional information or have any 10.24 + * questions. 10.25 + */ 10.26 + 10.27 +/* 10.28 + * @test /nodynamiccopyright/ 10.29 + * @bug 8020664 10.30 + * @summary doclint gives incorrect warnings on normal package statements 10.31 + * @library ../.. 10.32 + * @build DocLintTester 10.33 + * @run main DocLintTester package-info.java 10.34 + */ 10.35 + 10.36 +/** Description. */ 10.37 +package good;