8258957: DocLint: check for HTML start element at end of body

Reviewed-by: vromero
This commit is contained in:
Jonathan Gibbons 2021-03-24 23:58:16 +00:00
parent 3d7f91223e
commit 0ff81682e6
5 changed files with 84 additions and 3 deletions

View File

@ -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;

View File

@ -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() { }
}

View File

@ -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

View File

@ -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

View File

@ -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