-
Notifications
You must be signed in to change notification settings - Fork 155
JDK-8262886: javadoc generates broken links with {@inheritDoc} #17
Conversation
|
👋 Welcome back hannesw! A progress list of the required criteria for merging this PR into |
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.
Nice. Approved, but (as is often the case) there is potential for additional cleanup downstream.
| // Note: It would be nice to have getCurrentPageElement() return package and module elements | ||
| // in their respective writers, but other uses of the method are only interested in TypeElements. | ||
| Element currentPageElement = getCurrentPageElement(); | ||
| if (currentPageElement == null) { | ||
| if (this instanceof PackageWriterImpl packageWriter) { | ||
| currentPageElement = packageWriter.packageElement; | ||
| } else if (this instanceof ModuleWriterImpl moduleWriter) { | ||
| currentPageElement = moduleWriter.mdle; | ||
| } | ||
| } |
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.
File an RFE?
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.
I actually considered changing it as part of this change, but decided it wasn't worth changing several unrelated usages of the methods. In the end it's not a problem, except that the method name suggest it would also return package and module elements. Maybe we should just rename the method to getCurrentTypeElement to better represent its behaviour.
| String text = tt.getBody(); | ||
| if (element == null || utils.isOverviewElement(element) || shouldNotRedirectRelativeLinks()) { | ||
| if (!shouldRedirectRelativeLinks(element)) { | ||
| return text; | ||
| } | ||
|
|
||
| DocPath redirectPathFromRoot = new SimpleElementVisitor14<DocPath, Void>() { | ||
| @Override | ||
| public DocPath visitType(TypeElement e, Void p) { | ||
| return docPaths.forPackage(utils.containingPackage(e)); | ||
| String lower = Utils.toLowerCase(text); | ||
| if (lower.startsWith("mailto:") | ||
| || lower.startsWith("http:") | ||
| || lower.startsWith("https:") | ||
| || lower.startsWith("file:")) { | ||
| return text; | ||
| } | ||
| if (text.startsWith("#")) { | ||
| // Redirected fragment link: prepend HTML file name to make it work | ||
| if (utils.isModule(element)) { | ||
| text = "module-summary.html" + text; | ||
| } else if (utils.isPackage(element)) { | ||
| text = DocPaths.PACKAGE_SUMMARY.getPath() + text; | ||
| } else { | ||
| TypeElement typeElement = element instanceof TypeElement | ||
| ? (TypeElement) element : utils.getEnclosingTypeElement(element); | ||
| text = docPaths.forName(typeElement).getPath() + text; | ||
| } | ||
| } |
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 OK, but would it be better to try and create a URI from the text, and then use URI methods to check or manipulate the URI? Maybe an RFE...?
| }.visit(element); | ||
| if (redirectPathFromRoot == null) { | ||
| return text; | ||
| } | ||
| String lower = Utils.toLowerCase(text); | ||
| if (!(lower.startsWith("mailto:") | ||
| || lower.startsWith("http:") | ||
| || lower.startsWith("https:") | ||
| || lower.startsWith("file:"))) { | ||
| text = "{@" + (new DocRootTaglet()).getName() + "}/" | ||
| + redirectPathFromRoot.resolve(text).getPath(); | ||
| text = replaceDocRootDir(text); |
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.
ah OK, I see you were just moving stuff around ;-)
| text = "{@" + (new DocRootTaglet()).getName() + "}/" | ||
| + redirectPathFromRoot.resolve(text).getPath(); |
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.
OK, but icky code ...
- icky to create an object to just get its name
- icky to create a comment fragment to get the docRoot behavior
I accept this is old code moved around. Maybe file an RFE for cleanup
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, Jon. I agree this change keeps alive too much old/obsolete code. I will file an RFE for cleanup.
| // This is not a relative path and should not be redirected. | ||
| checkOutput("index-all.html", true, | ||
| """ | ||
| <div class="block"><a name="masters"></a>"""); |
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.
wow!
| // since the test uses explicit links to non-existent files, | ||
| // we create those files to avoid false positive errors from checkLinks |
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.
:-)
|
@hns 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: 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 381 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. ➡️ To integrate this PR with the above commit message to the |
|
(general wishful thinking) |
|
/integrate |
|
Going to push as commit 962f1c1.
Your commit was automatically rebased without conflicts. |
(This jdk17 PR is the continuation of PR openjdk/jdk#4459 in the mainline jdk repo, commits are identical at the point of transition.)
This change fixes a whole slew of shortcomings in the redirection of relative links in doc comments. The basic idea is that relative links are authored to work in their "native primary" environment (e.g. the package summary page for a package or the class page for a class and its members), and have to be rewritten when used in other contexts such as "use" or index pages.
A list of omissions that are fixed in this change:
While fixing above issues I also made sure link rewriting is kept to a minimum, avoiding it as much as possible for elements that live in the same package.
Furthermore, the test for redirected relative links was a bit out of order. The
javadoccommand issued by the test returnedERRORbecause one of the source files contained non-valid HTML (an anchor with anameattribute to test whether that attribute would be modified). Because of this, thecheckLinks()method was never invoked, which is a problem for a test that is supposed to make sure generated links are valid. I changed the test to use the valididattribute instead ofnameand made surecheckLinks()is executed again.I also added checks for the newly supported cases. I added a whole new test for modules since retrofitting the existing test to cover modules would not have been practical.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk17 pull/17/head:pull/17$ git checkout pull/17Update a local copy of the PR:
$ git checkout pull/17$ git pull https://git.openjdk.java.net/jdk17 pull/17/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 17View PR using the GUI difftool:
$ git pr show -t 17Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk17/pull/17.diff