8010317: DocLint incorrectly reports some <pre> tags as empty
authorjjg
Tue, 19 Mar 2013 19:16:59 -0700
changeset 16562 9f09744e221a
parent 16561 05845a6d80a9
child 16563 c0b12eae2488
8010317: DocLint incorrectly reports some <pre> tags as empty Reviewed-by: darcy
langtools/src/share/classes/com/sun/tools/doclint/Checker.java
langtools/test/tools/doclint/EmptyPreTest.java
--- a/langtools/src/share/classes/com/sun/tools/doclint/Checker.java	Tue Mar 19 17:05:57 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclint/Checker.java	Tue Mar 19 19:16:59 2013 -0700
@@ -25,20 +25,18 @@
 
 package com.sun.tools.doclint;
 
-import com.sun.source.doctree.LiteralTree;
-import java.util.regex.Matcher;
-import com.sun.source.doctree.LinkTree;
+import java.io.IOException;
+import java.io.StringWriter;
 import java.net.URI;
-import java.util.regex.Pattern;
-import java.io.IOException;
-import com.sun.tools.javac.tree.DocPretty;
-import java.io.StringWriter;
+import java.net.URISyntaxException;
 import java.util.Deque;
 import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.lang.model.element.Element;
 import javax.lang.model.element.ElementKind;
@@ -52,12 +50,15 @@
 import com.sun.source.doctree.AttributeTree;
 import com.sun.source.doctree.AuthorTree;
 import com.sun.source.doctree.DocCommentTree;
+import com.sun.source.doctree.DocRootTree;
 import com.sun.source.doctree.DocTree;
 import com.sun.source.doctree.EndElementTree;
 import com.sun.source.doctree.EntityTree;
 import com.sun.source.doctree.ErroneousTree;
 import com.sun.source.doctree.IdentifierTree;
 import com.sun.source.doctree.InheritDocTree;
+import com.sun.source.doctree.LinkTree;
+import com.sun.source.doctree.LiteralTree;
 import com.sun.source.doctree.ParamTree;
 import com.sun.source.doctree.ReferenceTree;
 import com.sun.source.doctree.ReturnTree;
@@ -67,11 +68,12 @@
 import com.sun.source.doctree.StartElementTree;
 import com.sun.source.doctree.TextTree;
 import com.sun.source.doctree.ThrowsTree;
+import com.sun.source.doctree.ValueTree;
 import com.sun.source.doctree.VersionTree;
 import com.sun.source.util.DocTreeScanner;
 import com.sun.source.util.TreePath;
 import com.sun.tools.doclint.HtmlTag.AttrKind;
-import java.net.URISyntaxException;
+import com.sun.tools.javac.tree.DocPretty;
 import static com.sun.tools.doclint.Messages.Group.*;
 
 
@@ -95,6 +97,7 @@
     public enum Flag {
         TABLE_HAS_CAPTION,
         HAS_ELEMENT,
+        HAS_INLINE_TAG,
         HAS_TEXT,
         REPORTED_BAD_INLINE
     }
@@ -418,7 +421,8 @@
                     }
                     if (t.flags.contains(HtmlTag.Flag.EXPECT_CONTENT)
                             && !top.flags.contains(Flag.HAS_TEXT)
-                            && !top.flags.contains(Flag.HAS_ELEMENT)) {
+                            && !top.flags.contains(Flag.HAS_ELEMENT)
+                            && !top.flags.contains(Flag.HAS_INLINE_TAG)) {
                         env.messages.warning(HTML, tree, "dc.tag.empty", treeName);
                     }
                     tagStack.pop();
@@ -571,7 +575,14 @@
     }
 
     @Override
+    public Void visitDocRoot(DocRootTree tree, Void ignore) {
+        markEnclosingTag(Flag.HAS_INLINE_TAG);
+        return super.visitDocRoot(tree, ignore);
+    }
+
+    @Override
     public Void visitInheritDoc(InheritDocTree tree, Void ignore) {
+        markEnclosingTag(Flag.HAS_INLINE_TAG);
         // TODO: verify on overridden method
         foundInheritDoc = true;
         return super.visitInheritDoc(tree, ignore);
@@ -579,6 +590,7 @@
 
     @Override
     public Void visitLink(LinkTree tree, Void ignore) {
+        markEnclosingTag(Flag.HAS_INLINE_TAG);
         // simulate inline context on tag stack
         HtmlTag t = (tree.getKind() == DocTree.Kind.LINK)
                 ? HtmlTag.CODE : HtmlTag.SPAN;
@@ -592,6 +604,7 @@
 
     @Override
     public Void visitLiteral(LiteralTree tree, Void ignore) {
+        markEnclosingTag(Flag.HAS_INLINE_TAG);
         if (tree.getKind() == DocTree.Kind.CODE) {
             for (TagStackItem tsi: tagStack) {
                 if (tsi.tag == HtmlTag.CODE) {
@@ -746,6 +759,12 @@
     }
 
     @Override
+    public Void visitValue(ValueTree tree, Void ignore) {
+        markEnclosingTag(Flag.HAS_INLINE_TAG);
+        return super.visitValue(tree, ignore);
+    }
+
+    @Override
     public Void visitVersion(VersionTree tree, Void ignore) {
         warnIfEmpty(tree, tree.getBody());
         return super.visitVersion(tree, ignore);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/EmptyPreTest.java	Tue Mar 19 19:16:59 2013 -0700
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8010317
+ * @summary DocLint incorrectly reports some <pre> tags as empty
+ * @build DocLintTester
+ * @run main DocLintTester -Xmsgs:html EmptyPreTest.java
+ */
+
+public class EmptyPreTest {
+    /** <pre> {@code xyzzy} </pre> */
+    public void m1() { }
+
+    /** <pre> {@docRoot} </pre> */
+    public void m2() { }
+
+    /** <pre> {@link java.lang.String} </pre> */
+    public void m3() { }
+
+    /** <pre> {@value} </pre> */
+    public static final int v1 = 1;
+}