Skip to content

Commit 1f432a0

Browse files
author
duke
committedMar 24, 2021
Automatic merge of jdk:master into master
2 parents 0df817d + 0ff8168 commit 1f432a0

File tree

5 files changed

+84
-3
lines changed

5 files changed

+84
-3
lines changed
 

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclint/Checker.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,20 @@ private void reportReference(String code, Object... args) {
269269

270270
@Override @DefinedBy(Api.COMPILER_TREE)
271271
public Void visitDocComment(DocCommentTree tree, Void ignore) {
272-
super.visitDocComment(tree, ignore);
272+
scan(tree.getFirstSentence(), ignore);
273+
scan(tree.getBody(), ignore);
274+
checkTagStack();
275+
276+
for (DocTree blockTag : tree.getBlockTags()) {
277+
tagStack.clear();
278+
scan(blockTag, ignore);
279+
checkTagStack();
280+
}
281+
282+
return null;
283+
}
284+
285+
private void checkTagStack() {
273286
for (TagStackItem tsi: tagStack) {
274287
warnIfEmpty(tsi, null);
275288
if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT
@@ -278,7 +291,6 @@ public Void visitDocComment(DocCommentTree tree, Void ignore) {
278291
env.messages.error(HTML, t, "dc.tag.not.closed", t.getName());
279292
}
280293
}
281-
return null;
282294
}
283295
// </editor-fold>
284296

@@ -548,6 +560,7 @@ public Void visitEndElement(EndElementTree tree, Void ignore) {
548560
done = true;
549561
break;
550562
} else if (top.tag == null || top.tag.endKind != HtmlTag.EndKind.REQUIRED) {
563+
warnIfEmpty(top, null);
551564
tagStack.pop();
552565
} else {
553566
boolean found = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* @test /nodynamiccopyright/
3+
* @bug 8258957
4+
* @summary DocLint: check for HTML start element at end of body
5+
* @modules jdk.javadoc/jdk.javadoc.internal.doclint
6+
* @build DocLintTester
7+
* @run main DocLintTester -Xmsgs:-html EmptyTagsTest.java
8+
* @run main DocLintTester -Xmsgs:html -ref EmptyTagsTest.out EmptyTagsTest.java
9+
*/
10+
11+
/** . */
12+
public class EmptyTagsTest {
13+
/**
14+
* Comment. <p>
15+
*/
16+
void simpleTrailing() { }
17+
18+
/**
19+
* Comment. <p>
20+
* <ul>
21+
* <li>Item.
22+
* </ul>
23+
*/
24+
void beforeBlock() { }
25+
26+
/**
27+
* Comment. <p>
28+
* @since 1.0
29+
*/
30+
void beforeTag() { }
31+
32+
/**
33+
* Comment.
34+
* <ul>
35+
* <li>Item. <p>
36+
* </ul>
37+
*/
38+
void inBlock() { }
39+
40+
/**
41+
* Comment.
42+
* @author J. Duke<p>
43+
*/
44+
void inTag() { }
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
EmptyTagsTest.java:14: warning: empty <p> tag
2+
* Comment. <p>
3+
^
4+
EmptyTagsTest.java:19: warning: empty <p> tag
5+
* Comment. <p>
6+
^
7+
EmptyTagsTest.java:27: warning: empty <p> tag
8+
* Comment. <p>
9+
^
10+
EmptyTagsTest.java:35: warning: empty <p> tag
11+
* <li>Item. <p>
12+
^
13+
EmptyTagsTest.java:42: warning: empty <p> tag
14+
* @author J. Duke<p>
15+
^
16+
5 warnings

‎test/langtools/tools/doclint/EndTagsTest.out

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
EndTagsTest.java:19: error: unexpected end tag: </a>
22
/** </a> */
33
^
4+
EndTagsTest.java:22: warning: empty <p> tag
5+
/** <p> </a> */
6+
^
47
EndTagsTest.java:22: error: unexpected end tag: </a>
58
/** <p> </a> */
69
^
@@ -23,3 +26,4 @@ EndTagsTest.java:37: error: unknown tag: invalid
2326
/** </invalid> */
2427
^
2528
8 errors
29+
1 warning

‎test/langtools/tools/doclint/HtmlTagsTest.out

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ HtmlTagsTest.java:29: error: element not closed: html
1616
HtmlTagsTest.java:34: error: block element not allowed within inline element <span>: p
1717
* <span> <p> </span>
1818
^
19+
HtmlTagsTest.java:34: warning: empty <p> tag
20+
* <span> <p> </span>
21+
^
1922
HtmlTagsTest.java:39: error: block element not allowed within @link: p
2023
* {@link java.lang.String <p> }
2124
^
@@ -41,4 +44,4 @@ HtmlTagsTest.java:65: error: tag not allowed here: <b>
4144
* <ul> <b>text</b> <li> ... </li> </ul>
4245
^
4346
13 errors
44-
1 warning
47+
2 warnings

0 commit comments

Comments
 (0)
Please sign in to comment.