mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
8326332: Unclosed inline tags cause misalignment in summary tables
Reviewed-by: rschmelter
Backport-of: a6dc4bc2b8
This commit is contained in:
committed by
Vitaly Provodin
parent
e58503f505
commit
28be8a4264
@@ -117,6 +117,7 @@ import static com.sun.source.doctree.DocTree.Kind.COMMENT;
|
||||
import static com.sun.source.doctree.DocTree.Kind.LINK;
|
||||
import static com.sun.source.doctree.DocTree.Kind.LINK_PLAIN;
|
||||
import static com.sun.source.doctree.DocTree.Kind.SEE;
|
||||
import static com.sun.source.doctree.DocTree.Kind.START_ELEMENT;
|
||||
import static com.sun.source.doctree.DocTree.Kind.TEXT;
|
||||
|
||||
|
||||
@@ -1133,21 +1134,37 @@ public class HtmlDocletWriter {
|
||||
}
|
||||
}
|
||||
|
||||
boolean ignoreNonInlineTag(DocTree dtree) {
|
||||
// helper methods because jdk21 functionality is not allowed
|
||||
private static Name getLastHelper(List<Name> l) {
|
||||
return l.get(l.size() - 1);
|
||||
}
|
||||
|
||||
private static Name removeLastHelper(List<Name> l) {
|
||||
return l.remove(l.size() - 1);
|
||||
}
|
||||
|
||||
boolean ignoreNonInlineTag(DocTree dtree, List<Name> openTags) {
|
||||
Name name = null;
|
||||
if (dtree.getKind() == Kind.START_ELEMENT) {
|
||||
StartElementTree setree = (StartElementTree)dtree;
|
||||
name = setree.getName();
|
||||
} else if (dtree.getKind() == Kind.END_ELEMENT) {
|
||||
EndElementTree eetree = (EndElementTree)dtree;
|
||||
name = eetree.getName();
|
||||
Kind kind = dtree.getKind();
|
||||
if (kind == Kind.START_ELEMENT) {
|
||||
name = ((StartElementTree)dtree).getName();
|
||||
} else if (kind == Kind.END_ELEMENT) {
|
||||
name = ((EndElementTree)dtree).getName();
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
HtmlTag htmlTag = HtmlTag.get(name);
|
||||
if (htmlTag != null &&
|
||||
htmlTag.blockType != jdk.javadoc.internal.doclint.HtmlTag.BlockType.INLINE) {
|
||||
return true;
|
||||
if (htmlTag != null) {
|
||||
if (htmlTag.blockType != HtmlTag.BlockType.INLINE) {
|
||||
return true;
|
||||
}
|
||||
// Keep track of open inline tags that need to be closed, see 8326332
|
||||
if (kind == START_ELEMENT && htmlTag.endKind == HtmlTag.EndKind.REQUIRED) {
|
||||
openTags.add(name);
|
||||
} else if (kind == Kind.END_ELEMENT && !openTags.isEmpty()
|
||||
&& getLastHelper(openTags).equals(name)) {
|
||||
removeLastHelper(openTags);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -1219,6 +1236,7 @@ public class HtmlDocletWriter {
|
||||
CommentHelper ch = utils.getCommentHelper(element);
|
||||
configuration.tagletManager.checkTags(element, trees);
|
||||
commentRemoved = false;
|
||||
List<Name> openTags = new ArrayList<>();
|
||||
|
||||
for (ListIterator<? extends DocTree> iterator = trees.listIterator(); iterator.hasNext();) {
|
||||
boolean isFirstNode = !iterator.hasPrevious();
|
||||
@@ -1227,14 +1245,16 @@ public class HtmlDocletWriter {
|
||||
|
||||
if (context.isFirstSentence) {
|
||||
// Ignore block tags
|
||||
if (ignoreNonInlineTag(tag))
|
||||
if (ignoreNonInlineTag(tag, openTags)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore any trailing whitespace OR whitespace after removed html comment
|
||||
if ((isLastNode || commentRemoved)
|
||||
&& tag.getKind() == TEXT
|
||||
&& ((tag instanceof TextTree tt) && tt.getBody().isBlank()))
|
||||
&& ((tag instanceof TextTree tt) && tt.getBody().isBlank())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore any leading html comments
|
||||
if ((isFirstNode || commentRemoved) && tag.getKind() == COMMENT) {
|
||||
@@ -1485,6 +1505,10 @@ public class HtmlDocletWriter {
|
||||
if (allDone)
|
||||
break;
|
||||
}
|
||||
// Close any open inline tags
|
||||
while (!openTags.isEmpty()) {
|
||||
result.add(RawHtml.endElement(removeLastHelper(openTags)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4165985
|
||||
* @bug 4165985 8326332
|
||||
* @summary Determine the end of the first sentence using BreakIterator.
|
||||
* If the first sentence of "method" is parsed correctly, the test passes.
|
||||
* Correct Answer: "This is a class (i.e. it is indeed a class)."
|
||||
@@ -76,5 +76,10 @@ public class TestBreakIterator extends JavadocTester {
|
||||
"""
|
||||
<div class="block">A constant indicating that the keyLocation is indeterminate
|
||||
or not relevant.</div>""");
|
||||
|
||||
checkOutput("pkg/BreakIteratorTest.html", true,
|
||||
"""
|
||||
<div class="block">Inline tags <i><a href="../index-all.html">extending
|
||||
beyond the first sentence.</a></i></div>""");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,4 +56,9 @@ public class BreakIteratorTest {
|
||||
*/
|
||||
public void fe(){}
|
||||
|
||||
/**
|
||||
* Inline tags <i><a href="{@docRoot}/index-all.html">extending
|
||||
* beyond the first sentence. Tags are closed here.</a></i>
|
||||
*/
|
||||
public void meh(){}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user