Skip to content

Commit

Permalink
8326332: Unclosed inline tags cause misalignment in summary tables
Browse files Browse the repository at this point in the history
Reviewed-by: rschmelter
Backport-of: a6dc4bc2b83c7240e573ac43f9b7a10191c58ed3
  • Loading branch information
MBaesken committed Jul 26, 2024
1 parent bba56e0 commit cc85abc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
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;


Expand Down Expand Up @@ -1133,21 +1134,37 @@ private void addCommentTags(Element element, List<? extends DocTree> tags, boole
}
}

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;
Expand Down Expand Up @@ -1219,6 +1236,7 @@ public ContentBuilder add(CharSequence text) {
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();
Expand All @@ -1227,14 +1245,16 @@ public ContentBuilder add(CharSequence text) {

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) {
Expand Down Expand Up @@ -1485,6 +1505,10 @@ protected Boolean defaultAction(DocTree node, Content content) {
if (allDone)
break;
}
// Close any open inline tags
while (!openTags.isEmpty()) {
result.add(RawHtml.endElement(removeLastHelper(openTags)));
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
Expand Down Expand Up @@ -76,5 +76,10 @@ public void test() {
"""
<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>""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public void foobar(){}
*/
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(){}
}

3 comments on commit cc85abc

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on cc85abc Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken Could not automatically backport cc85abc2 to openjdk/jdk17u-dev due to conflicts in the following files:

  • src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-MBaesken-cc85abc2-master

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk21u-dev.git cc85abc2120b5d1b1c5eca5c9b89a73386956bb7

# Backport the commit
$ git cherry-pick --no-commit cc85abc2120b5d1b1c5eca5c9b89a73386956bb7
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport cc85abc2120b5d1b1c5eca5c9b89a73386956bb7'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport cc85abc2120b5d1b1c5eca5c9b89a73386956bb7.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit cc85abc2 from the openjdk/jdk21u-dev repository.

The commit being backported was authored by Matthias Baesken on 26 Jul 2024 and was reviewed by Ralf Schmelter.

Thanks!

Please sign in to comment.