From c979f97eeca5edbfd90941c7a9914d4e16c903bb Mon Sep 17 00:00:00 2001 From: jjg Date: Tue, 19 Mar 2013 19:16:59 -0700 Subject: [PATCH] 8010317: DocLint incorrectly reports some
 tags as empty
 Reviewed-by: darcy

---
 .../com/sun/tools/doclint/Checker.java        | 35 +++++++++++----
 test/tools/doclint/EmptyPreTest.java          | 44 +++++++++++++++++++
 2 files changed, 71 insertions(+), 8 deletions(-)
 create mode 100644 test/tools/doclint/EmptyPreTest.java

diff --git a/src/share/classes/com/sun/tools/doclint/Checker.java b/src/share/classes/com/sun/tools/doclint/Checker.java
index 5969a10a..716845d1 100644
--- a/src/share/classes/com/sun/tools/doclint/Checker.java
+++ b/src/share/classes/com/sun/tools/doclint/Checker.java
@@ -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.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.URI;
+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 javax.tools.Diagnostic.Kind;
 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.SinceTree;
 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 class Checker extends DocTreeScanner {
     public enum Flag {
         TABLE_HAS_CAPTION,
         HAS_ELEMENT,
+        HAS_INLINE_TAG,
         HAS_TEXT,
         REPORTED_BAD_INLINE
     }
@@ -418,7 +421,8 @@ public class Checker extends DocTreeScanner {
                     }
                     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();
@@ -570,8 +574,15 @@ public class Checker extends DocTreeScanner {
         return super.visitAuthor(tree, ignore);
     }
 
+    @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 @@ public class Checker extends DocTreeScanner {
 
     @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 @@ public class Checker extends DocTreeScanner {
 
     @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) {
@@ -745,6 +758,12 @@ public class Checker extends DocTreeScanner {
         }
     }
 
+    @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());
diff --git a/test/tools/doclint/EmptyPreTest.java b/test/tools/doclint/EmptyPreTest.java
new file mode 100644
index 00000000..ada4995f
--- /dev/null
+++ b/test/tools/doclint/EmptyPreTest.java
@@ -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 
 tags as empty
+ * @build DocLintTester
+ * @run main DocLintTester -Xmsgs:html EmptyPreTest.java
+ */
+
+public class EmptyPreTest {
+    /** 
 {@code xyzzy} 
*/ + public void m1() { } + + /**
 {@docRoot} 
*/ + public void m2() { } + + /**
 {@link java.lang.String} 
*/ + public void m3() { } + + /**
 {@value} 
*/ + public static final int v1 = 1; +} -- GitLab