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: gli, jjg
  • Loading branch information
hns committed Mar 8, 2024
1 parent 33aa4b2 commit a6dc4bc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
import jdk.javadoc.internal.doclint.HtmlTag;

import static com.sun.source.doctree.DocTree.Kind.COMMENT;
import static com.sun.source.doctree.DocTree.Kind.START_ELEMENT;
import static com.sun.source.doctree.DocTree.Kind.TEXT;


Expand Down Expand Up @@ -1171,21 +1172,28 @@ private void addCommentTags(Element element, List<? extends DocTree> tags, boole
}
}

boolean ignoreNonInlineTag(DocTree dtree) {
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()
&& openTags.getLast().equals(name)) {
openTags.removeLast();
}
}
}
return false;
Expand Down Expand Up @@ -1257,6 +1265,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 @@ -1265,14 +1274,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 @@ -1466,6 +1477,10 @@ protected Boolean defaultAction(DocTree node, Content content) {
if (allDone)
break;
}
// Close any open inline tags
while (!openTags.isEmpty()) {
result.add(RawHtml.endElement(openTags.removeLast()));
}
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 a6dc4bc

@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

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on a6dc4bc Jul 23, 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 a6dc4bc2 to openjdk/jdk21u-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/jdk21u-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/jdk21u-dev.git master:master

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

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

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

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

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

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

Hi all,

This pull request contains a backport of commit a6dc4bc2 from the openjdk/jdk repository.

The commit being backported was authored by Hannes Wallnöfer on 8 Mar 2024 and was reviewed by Guoxiong Li and Jonathan Gibbons.

Thanks!

Please sign in to comment.