OpenJDK / jdk / jdk
changeset 59725:e0559f61db6b
8247235: doclint should permit "self-closing" tags for void elements in HTML5
Reviewed-by: hannesw
author | jjg |
---|---|
date | Wed, 10 Jun 2020 17:23:05 -0700 |
parents | 2f75432d7eb3 |
children | c62986f0ae6b |
files | src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java test/langtools/jdk/javadoc/doclet/testWarnings/TestWarnings.java test/langtools/jdk/javadoc/doclet/testWarnings/pkg/X.java |
diffstat | 3 files changed, 21 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java Wed Jun 10 18:18:30 2020 -0400 +++ b/src/jdk.compiler/share/classes/com/sun/tools/doclint/Checker.java Wed Jun 10 17:23:05 2020 -0700 @@ -375,7 +375,7 @@ } // check for self closing tags, such as <a id="name"/> - if (tree.isSelfClosing()) { + if (tree.isSelfClosing() && !isSelfClosingAllowed(t)) { env.messages.error(HTML, tree, "dc.tag.self.closing", treeName); } @@ -415,6 +415,13 @@ } } + // so-called "self-closing" tags are only permitted in HTML 5, for void elements + // https://html.spec.whatwg.org/multipage/syntax.html#start-tags + private boolean isSelfClosingAllowed(HtmlTag tag) { + return env.htmlVersion == HtmlVersion.HTML5 + && tag.endKind == HtmlTag.EndKind.NONE; + } + private void checkStructure(StartElementTree tree, HtmlTag t) { Name treeName = tree.getName(); TagStackItem top = tagStack.peek();
--- a/test/langtools/jdk/javadoc/doclet/testWarnings/TestWarnings.java Wed Jun 10 18:18:30 2020 -0400 +++ b/test/langtools/jdk/javadoc/doclet/testWarnings/TestWarnings.java Wed Jun 10 17:23:05 2020 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 4515705 4804296 4702454 4697036 8025633 8182765 + * @bug 4515705 4804296 4702454 4697036 8025633 8182765 8247235 * @summary Make sure that first sentence warning only appears once. * Make sure that only warnings/errors are printed when quiet is used. * Make sure that links to private/unincluded methods do not cause @@ -50,17 +50,23 @@ "pkg"); checkExit(Exit.ERROR); - checkOutput(Output.OUT, true, + checkOutput(Output.OUT, false, "X.java:23: error: self-closing element not allowed"); - checkOutput(Output.OUT, true, + checkOutput(Output.OUT, false, "X.java:24: error: self-closing element not allowed"); - checkOutput(Output.OUT, true, + checkOutput(Output.OUT, false, "X.java:25: error: self-closing element not allowed"); + checkOutput(Output.OUT, false, + "X.java:26: error: self-closing element not allowed"); + checkOutput(Output.OUT, true, - "X.java:26: error: self-closing element not allowed"); + "X.java:28: error: self-closing element not allowed"); + + checkOutput(Output.OUT, true, + "X.java:28: warning: empty <p> tag"); checkOutput("pkg/X.html", false, "can't find m()");
--- a/test/langtools/jdk/javadoc/doclet/testWarnings/pkg/X.java Wed Jun 10 18:18:30 2020 -0400 +++ b/test/langtools/jdk/javadoc/doclet/testWarnings/pkg/X.java Wed Jun 10 17:23:05 2020 -0700 @@ -24,6 +24,8 @@ * {@link #m()}<br/> * {@link #f}<br/> * {@link java.lang.String#toString()}<br/> + * <hr/> + * <p/> */ public void foo() {} }