Tue, 19 Mar 2013 19:16:59 -0700
8010317: DocLint incorrectly reports some <pre> tags as empty
Reviewed-by: darcy
src/share/classes/com/sun/tools/doclint/Checker.java | file | annotate | diff | comparison | revisions | |
test/tools/doclint/EmptyPreTest.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/doclint/Checker.java Tue Mar 19 17:05:57 2013 -0700 1.2 +++ b/src/share/classes/com/sun/tools/doclint/Checker.java Tue Mar 19 19:16:59 2013 -0700 1.3 @@ -25,20 +25,18 @@ 1.4 1.5 package com.sun.tools.doclint; 1.6 1.7 -import com.sun.source.doctree.LiteralTree; 1.8 -import java.util.regex.Matcher; 1.9 -import com.sun.source.doctree.LinkTree; 1.10 +import java.io.IOException; 1.11 +import java.io.StringWriter; 1.12 import java.net.URI; 1.13 -import java.util.regex.Pattern; 1.14 -import java.io.IOException; 1.15 -import com.sun.tools.javac.tree.DocPretty; 1.16 -import java.io.StringWriter; 1.17 +import java.net.URISyntaxException; 1.18 import java.util.Deque; 1.19 import java.util.EnumSet; 1.20 import java.util.HashSet; 1.21 import java.util.LinkedList; 1.22 import java.util.List; 1.23 import java.util.Set; 1.24 +import java.util.regex.Matcher; 1.25 +import java.util.regex.Pattern; 1.26 1.27 import javax.lang.model.element.Element; 1.28 import javax.lang.model.element.ElementKind; 1.29 @@ -52,12 +50,15 @@ 1.30 import com.sun.source.doctree.AttributeTree; 1.31 import com.sun.source.doctree.AuthorTree; 1.32 import com.sun.source.doctree.DocCommentTree; 1.33 +import com.sun.source.doctree.DocRootTree; 1.34 import com.sun.source.doctree.DocTree; 1.35 import com.sun.source.doctree.EndElementTree; 1.36 import com.sun.source.doctree.EntityTree; 1.37 import com.sun.source.doctree.ErroneousTree; 1.38 import com.sun.source.doctree.IdentifierTree; 1.39 import com.sun.source.doctree.InheritDocTree; 1.40 +import com.sun.source.doctree.LinkTree; 1.41 +import com.sun.source.doctree.LiteralTree; 1.42 import com.sun.source.doctree.ParamTree; 1.43 import com.sun.source.doctree.ReferenceTree; 1.44 import com.sun.source.doctree.ReturnTree; 1.45 @@ -67,11 +68,12 @@ 1.46 import com.sun.source.doctree.StartElementTree; 1.47 import com.sun.source.doctree.TextTree; 1.48 import com.sun.source.doctree.ThrowsTree; 1.49 +import com.sun.source.doctree.ValueTree; 1.50 import com.sun.source.doctree.VersionTree; 1.51 import com.sun.source.util.DocTreeScanner; 1.52 import com.sun.source.util.TreePath; 1.53 import com.sun.tools.doclint.HtmlTag.AttrKind; 1.54 -import java.net.URISyntaxException; 1.55 +import com.sun.tools.javac.tree.DocPretty; 1.56 import static com.sun.tools.doclint.Messages.Group.*; 1.57 1.58 1.59 @@ -95,6 +97,7 @@ 1.60 public enum Flag { 1.61 TABLE_HAS_CAPTION, 1.62 HAS_ELEMENT, 1.63 + HAS_INLINE_TAG, 1.64 HAS_TEXT, 1.65 REPORTED_BAD_INLINE 1.66 } 1.67 @@ -418,7 +421,8 @@ 1.68 } 1.69 if (t.flags.contains(HtmlTag.Flag.EXPECT_CONTENT) 1.70 && !top.flags.contains(Flag.HAS_TEXT) 1.71 - && !top.flags.contains(Flag.HAS_ELEMENT)) { 1.72 + && !top.flags.contains(Flag.HAS_ELEMENT) 1.73 + && !top.flags.contains(Flag.HAS_INLINE_TAG)) { 1.74 env.messages.warning(HTML, tree, "dc.tag.empty", treeName); 1.75 } 1.76 tagStack.pop(); 1.77 @@ -571,7 +575,14 @@ 1.78 } 1.79 1.80 @Override 1.81 + public Void visitDocRoot(DocRootTree tree, Void ignore) { 1.82 + markEnclosingTag(Flag.HAS_INLINE_TAG); 1.83 + return super.visitDocRoot(tree, ignore); 1.84 + } 1.85 + 1.86 + @Override 1.87 public Void visitInheritDoc(InheritDocTree tree, Void ignore) { 1.88 + markEnclosingTag(Flag.HAS_INLINE_TAG); 1.89 // TODO: verify on overridden method 1.90 foundInheritDoc = true; 1.91 return super.visitInheritDoc(tree, ignore); 1.92 @@ -579,6 +590,7 @@ 1.93 1.94 @Override 1.95 public Void visitLink(LinkTree tree, Void ignore) { 1.96 + markEnclosingTag(Flag.HAS_INLINE_TAG); 1.97 // simulate inline context on tag stack 1.98 HtmlTag t = (tree.getKind() == DocTree.Kind.LINK) 1.99 ? HtmlTag.CODE : HtmlTag.SPAN; 1.100 @@ -592,6 +604,7 @@ 1.101 1.102 @Override 1.103 public Void visitLiteral(LiteralTree tree, Void ignore) { 1.104 + markEnclosingTag(Flag.HAS_INLINE_TAG); 1.105 if (tree.getKind() == DocTree.Kind.CODE) { 1.106 for (TagStackItem tsi: tagStack) { 1.107 if (tsi.tag == HtmlTag.CODE) { 1.108 @@ -746,6 +759,12 @@ 1.109 } 1.110 1.111 @Override 1.112 + public Void visitValue(ValueTree tree, Void ignore) { 1.113 + markEnclosingTag(Flag.HAS_INLINE_TAG); 1.114 + return super.visitValue(tree, ignore); 1.115 + } 1.116 + 1.117 + @Override 1.118 public Void visitVersion(VersionTree tree, Void ignore) { 1.119 warnIfEmpty(tree, tree.getBody()); 1.120 return super.visitVersion(tree, ignore);
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/doclint/EmptyPreTest.java Tue Mar 19 19:16:59 2013 -0700 2.3 @@ -0,0 +1,44 @@ 2.4 +/* 2.5 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8010317 2.30 + * @summary DocLint incorrectly reports some <pre> tags as empty 2.31 + * @build DocLintTester 2.32 + * @run main DocLintTester -Xmsgs:html EmptyPreTest.java 2.33 + */ 2.34 + 2.35 +public class EmptyPreTest { 2.36 + /** <pre> {@code xyzzy} </pre> */ 2.37 + public void m1() { } 2.38 + 2.39 + /** <pre> {@docRoot} </pre> */ 2.40 + public void m2() { } 2.41 + 2.42 + /** <pre> {@link java.lang.String} </pre> */ 2.43 + public void m3() { } 2.44 + 2.45 + /** <pre> {@value} </pre> */ 2.46 + public static final int v1 = 1; 2.47 +}