--- a/langtools/src/share/classes/com/sun/tools/doclint/Checker.java Wed Jan 16 17:40:28 2013 +0000
+++ b/langtools/src/share/classes/com/sun/tools/doclint/Checker.java Wed Jan 16 10:29:52 2013 -0800
@@ -25,6 +25,7 @@
package com.sun.tools.doclint;
+import com.sun.source.doctree.LiteralTree;
import java.util.regex.Matcher;
import com.sun.source.doctree.LinkTree;
import java.net.URI;
@@ -359,9 +360,8 @@
env.messages.error(HTML, tree, "dc.tag.unknown", treeName);
} else if (t.endKind == HtmlTag.EndKind.NONE) {
env.messages.error(HTML, tree, "dc.tag.end.not.permitted", treeName);
- } else if (tagStack.isEmpty()) {
- env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName);
} else {
+ boolean done = false;
while (!tagStack.isEmpty()) {
TagStackItem top = tagStack.peek();
if (t == top.tag) {
@@ -383,6 +383,7 @@
env.messages.error(HTML, tree, "dc.text.not.allowed", treeName);
}
tagStack.pop();
+ done = true;
break;
} else if (top.tag == null || top.tag.endKind != HtmlTag.EndKind.REQUIRED) {
tagStack.pop();
@@ -400,10 +401,15 @@
tagStack.pop();
} else {
env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName);
+ done = true;
break;
}
}
}
+
+ if (!done && tagStack.isEmpty()) {
+ env.messages.error(HTML, tree, "dc.tag.end.unexpected", treeName);
+ }
}
return super.visitEndElement(tree, ignore);
@@ -546,6 +552,19 @@
}
@Override
+ public Void visitLiteral(LiteralTree tree, Void ignore) {
+ if (tree.getKind() == DocTree.Kind.CODE) {
+ for (TagStackItem tsi: tagStack) {
+ if (tsi.tag == HtmlTag.CODE) {
+ env.messages.warning(HTML, tree, "dc.tag.nested.not.allowed", "code");
+ break;
+ }
+ }
+ }
+ return super.visitLiteral(tree, ignore);
+ }
+
+ @Override
public Void visitParam(ParamTree tree, Void ignore) {
boolean typaram = tree.isTypeParameter();
IdentifierTree nameTree = tree.getName();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/EndTagsTest.java Wed Jan 16 10:29:52 2013 -0800
@@ -0,0 +1,39 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8006236
+ * @summary doclint: structural issue hidden
+ * @build DocLintTester
+ * @run main DocLintTester -Xmsgs:-html EndTagsTest.java
+ * @run main DocLintTester -ref EndTagsTest.out EndTagsTest.java
+ */
+
+/** */
+public class EndTagsTest {
+ /** <p> <a name="a1"> text <img alt="image" src="image.png"> </a> </p> */
+ public void valid_all() { }
+
+ /** <p> <a name="a2"> text <img alt="image" src="image.png"> </a> */
+ public void valid_omit_optional_close() { }
+
+ /** </a> */
+ public void invalid_missing_start() { }
+
+ /** <p> </a> */
+ public void invalid_missing_start_2() { }
+
+ /** <p> text </p> </a> */
+ public void invalid_missing_start_3() { }
+
+ /** <img alt="image" src="image.png"> </img> */
+ public void invalid_end() { }
+
+ /** <invalid> </invalid> */
+ public void unknown_start_end() { }
+
+ /** <invalid> */
+ public void unknown_start() { }
+
+ /** </invalid> */
+ public void unknown_end() { }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/doclint/EndTagsTest.out Wed Jan 16 10:29:52 2013 -0800
@@ -0,0 +1,25 @@
+EndTagsTest.java:18: error: unexpected end tag: </a>
+ /** </a> */
+ ^
+EndTagsTest.java:21: error: unexpected end tag: </a>
+ /** <p> </a> */
+ ^
+EndTagsTest.java:24: error: unexpected end tag: </a>
+ /** <p> text </p> </a> */
+ ^
+EndTagsTest.java:27: error: invalid end tag: </img>
+ /** <img alt="image" src="image.png"> </img> */
+ ^
+EndTagsTest.java:30: error: unknown tag: invalid
+ /** <invalid> </invalid> */
+ ^
+EndTagsTest.java:30: error: unknown tag: invalid
+ /** <invalid> </invalid> */
+ ^
+EndTagsTest.java:33: error: unknown tag: invalid
+ /** <invalid> */
+ ^
+EndTagsTest.java:36: error: unknown tag: invalid
+ /** </invalid> */
+ ^
+8 errors