8026368: doclint does not report empty tags when tag closed implicitly
Reviewed-by: darcy
--- a/langtools/src/share/classes/com/sun/tools/doclint/Checker.java Fri Oct 11 23:31:06 2013 -0700
+++ b/langtools/src/share/classes/com/sun/tools/doclint/Checker.java Mon Oct 14 12:38:09 2013 -0700
@@ -213,6 +213,7 @@
public Void visitDocComment(DocCommentTree tree, Void ignore) {
super.visitDocComment(tree, ignore);
for (TagStackItem tsi: tagStack) {
+ warnIfEmpty(tsi, null);
if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT
&& tsi.tag.endKind == HtmlTag.EndKind.REQUIRED) {
StartElementTree t = (StartElementTree) tsi.tree;
@@ -270,7 +271,6 @@
@Override
public Void visitStartElement(StartElementTree tree, Void ignore) {
- markEnclosingTag(Flag.HAS_ELEMENT);
final Name treeName = tree.getName();
final HtmlTag t = HtmlTag.get(treeName);
if (t == null) {
@@ -279,7 +279,10 @@
boolean done = false;
for (TagStackItem tsi: tagStack) {
if (tsi.tag.accepts(t)) {
- while (tagStack.peek() != tsi) tagStack.pop();
+ while (tagStack.peek() != tsi) {
+ warnIfEmpty(tagStack.peek(), null);
+ tagStack.pop();
+ }
done = true;
break;
} else if (tsi.tag.endKind != HtmlTag.EndKind.OPTIONAL) {
@@ -288,9 +291,13 @@
}
}
if (!done && HtmlTag.BODY.accepts(t)) {
- tagStack.clear();
+ while (!tagStack.isEmpty()) {
+ warnIfEmpty(tagStack.peek(), null);
+ tagStack.pop();
+ }
}
+ markEnclosingTag(Flag.HAS_ELEMENT);
checkStructure(tree, t);
// tag specific checks
@@ -447,12 +454,7 @@
"dc.no.summary.or.caption.for.table");
}
}
- 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_INLINE_TAG)) {
- env.messages.warning(HTML, tree, "dc.tag.empty", treeName);
- }
+ warnIfEmpty(top, tree);
tagStack.pop();
done = true;
break;
@@ -485,6 +487,20 @@
return super.visitEndElement(tree, ignore);
}
+
+ void warnIfEmpty(TagStackItem tsi, DocTree endTree) {
+ if (tsi.tag != null && tsi.tree instanceof StartElementTree) {
+ if (tsi.tag.flags.contains(HtmlTag.Flag.EXPECT_CONTENT)
+ && !tsi.flags.contains(Flag.HAS_TEXT)
+ && !tsi.flags.contains(Flag.HAS_ELEMENT)
+ && !tsi.flags.contains(Flag.HAS_INLINE_TAG)) {
+ DocTree tree = (endTree != null) ? endTree : tsi.tree;
+ Name treeName = ((StartElementTree) tsi.tree).getName();
+ env.messages.warning(HTML, tree, "dc.tag.empty", treeName);
+ }
+ }
+ }
+
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="HTML attributes">
--- a/langtools/test/tools/doclint/HtmlAttrsTest.java Fri Oct 11 23:31:06 2013 -0700
+++ b/langtools/test/tools/doclint/HtmlAttrsTest.java Mon Oct 14 12:38:09 2013 -0700
@@ -10,7 +10,7 @@
/** */
public class HtmlAttrsTest {
/**
- * <p xyz>
+ * <p xyz> text </p>
*/
public void unknown() { }
--- a/langtools/test/tools/doclint/HtmlAttrsTest.out Fri Oct 11 23:31:06 2013 -0700
+++ b/langtools/test/tools/doclint/HtmlAttrsTest.out Mon Oct 14 12:38:09 2013 -0700
@@ -1,5 +1,5 @@
HtmlAttrsTest.java:13: error: unknown attribute: xyz
- * <p xyz>
+ * <p xyz> text </p>
^
HtmlAttrsTest.java:18: warning: attribute obsolete: name
* <img name="x" alt="alt">
--- a/langtools/test/tools/doclint/tidy/BadEnd.out Fri Oct 11 23:31:06 2013 -0700
+++ b/langtools/test/tools/doclint/tidy/BadEnd.out Mon Oct 14 12:38:09 2013 -0700
@@ -1,6 +1,9 @@
BadEnd.java:14: warning: nested tag not allowed: <code>
* <code> text <code>
^
+BadEnd.java:14: warning: empty <code> tag
+ * <code> text <code>
+ ^
BadEnd.java:14: error: element not closed: code
* <code> text <code>
^
@@ -14,4 +17,4 @@
* <a name="here"> text <a>
^
4 errors
-1 warning
+2 warnings
--- a/langtools/test/tools/doclint/tidy/TrimmingEmptyTag.java Fri Oct 11 23:31:06 2013 -0700
+++ b/langtools/test/tools/doclint/tidy/TrimmingEmptyTag.java Mon Oct 14 12:38:09 2013 -0700
@@ -1,6 +1,6 @@
/*
* @test /nodynamiccopyright/
- * @bug 8004832
+ * @bug 8004832 8026368
* @summary Add new doclint package
* @library ..
* @build DocLintTester
@@ -26,4 +26,9 @@
* <ul></ul>
* <ul><li></li></ul>
*/
-public class TrimmingEmptyTag { }
+public class TrimmingEmptyTag {
+ /** <p> */
+ public void implicitParaEnd_endOfComment() { }
+ /** <p> <ul><li>text</ul> */
+ public void implicitParaEnd_nextBlockTag() { }
+}
--- a/langtools/test/tools/doclint/tidy/TrimmingEmptyTag.out Fri Oct 11 23:31:06 2013 -0700
+++ b/langtools/test/tools/doclint/tidy/TrimmingEmptyTag.out Mon Oct 14 12:38:09 2013 -0700
@@ -43,4 +43,10 @@
TrimmingEmptyTag.java:26: warning: empty <ul> tag
* <ul></ul>
^
-15 warnings
+TrimmingEmptyTag.java:30: warning: empty <p> tag
+ /** <p> */
+ ^
+TrimmingEmptyTag.java:32: warning: empty <p> tag
+ /** <p> <ul><li>text</ul> */
+ ^
+17 warnings