aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jonathan Gibbons <jjg@openjdk.org> 2021-03-24 23:58:16 +0000
committerGravatar Jonathan Gibbons <jjg@openjdk.org> 2021-03-24 23:58:16 +0000
commit0ff81682e63fe2964fee7149b70baa299169894a (patch)
treeabd2a472402a68dc981daf18e666dfe2e6c516f1
parent3d7f91223ec925e037fa4b22164cc1d0c97d08d9 (diff)
downloadjdk-0ff81682e63fe2964fee7149b70baa299169894a.tar.gz
jdk-0ff81682e63fe2964fee7149b70baa299169894a.zip
8258957: DocLint: check for HTML start element at end of body
Reviewed-by: vromero
-rw-r--r--src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Checker.java17
-rw-r--r--test/langtools/tools/doclint/EmptyTagsTest.java45
-rw-r--r--test/langtools/tools/doclint/EmptyTagsTest.out16
-rw-r--r--test/langtools/tools/doclint/EndTagsTest.out4
-rw-r--r--test/langtools/tools/doclint/HtmlTagsTest.out5
5 files changed, 84 insertions, 3 deletions
diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Checker.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Checker.java
index 94d91c5cb83..1150b43b854 100644
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Checker.java
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Checker.java
@@ -269,7 +269,20 @@ public class Checker extends DocTreePathScanner<Void, Void> {
@Override @DefinedBy(Api.COMPILER_TREE)
public Void visitDocComment(DocCommentTree tree, Void ignore) {
- super.visitDocComment(tree, ignore);
+ scan(tree.getFirstSentence(), ignore);
+ scan(tree.getBody(), ignore);
+ checkTagStack();
+
+ for (DocTree blockTag : tree.getBlockTags()) {
+ tagStack.clear();
+ scan(blockTag, ignore);
+ checkTagStack();
+ }
+
+ return null;
+ }
+
+ private void checkTagStack() {
for (TagStackItem tsi: tagStack) {
warnIfEmpty(tsi, null);
if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT
@@ -278,7 +291,6 @@ public class Checker extends DocTreePathScanner<Void, Void> {
env.messages.error(HTML, t, "dc.tag.not.closed", t.getName());
}
}
- return null;
}
// </editor-fold>
@@ -548,6 +560,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
done = true;
break;
} else if (top.tag == null || top.tag.endKind != HtmlTag.EndKind.REQUIRED) {
+ warnIfEmpty(top, null);
tagStack.pop();
} else {
boolean found = false;
diff --git a/test/langtools/tools/doclint/EmptyTagsTest.java b/test/langtools/tools/doclint/EmptyTagsTest.java
new file mode 100644
index 00000000000..bec33195df5
--- /dev/null
+++ b/test/langtools/tools/doclint/EmptyTagsTest.java
@@ -0,0 +1,45 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8258957
+ * @summary DocLint: check for HTML start element at end of body
+ * @modules jdk.javadoc/jdk.javadoc.internal.doclint
+ * @build DocLintTester
+ * @run main DocLintTester -Xmsgs:-html EmptyTagsTest.java
+ * @run main DocLintTester -Xmsgs:html -ref EmptyTagsTest.out EmptyTagsTest.java
+ */
+
+/** . */
+public class EmptyTagsTest {
+ /**
+ * Comment. <p>
+ */
+ void simpleTrailing() { }
+
+ /**
+ * Comment. <p>
+ * <ul>
+ * <li>Item.
+ * </ul>
+ */
+ void beforeBlock() { }
+
+ /**
+ * Comment. <p>
+ * @since 1.0
+ */
+ void beforeTag() { }
+
+ /**
+ * Comment.
+ * <ul>
+ * <li>Item. <p>
+ * </ul>
+ */
+ void inBlock() { }
+
+ /**
+ * Comment.
+ * @author J. Duke<p>
+ */
+ void inTag() { }
+}
diff --git a/test/langtools/tools/doclint/EmptyTagsTest.out b/test/langtools/tools/doclint/EmptyTagsTest.out
new file mode 100644
index 00000000000..34ad9389fd7
--- /dev/null
+++ b/test/langtools/tools/doclint/EmptyTagsTest.out
@@ -0,0 +1,16 @@
+EmptyTagsTest.java:14: warning: empty <p> tag
+ * Comment. <p>
+ ^
+EmptyTagsTest.java:19: warning: empty <p> tag
+ * Comment. <p>
+ ^
+EmptyTagsTest.java:27: warning: empty <p> tag
+ * Comment. <p>
+ ^
+EmptyTagsTest.java:35: warning: empty <p> tag
+ * <li>Item. <p>
+ ^
+EmptyTagsTest.java:42: warning: empty <p> tag
+ * @author J. Duke<p>
+ ^
+5 warnings \ No newline at end of file
diff --git a/test/langtools/tools/doclint/EndTagsTest.out b/test/langtools/tools/doclint/EndTagsTest.out
index 3367a62b8c7..2455b197718 100644
--- a/test/langtools/tools/doclint/EndTagsTest.out
+++ b/test/langtools/tools/doclint/EndTagsTest.out
@@ -1,6 +1,9 @@
EndTagsTest.java:19: error: unexpected end tag: </a>
/** </a> */
^
+EndTagsTest.java:22: warning: empty <p> tag
+ /** <p> </a> */
+ ^
EndTagsTest.java:22: error: unexpected end tag: </a>
/** <p> </a> */
^
@@ -23,3 +26,4 @@ EndTagsTest.java:37: error: unknown tag: invalid
/** </invalid> */
^
8 errors
+1 warning \ No newline at end of file
diff --git a/test/langtools/tools/doclint/HtmlTagsTest.out b/test/langtools/tools/doclint/HtmlTagsTest.out
index 66d80e365e6..8117de21dc1 100644
--- a/test/langtools/tools/doclint/HtmlTagsTest.out
+++ b/test/langtools/tools/doclint/HtmlTagsTest.out
@@ -16,6 +16,9 @@ HtmlTagsTest.java:29: error: element not closed: html
HtmlTagsTest.java:34: error: block element not allowed within inline element <span>: p
* <span> <p> </span>
^
+HtmlTagsTest.java:34: warning: empty <p> tag
+ * <span> <p> </span>
+ ^
HtmlTagsTest.java:39: error: block element not allowed within @link: p
* {@link java.lang.String <p> }
^
@@ -41,4 +44,4 @@ HtmlTagsTest.java:65: error: tag not allowed here: <b>
* <ul> <b>text</b> <li> ... </li> </ul>
^
13 errors
-1 warning
+2 warnings