Skip to content
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-8309566: Migrate away from TagletWriter and TagletWriterImpl #14793

Conversation

jonathan-gibbons
Copy link
Contributor

@jonathan-gibbons jonathan-gibbons commented Jul 7, 2023

Please review a medium-substantial cleanup of the internal Taglet world.

The initial motivation was to move tag-specific functionality from TagletWriter[Impl] to HTML-specific new subtypes of the individual Taglet classes, so that taglets are now better represented by a format-neutral base type and an HTML-specific subtype. The new subtypes are collected in a new formats.html.taglets package, and for the most part, they are accessed via their Taglet API.

A secondary motivation is to clean up handling of inline tags. Not all inline tags had corresponding taglets: most notably, {@link} was not modeled by a taglet. Introducing [Html]LinkTaglet allowed more code to move from TagletWriterImpl to HtmlLinkTaglet ... and HtmlSeeTaglet and HtmlSnippetTablet now delegate to HtmlLinkTaglet to generate links. Also, in HtmlDocletWriter a notable visitor, in commentTags toContent had explicit visit... methods that effectively duplicated the functionality of defaultAction, so those methods can be and have been deleted.

Taglets used to be stateless, even though they are generally created once per doclet. (That was fixed, now, they are created just once per doclet.) They now contain the standard long-lived members, like configuration, utils, messages, etc for the convenience of subtypes. TagletWriterImpl.Context has always been effectively format-neutral and has been moved up to Taglet.Context.

It had been hoped to replace the TagletWriter parameter to Taglet::getInlineTagOutput and Taglet::getAllBlockTagOutput with Taglet.Context perhaps calling with a HTML-subtype instance. But there is still enough useful functionality on TagletWriter that that is not practical at this time.

Taglets vary greatly in size, from small/trivial to large/complex. While it might seem unnecessary to use top-level classes for the small case, it seems better to go with a consistent uniform design rather than try and reduce any perceived overhead, perhaps by selectively using nested classes, as is often the case elsewhere in jdk.javadoc and jdk.compiler. Grouping the new HTML...Taglet classes in a new formats.html.taglets package seems like a good compromise.

Note: this is just "cleanup" and refactoring. There is no intentional change to any functionality, nor any added or removed. If code appears to have been "deleted" it has either been moved elsewhere, or was effectively unused anyway. No tests are modified, and the JDK API docs are not affected by these changes.

Some stats:

Class Before After
TagletWriter 420 lines 294 lines
TagletWriterImpl 985 lines 272 lines

... so, even if TagletWriter and TagletWriterImpl have not gone away completely, they have at least been significantly reduced.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issues

  • JDK-8309566: Migrate away from TagletWriter and TagletWriterImpl (Enhancement - P4)
  • JDK-8311974: Clean up Utils.getBlockTags (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14793/head:pull/14793
$ git checkout pull/14793

Update a local copy of the PR:
$ git checkout pull/14793
$ git pull https://git.openjdk.org/jdk.git pull/14793/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14793

View PR using the GUI difftool:
$ git pr show -t 14793

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14793.diff

Webrev

Link to Webrev Comment

@jonathan-gibbons jonathan-gibbons marked this pull request as draft July 7, 2023 00:15
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 7, 2023

👋 Welcome back jjg! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jul 7, 2023

@jonathan-gibbons The following label will be automatically applied to this pull request:

  • javadoc

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the javadoc javadoc-dev@openjdk.org label Jul 7, 2023
@jonathan-gibbons jonathan-gibbons marked this pull request as ready for review July 7, 2023 15:33
@openjdk openjdk bot added the rfr Pull request is ready for review label Jul 7, 2023
@mlbridge
Copy link

mlbridge bot commented Jul 7, 2023

Webrevs

Copy link
Member

@pavelrappo pavelrappo left a comment

Choose a reason for hiding this comment

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

This is good work, Jon. We discussed it with you offline and agreed that it's an incremental step towards simpler jdk.javadoc.

Please update the copyright years and if you change something before pushing, re-run tier1. Thanks!

// by those taglets that need to refer to it
protected TagletWriter tagletWriter;

public BaseTaglet(BaseConfiguration config, DocTree.Kind tagKind, boolean inline, Set<Location> sites) {
Copy link
Member

Choose a reason for hiding this comment

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

Good to see that the taglets now uniformly have useful state (BaseConfiguration). That reminded me of this prior discussion of ours.

@@ -118,7 +106,7 @@ public DocTree.Kind getTagKind() {
}

/**
* Returns whether or not this taglet accepts a {@code DocTree} node.
* Returns whether this taglet accepts a {@code DocTree} node.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for removing that redundancy!

* <blockquote> The type {@code List<P>} </blockquote>
*/
public class CodeTaglet extends BaseTaglet {
public abstract class LinkTaglet extends BaseTaglet {
Copy link
Member

Choose a reason for hiding this comment

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

{@link} has finally got its own taglet. However, I note that {@code} has lost its taglet.

In the markup sense, {@link} is to {@code} as {@linkplain} is to {@literal}. If you agree with this, then I think we should leave {@code}, rather than {@literal}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, but may do that separately, or as part of subsequent cleanup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I may leave the types as-is but try and fix it in the doc comments. The problem is in the class names and the crossed-over functionality.

this.showTaglets = options.showTaglets();
this.utils = configuration.utils;
this.tagletPath = options.tagletPath();
initStandardTaglets();
// initStandardTaglets();
Copy link
Member

Choose a reason for hiding this comment

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

A leftover?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops yes.

*/
protected abstract Content systemPropertyTagOutput(Element element, SystemPropertyTree systemPropertyTag);
public final Context context;
Copy link
Member

Choose a reason for hiding this comment

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

I dislike it when a variable is accessible both directly and through the getter. Nonencapsulated fields like that is harder to debug and maintain. That said, I realise that it's somewhat of a pattern in jdk.javadoc. So, no need to change it at this time; I just make an observation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Observation noted. For my part, I don't mind non-encapsulated fields if they are final. I prefer that style to the "noisy" parens of getter methods:

var x = utils.something;
var x = utils().something;

Copy link
Member

Choose a reason for hiding this comment

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

My comment was about fields that are BOTH accessible directly and through the getter. To me, it's an either-or situation.

Regardless, don't bother with changing it now. I just felt like it's a good opportunity to raise that general concern.

@openjdk
Copy link

openjdk bot commented Jul 10, 2023

@jonathan-gibbons This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8309566: Migrate away from TagletWriter and TagletWriterImpl
8311974: Clean up Utils.getBlockTags

Reviewed-by: prappo

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 44 new commits pushed to the master branch:

  • 372d0cf: 8311545: Allow test symbol files to be kept in the test image
  • 489a32f: 8311813: C1: Uninitialized PhiResolver::_loop field
  • 119cc49: 8156889: ListKeychainStore.sh fails in some virtualized environments
  • ed9337e: 8155902: DataOuputStream should clarify that it might write primitive types as multiple byte groups
  • f82c818: 8308694: Clarify reversed() default methods' implementation requirements
  • 7304316: 8311926: java/lang/ScopedValue/StressStackOverflow.java takes 9mins in tier1
  • aa7367f: 8311921: Inform about MaxExpectedDataSegmentSize in case of pthread_create failures on AIX
  • 753bd56: 8311870: Split CompressedKlassPointers from compressedOops.hpp
  • 0b0e064: 8311656: Shenandoah: Unused ShenandoahSATBAndRemarkThreadsClosure::_claim_token
  • fd7fddb: 8295894: Remove SECOM certificate that is expiring in September 2023
  • ... and 34 more: https://git.openjdk.org/jdk/compare/ec7da91bd83803b7d91a4de3a01caf0ba256c037...master

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 10, 2023
@jonathan-gibbons
Copy link
Contributor Author

Based on direct feedback, the sense is that while it is good to move taglet-specific code out of TagletWriter[Impl], there is insufficient benefit to split the code for each taglet between a format-neutral version and an HTML-specific subtype. Essentially, this is admitting that the reasons for supporting multiple output formats in times long past (that is, to facilitate paper books) are no longer valid, and/or such requirements would now be handled differently. As a result, the PR is updated to merge the format-neutral code for each taglet with the HTML code for each taglet, to create a single unified taglet for each tag (with appropriate hand-waving for @code/@literal and @link/@linkplain/@see.)

@jonathan-gibbons
Copy link
Contributor Author

As a result of the merge, TagletWriter has also moved to the formats.html.taglets package, and merged with TagletWriterImpl which no longer exists.

@jonathan-gibbons
Copy link
Contributor Author

I also cleaned up some related bit-decay, so that there are no imports in the toolkit world for classes in the formats.html world.

Convert `InheritableTaglet` to just a marker interface.
Copy link
Member

@pavelrappo pavelrappo left a comment

Choose a reason for hiding this comment

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

I started adding "nits" on extra or missing newlines, but then realised it will introduce much noise. Could you please inspect the changed files for those newlines and also update the copyright years as appropriate? Thanks!

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jul 12, 2023
@jonathan-gibbons
Copy link
Contributor Author

/issue add JDK-8311974

@openjdk
Copy link

openjdk bot commented Jul 12, 2023

@jonathan-gibbons
Adding additional issue to issue list: 8311974: Clean up Utils.getBlockTags.

Copy link
Member

@pavelrappo pavelrappo left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jul 12, 2023
Copy link
Member

@pavelrappo pavelrappo left a comment

Choose a reason for hiding this comment

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

Even better; thanks.

@jonathan-gibbons
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jul 13, 2023

Going to push as commit e51472e.
Since your change was applied there have been 46 commits pushed to the master branch:

  • fb90af8: 8311380: Prepare java.desktop for C++17
  • 743e8b8: 8306785: fix deficient spliterators for Sequenced Collections
  • 372d0cf: 8311545: Allow test symbol files to be kept in the test image
  • 489a32f: 8311813: C1: Uninitialized PhiResolver::_loop field
  • 119cc49: 8156889: ListKeychainStore.sh fails in some virtualized environments
  • ed9337e: 8155902: DataOuputStream should clarify that it might write primitive types as multiple byte groups
  • f82c818: 8308694: Clarify reversed() default methods' implementation requirements
  • 7304316: 8311926: java/lang/ScopedValue/StressStackOverflow.java takes 9mins in tier1
  • aa7367f: 8311921: Inform about MaxExpectedDataSegmentSize in case of pthread_create failures on AIX
  • 753bd56: 8311870: Split CompressedKlassPointers from compressedOops.hpp
  • ... and 36 more: https://git.openjdk.org/jdk/compare/ec7da91bd83803b7d91a4de3a01caf0ba256c037...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 13, 2023
@openjdk openjdk bot closed this Jul 13, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 13, 2023
@openjdk
Copy link

openjdk bot commented Jul 13, 2023

@jonathan-gibbons Pushed as commit e51472e.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated javadoc javadoc-dev@openjdk.org
2 participants