mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 02:54:35 +02:00
8026368: doclint does not report empty tags when tag closed implicitly
Reviewed-by: darcy
This commit is contained in:
parent
27bd2d769e
commit
09523f2583
6 changed files with 45 additions and 15 deletions
|
@ -213,6 +213,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||||
public Void visitDocComment(DocCommentTree tree, Void ignore) {
|
public Void visitDocComment(DocCommentTree tree, Void ignore) {
|
||||||
super.visitDocComment(tree, ignore);
|
super.visitDocComment(tree, ignore);
|
||||||
for (TagStackItem tsi: tagStack) {
|
for (TagStackItem tsi: tagStack) {
|
||||||
|
warnIfEmpty(tsi, null);
|
||||||
if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT
|
if (tsi.tree.getKind() == DocTree.Kind.START_ELEMENT
|
||||||
&& tsi.tag.endKind == HtmlTag.EndKind.REQUIRED) {
|
&& tsi.tag.endKind == HtmlTag.EndKind.REQUIRED) {
|
||||||
StartElementTree t = (StartElementTree) tsi.tree;
|
StartElementTree t = (StartElementTree) tsi.tree;
|
||||||
|
@ -270,7 +271,6 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Void visitStartElement(StartElementTree tree, Void ignore) {
|
public Void visitStartElement(StartElementTree tree, Void ignore) {
|
||||||
markEnclosingTag(Flag.HAS_ELEMENT);
|
|
||||||
final Name treeName = tree.getName();
|
final Name treeName = tree.getName();
|
||||||
final HtmlTag t = HtmlTag.get(treeName);
|
final HtmlTag t = HtmlTag.get(treeName);
|
||||||
if (t == null) {
|
if (t == null) {
|
||||||
|
@ -279,7 +279,10 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
for (TagStackItem tsi: tagStack) {
|
for (TagStackItem tsi: tagStack) {
|
||||||
if (tsi.tag.accepts(t)) {
|
if (tsi.tag.accepts(t)) {
|
||||||
while (tagStack.peek() != tsi) tagStack.pop();
|
while (tagStack.peek() != tsi) {
|
||||||
|
warnIfEmpty(tagStack.peek(), null);
|
||||||
|
tagStack.pop();
|
||||||
|
}
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
} else if (tsi.tag.endKind != HtmlTag.EndKind.OPTIONAL) {
|
} else if (tsi.tag.endKind != HtmlTag.EndKind.OPTIONAL) {
|
||||||
|
@ -288,9 +291,13 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!done && HtmlTag.BODY.accepts(t)) {
|
if (!done && HtmlTag.BODY.accepts(t)) {
|
||||||
tagStack.clear();
|
while (!tagStack.isEmpty()) {
|
||||||
|
warnIfEmpty(tagStack.peek(), null);
|
||||||
|
tagStack.pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markEnclosingTag(Flag.HAS_ELEMENT);
|
||||||
checkStructure(tree, t);
|
checkStructure(tree, t);
|
||||||
|
|
||||||
// tag specific checks
|
// tag specific checks
|
||||||
|
@ -447,12 +454,7 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||||
"dc.no.summary.or.caption.for.table");
|
"dc.no.summary.or.caption.for.table");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (t.flags.contains(HtmlTag.Flag.EXPECT_CONTENT)
|
warnIfEmpty(top, tree);
|
||||||
&& !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);
|
|
||||||
}
|
|
||||||
tagStack.pop();
|
tagStack.pop();
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
|
@ -485,6 +487,20 @@ public class Checker extends DocTreePathScanner<Void, Void> {
|
||||||
|
|
||||||
return super.visitEndElement(tree, ignore);
|
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>
|
||||||
|
|
||||||
// <editor-fold defaultstate="collapsed" desc="HTML attributes">
|
// <editor-fold defaultstate="collapsed" desc="HTML attributes">
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
/** */
|
/** */
|
||||||
public class HtmlAttrsTest {
|
public class HtmlAttrsTest {
|
||||||
/**
|
/**
|
||||||
* <p xyz>
|
* <p xyz> text </p>
|
||||||
*/
|
*/
|
||||||
public void unknown() { }
|
public void unknown() { }
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
HtmlAttrsTest.java:13: error: unknown attribute: xyz
|
HtmlAttrsTest.java:13: error: unknown attribute: xyz
|
||||||
* <p xyz>
|
* <p xyz> text </p>
|
||||||
^
|
^
|
||||||
HtmlAttrsTest.java:18: warning: attribute obsolete: name
|
HtmlAttrsTest.java:18: warning: attribute obsolete: name
|
||||||
* <img name="x" alt="alt">
|
* <img name="x" alt="alt">
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
BadEnd.java:14: warning: nested tag not allowed: <code>
|
BadEnd.java:14: warning: nested tag not allowed: <code>
|
||||||
* <code> text <code>
|
* <code> text <code>
|
||||||
^
|
^
|
||||||
|
BadEnd.java:14: warning: empty <code> tag
|
||||||
|
* <code> text <code>
|
||||||
|
^
|
||||||
BadEnd.java:14: error: element not closed: code
|
BadEnd.java:14: error: element not closed: code
|
||||||
* <code> text <code>
|
* <code> text <code>
|
||||||
^
|
^
|
||||||
|
@ -14,4 +17,4 @@ BadEnd.java:13: error: element not closed: a
|
||||||
* <a name="here"> text <a>
|
* <a name="here"> text <a>
|
||||||
^
|
^
|
||||||
4 errors
|
4 errors
|
||||||
1 warning
|
2 warnings
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* @test /nodynamiccopyright/
|
* @test /nodynamiccopyright/
|
||||||
* @bug 8004832
|
* @bug 8004832 8026368
|
||||||
* @summary Add new doclint package
|
* @summary Add new doclint package
|
||||||
* @library ..
|
* @library ..
|
||||||
* @build DocLintTester
|
* @build DocLintTester
|
||||||
|
@ -26,4 +26,9 @@
|
||||||
* <ul></ul>
|
* <ul></ul>
|
||||||
* <ul><li></li></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() { }
|
||||||
|
}
|
||||||
|
|
|
@ -43,4 +43,10 @@ TrimmingEmptyTag.java:25: warning: empty <tt> tag
|
||||||
TrimmingEmptyTag.java:26: warning: empty <ul> tag
|
TrimmingEmptyTag.java:26: warning: empty <ul> tag
|
||||||
* <ul></ul>
|
* <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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue