New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDK-8257925 enable more support for nested inline tags #2369
Conversation
|
@jonathan-gibbons The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
Although this patch generally looks reasonable, I'm surprised to see some of the behavior it introduces. For example, consider composition of
Before the patch that doc comment resulted in the following HTML:
After the patch that same doc comment results in HTML that looks like this:
I wouldn't expect that latter behavior. Not only nested |
Thanks; it was on my list to check whether nested links were allowed. I'm pleased they're not, and this will be another situation where the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing the nested <a>
issue. With your last commit (96bfeb5) the output from
/** First sentence. {@link #m1() ABC {@link #m2() DEF} GHI} */
looks like this
First sentence. <a href="#m1()"><code>ABC DEF GHI</code></a>
and if doclint is enabled, javadoc issues a warning
warning: nested tag: @link
/** First sentence. {@link #m1() ABC {@link #m2() DEF} GHI} */
^
I would recommend comparing JDK API documentation before and after, if only to bring any uncovered surprises to maintainers' attention early.
@jonathan-gibbons this pull request can not be integrated into git checkout inline-tags
git fetch https://git.openjdk.java.net/jdk master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very nice improvement! I have added a few comments and suggestions, but nothing of major importance.
} | ||
default -> { | ||
assert false; | ||
return HtmlTree.EMPTY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason to assert false
here and in other places instead of, say, always throw a RuntimeException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the general discussion about the use of assert
, and whether it is better to throw an exception in production code, or "carry on regardless". I wish Java had a should-not-happen statement or at least a ShoudNotHappen exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, IllegalStateException
is a reasonable alternative
Content label = commentTagsToContent(node, element, node.getLabel(), context); | ||
if (label.isEmpty()) { | ||
label = new StringContent(node.getReference().getSignature()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's quite a bit of work for something probably very few people should try...
@@ -1576,7 +1634,7 @@ public Boolean visitLiteral(LiteralTree node, Content c) { | |||
@Override | |||
public Boolean visitSee(SeeTree node, Content c) { | |||
// we need to pass the DocTreeImpl here, so ignore node | |||
result.add(seeTagToContent(element, tag)); | |||
result.add(seeTagToContent(element, tag, context)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is above comment still correct? Aren't tag
and node
the same object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, updated
@@ -109,7 +164,24 @@ public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) { | |||
public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence, boolean inSummary) { | |||
super(isFirstSentence); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid almost identical constructors this one could be implemented as
this(htmlWriter, new Context(isFirstSentence, inSummary));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
"{@link", | ||
"ABC <a href=\"#m2()\""); | ||
checkOutput("p/C.html", true, | ||
"ABC DEF GHI"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are running this with and without doclint, should this or any test in this file check for doclint warnings?
@jonathan-gibbons This change now passes all automated pre-integration checks. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 42 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
/integrate |
@jonathan-gibbons Since your change was applied there have been 48 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit c4f17a3. |
Please review an update to improve the support, where appropriate, for nested inline tags.
It has always been the case that certain inline tags allow text and HTML to appear within them. With tags like
{@return}
and{@summary}
it becomes desirable to also generally allow nested inline tags to appear in those places as well. The work for this was started with the support for{@return}
JDK-8075778, but applying the work more generally was out of scope at the time. This change completes the work that was started then.The work can be grouped into 4 parts, in 3 commits.
Commit 1
DocCommentParser
to syntactically allow nested inline tags in situations that permit text and HTMLA family of new tests are added, each testing the ability to put an inline tag within another of the same kind, with and without doclint being enabled. In addition, test cases are added placing a simple instance
{@value}
in an enclosing tag: this is a useful case just because the expansion is plain text and therefore valid in all situations. Additional tests and test cases can be added as needed.This commit left the
{@index}
tag generating "bad" code when it was nested. The error was "reference to an undeclared ID". The (temporary) solution was to disable the automatic link checking for this specific subtest.Commit 2
HtmlDocletWriter
andTagletWriterImpl
pass around a pair of booleansisFirstSentence
andinSummary
to help determine the output to be generated. Conceptually, a third value is added to that group: a set containing the set of nested tag kinds, so that it is possible to determine the enclosing tags for a tag. But, rather than add a third parameter to be passed around, the 3 are grouped into a new classTagletWriterImpl.Context
which encapsulates the two booleans and the new set. The new class is added in a way to minimize code churn. No tests are affected by this change: all continue to pass.Commit 3
Context#inTags
field is used to help improve the behavior of nested{@index}
tags even when used incorrectly, with warnings disabled. As a result, the temporary change in the first commit to disable automatic link checking in one of the test cases is reverted.The introduction of the new Context class is arguably more general than we need at this time, but it clears up some erratic and inconsistent use of the
isFirstSentence
andinSummary
booleans. The new class also provides a better framework for any complex new inline tags we may add in future. We might want to change theSet<DocTree.Kind>
to some other collection at some point, if needs be (a stack, for example.) We might also want to move more information into theContext
, such as the relatedElement
that is otherwise ubiquitously passed around.The overall cleanup also revealed some latent bugs in the code, that were hidden in some of the tests. Most notable was that there were still some cases were
<
and>
were not being correctly escaped as<
and>
leading to output in some tests of the formList<String>
! This triggered a minor cleanup/rewrite of the beginning ofHtmlDocletWriter.seeTagsToContent
which was previously a bit too liberal with the use ofnew RawHtml
! The other minor cleanup was more consistent handling of whitespace at the end of the first sentence, as will be seen in a couple of places in one of the tests that was updated.Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/2369/head:pull/2369
$ git checkout pull/2369