Skip to content

Commit bb022b2

Browse files
author
Pavel Rappo
committedMay 4, 2022
8285470: Improve handling of @inheritdoc
Reviewed-by: jjg
1 parent 09e6ee9 commit bb022b2

File tree

7 files changed

+48
-69
lines changed

7 files changed

+48
-69
lines changed
 

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/DocFilesHandlerImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ private void handleHtmlFile(DocFile srcfile, DocPath dstPath) throws DocFileIOEx
199199
HtmlDocletWriter docletWriter = new DocFileWriter(configuration, dfilePath, element, pkg);
200200

201201
List<? extends DocTree> localTags = getLocalHeaderTags(utils.getPreamble(dfElement));
202-
Content localTagsContent = docletWriter.commentTagsToContent(null, dfElement, localTags, false);
202+
Content localTagsContent = docletWriter.commentTagsToContent(dfElement, localTags, false);
203203

204204
String title = getWindowTitle(docletWriter, dfElement).trim();
205205
HtmlTree htmlContent = docletWriter.getBody(title);
206206

207207
List<? extends DocTree> fullBody = utils.getFullBody(dfElement);
208-
Content pageContent = docletWriter.commentTagsToContent(null, dfElement, fullBody, false);
208+
Content pageContent = docletWriter.commentTagsToContent(dfElement, fullBody, false);
209209
docletWriter.addTagsInfo(dfElement, pageContent);
210210

211211
htmlContent.add(new BodyContents()

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

+23-32
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ protected boolean hasSerializationOverviewTags(VariableElement field) {
366366
return !output.isEmpty();
367367
}
368368

369-
private Content getInlineTagOutput(Element element, DocTree holder, DocTree tree, TagletWriterImpl.Context context) {
369+
private Content getInlineTagOutput(Element element, DocTree tree, TagletWriterImpl.Context context) {
370370
return getTagletWriterInstance(context)
371-
.getInlineTagOutput(element, configuration.tagletManager, holder, tree);
371+
.getInlineTagOutput(element, configuration.tagletManager, tree);
372372
}
373373

374374
/**
@@ -1015,7 +1015,7 @@ public Content seeTagToContent(Element element, DocTree see, TagletWriterImpl.Co
10151015

10161016
boolean isLinkPlain = kind == LINK_PLAIN;
10171017
Content labelContent = plainOrCode(isLinkPlain,
1018-
commentTagsToContent(see, element, label, context));
1018+
commentTagsToContent(element, label, context));
10191019

10201020
// The signature from the @see tag. We will output this text when a label is not specified.
10211021
Content text = plainOrCode(isLinkPlain,
@@ -1370,7 +1370,7 @@ private void addCommentTags(Element element, List<? extends DocTree> tags, boole
13701370
return;
13711371
}
13721372
Content div;
1373-
Content result = commentTagsToContent(null, element, tags, first, inSummary);
1373+
Content result = commentTagsToContent(element, tags, first, inSummary);
13741374
if (depr) {
13751375
div = HtmlTree.DIV(HtmlStyle.deprecationComment, result);
13761376
target.add(div);
@@ -1407,65 +1407,56 @@ boolean ignoreNonInlineTag(DocTree dtree) {
14071407
private boolean commentRemoved = false;
14081408

14091409
/**
1410-
* Converts inline tags and text to Content, expanding the
1410+
* Converts inline tags and text to content, expanding the
14111411
* inline tags along the way. Called wherever text can contain
14121412
* an inline tag, such as in comments or in free-form text arguments
14131413
* to block tags.
14141414
*
1415-
* @param holderTag specific tag where comment resides
1416-
* @param element specific element where comment resides
1417-
* @param tags array of text tags and inline tags (often alternating)
1418-
present in the text of interest for this element
1419-
* @param isFirstSentence true if text is first sentence
1415+
* @param element specific element where comment resides
1416+
* @param tags list of text trees and inline tag trees (often alternating)
1417+
* @param isFirstSentence true if text is first sentence
14201418
* @return a Content object
14211419
*/
1422-
public Content commentTagsToContent(DocTree holderTag,
1423-
Element element,
1420+
public Content commentTagsToContent(Element element,
14241421
List<? extends DocTree> tags,
14251422
boolean isFirstSentence)
14261423
{
1427-
return commentTagsToContent(holderTag, element, tags, isFirstSentence, false);
1424+
return commentTagsToContent(element, tags, isFirstSentence, false);
14281425
}
14291426

14301427
/**
1431-
* Converts inline tags and text to text strings, expanding the
1428+
* Converts inline tags and text to content, expanding the
14321429
* inline tags along the way. Called wherever text can contain
14331430
* an inline tag, such as in comments or in free-form text arguments
14341431
* to block tags.
14351432
*
1436-
* @param holderTag specific tag where comment resides
14371433
* @param element specific element where comment resides
1438-
* @param trees array of text tags and inline tags (often alternating)
1439-
* present in the text of interest for this element
1434+
* @param trees list of text trees and inline tag trees (often alternating)
14401435
* @param isFirstSentence true if text is first sentence
14411436
* @param inSummary if the comment tags are added into the summary section
14421437
* @return a Content object
14431438
*/
1444-
public Content commentTagsToContent(DocTree holderTag,
1445-
Element element,
1439+
public Content commentTagsToContent(Element element,
14461440
List<? extends DocTree> trees,
14471441
boolean isFirstSentence,
14481442
boolean inSummary) {
1449-
return commentTagsToContent(holderTag, element, trees,
1443+
return commentTagsToContent(element, trees,
14501444
new TagletWriterImpl.Context(isFirstSentence, inSummary));
14511445
}
14521446

14531447
/**
1454-
* Converts inline tags and text to text strings, expanding the
1448+
* Converts inline tags and text to content, expanding the
14551449
* inline tags along the way. Called wherever text can contain
14561450
* an inline tag, such as in comments or in free-form text arguments
14571451
* to block tags.
14581452
*
1459-
* @param holderTag specific tag where comment resides
14601453
* @param element specific element where comment resides
14611454
* @param trees list of text trees and inline tag trees (often alternating)
1462-
* present in the text of interest for this element
14631455
* @param context the enclosing context for the trees
14641456
*
14651457
* @return a Content object
14661458
*/
1467-
public Content commentTagsToContent(DocTree holderTag,
1468-
Element element,
1459+
public Content commentTagsToContent(Element element,
14691460
List<? extends DocTree> trees,
14701461
TagletWriterImpl.Context context)
14711462
{
@@ -1576,7 +1567,7 @@ private Content copyDocRootContent(Content content) {
15761567

15771568
@Override
15781569
public Boolean visitDocRoot(DocRootTree node, Content c) {
1579-
Content docRootContent = getInlineTagOutput(element, holderTag, node, context);
1570+
Content docRootContent = getInlineTagOutput(element, node, context);
15801571
if (c != null) {
15811572
c.add(docRootContent);
15821573
} else {
@@ -1620,15 +1611,15 @@ public Boolean visitErroneous(ErroneousTree node, Content c) {
16201611

16211612
@Override
16221613
public Boolean visitInheritDoc(InheritDocTree node, Content c) {
1623-
Content output = getInlineTagOutput(element, holderTag, node, context);
1614+
Content output = getInlineTagOutput(element, node, context);
16241615
result.add(output);
16251616
// if we obtained the first sentence successfully, nothing more to do
16261617
return (context.isFirstSentence && !output.isEmpty());
16271618
}
16281619

16291620
@Override
16301621
public Boolean visitIndex(IndexTree node, Content p) {
1631-
Content output = getInlineTagOutput(element, holderTag, node, context);
1622+
Content output = getInlineTagOutput(element, node, context);
16321623
if (output != null) {
16331624
result.add(output);
16341625
}
@@ -1643,7 +1634,7 @@ public Boolean visitLink(LinkTree node, Content c) {
16431634
if (dtp != null) {
16441635
messages.warning(dtp, "doclet.see.nested_link", "{@" + node.getTagName() + "}");
16451636
}
1646-
Content label = commentTagsToContent(node, element, node.getLabel(), context);
1637+
Content label = commentTagsToContent(element, node.getLabel(), context);
16471638
if (label.isEmpty()) {
16481639
label = Text.of(node.getReference().getSignature());
16491640
}
@@ -1686,14 +1677,14 @@ public Boolean visitStartElement(StartElementTree node, Content c) {
16861677

16871678
@Override
16881679
public Boolean visitSummary(SummaryTree node, Content c) {
1689-
Content output = getInlineTagOutput(element, holderTag, node, context);
1680+
Content output = getInlineTagOutput(element, node, context);
16901681
result.add(output);
16911682
return false;
16921683
}
16931684

16941685
@Override
16951686
public Boolean visitSystemProperty(SystemPropertyTree node, Content p) {
1696-
Content output = getInlineTagOutput(element, holderTag, node, context);
1687+
Content output = getInlineTagOutput(element, node, context);
16971688
if (output != null) {
16981689
result.add(output);
16991690
}
@@ -1726,7 +1717,7 @@ public Boolean visitText(TextTree node, Content c) {
17261717

17271718
@Override
17281719
protected Boolean defaultAction(DocTree node, Content c) {
1729-
Content output = getInlineTagOutput(element, holderTag, node, context);
1720+
Content output = getInlineTagOutput(element, node, context);
17301721
if (output != null) {
17311722
result.add(output);
17321723
}

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriterImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,14 @@ public void computeModulesData() {
346346
utils.getProvidesTrees(mdle).forEach(tree -> {
347347
TypeElement t = ch.getServiceType(tree);
348348
if (t != null) {
349-
providesTrees.put(t, commentTagsToContent(tree, mdle, ch.getDescription(tree), false, true));
349+
providesTrees.put(t, commentTagsToContent(mdle, ch.getDescription(tree), false, true));
350350
}
351351
});
352352
// Generate the map of all services listed using @uses, and the description.
353353
utils.getUsesTrees(mdle).forEach(tree -> {
354354
TypeElement t = ch.getServiceType(tree);
355355
if (t != null) {
356-
usesTrees.put(t, commentTagsToContent(tree, mdle, ch.getDescription(tree), false, true));
356+
usesTrees.put(t, commentTagsToContent(mdle, ch.getDescription(tree), false, true));
357357
}
358358
});
359359
}

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TagletWriterImpl.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ protected Content indexTagOutput(Element element, IndexTree tag) {
209209
.replaceAll("\\s+", " ");
210210
}
211211

212-
Content desc = htmlWriter.commentTagsToContent(tag, element, tag.getDescription(), context.within(tag));
212+
Content desc = htmlWriter.commentTagsToContent(element, tag.getDescription(), context.within(tag));
213213
String descText = extractText(desc);
214214

215215
return createAnchorAndSearchIndex(element, tagText, descText, tag);
@@ -298,15 +298,15 @@ public Content paramTagOutput(Element element, ParamTree paramTag, String paramN
298298
body.add(HtmlTree.CODE(defineID ? HtmlTree.SPAN_ID(HtmlIds.forParam(paramName), nameContent) : nameContent));
299299
body.add(" - ");
300300
List<? extends DocTree> description = ch.getDescription(paramTag);
301-
body.add(htmlWriter.commentTagsToContent(paramTag, element, description, context.within(paramTag)));
301+
body.add(htmlWriter.commentTagsToContent(element, description, context.within(paramTag)));
302302
return HtmlTree.DD(body);
303303
}
304304

305305
@Override
306306
public Content returnTagOutput(Element element, ReturnTree returnTag, boolean inline) {
307307
CommentHelper ch = utils.getCommentHelper(element);
308308
List<? extends DocTree> desc = ch.getDescription(returnTag);
309-
Content content = htmlWriter.commentTagsToContent(returnTag, element, desc , context.within(returnTag));
309+
Content content = htmlWriter.commentTagsToContent(element, desc , context.within(returnTag));
310310
return inline
311311
? new ContentBuilder(contents.getContent("doclet.Returns_0", content))
312312
: new ContentBuilder(HtmlTree.DT(contents.returns), HtmlTree.DD(content));
@@ -366,7 +366,7 @@ public Content simpleBlockTagOutput(Element element, List<? extends DocTree> sim
366366
body.add(", ");
367367
}
368368
List<? extends DocTree> bodyTags = ch.getBody(simpleTag);
369-
body.add(htmlWriter.commentTagsToContent(simpleTag, element, bodyTags, context.within(simpleTag)));
369+
body.add(htmlWriter.commentTagsToContent(element, bodyTags, context.within(simpleTag)));
370370
many = true;
371371
}
372372
return new ContentBuilder(
@@ -513,7 +513,7 @@ public Content throwsTagOutput(Element element, ThrowsTree throwsTag, TypeMirror
513513
}
514514
body.add(HtmlTree.CODE(excName));
515515
List<? extends DocTree> description = ch.getDescription(throwsTag);
516-
Content desc = htmlWriter.commentTagsToContent(throwsTag, element, description, context.within(throwsTag));
516+
Content desc = htmlWriter.commentTagsToContent(element, description, context.within(throwsTag));
517517
if (desc != null && !desc.isEmpty()) {
518518
body.add(" - ");
519519
body.add(desc);
@@ -558,7 +558,7 @@ public Content commentTagsToOutput(Element holder,
558558
List<? extends DocTree> tags,
559559
boolean isFirstSentence)
560560
{
561-
return htmlWriter.commentTagsToContent(holderTag, holder,
561+
return htmlWriter.commentTagsToContent(holder,
562562
tags, holderTag == null ? context : context.within(holderTag));
563563
}
564564

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/InheritDocTaglet.java

+13-20
Original file line numberDiff line numberDiff line change
@@ -56,39 +56,34 @@ public InheritDocTaglet() {
5656
}
5757

5858
/**
59-
* Given an element, a {@code DocTree} in the element's doc comment
60-
* replace all occurrences of {@code {@inheritDoc}} with documentation from its
61-
* superclass or superinterface.
59+
* Given an element and {@code @inheritDoc} tag in that element's doc comment,
60+
* returns the (recursive) expansion of that tag.
61+
*
62+
* <p>This method does not expand all {@code {@inheritDoc}} tags in the given
63+
* element's doc comment. To do this, the method must be called for every
64+
* such tag.</p>
6265
*
6366
* @param writer the writer that is writing the output.
6467
* @param e the {@link Element} that we are documenting.
65-
*
66-
* @param holderTag
67-
*
68-
* either the tag that holds the {@code {@inheritDoc}} tag or {@code null},
69-
* which can mean either of:
70-
* <ul>
71-
* <li>the tag is used on a class {@link jdk.javadoc.doclet.Taglet.Location#TYPE} declaration, or
72-
* <li>the tag is used to copy the overall doc comment
73-
* </ul>
74-
*
68+
* @param inheritDoc the {@code {@inheritDoc}} tag
7569
* @param isFirstSentence true if we only want to inherit the first sentence
7670
*/
7771
private Content retrieveInheritedDocumentation(TagletWriter writer,
7872
Element e,
79-
DocTree holderTag,
73+
DocTree inheritDoc,
8074
boolean isFirstSentence) {
8175
Content replacement = writer.getOutputInstance();
8276
BaseConfiguration configuration = writer.configuration();
8377
Messages messages = configuration.getMessages();
8478
Utils utils = configuration.utils;
8579
CommentHelper ch = utils.getCommentHelper(e);
86-
Taglet taglet = holderTag == null
80+
var path = ch.getDocTreePath(inheritDoc).getParentPath();
81+
DocTree holderTag = path.getLeaf();
82+
Taglet taglet = holderTag.getKind() == DocTree.Kind.DOC_COMMENT
8783
? null
8884
: configuration.tagletManager.getTaglet(ch.getTagName(holderTag));
8985
if (taglet != null && !(taglet instanceof InheritableTaglet)) {
9086
// This tag does not support inheritance.
91-
var path = writer.configuration().utils.getCommentHelper(e).getDocTreePath(holderTag);
9287
messages.warning(path, "doclet.inheritDocWithinInappropriateTag");
9388
return replacement;
9489
}
@@ -119,9 +114,7 @@ private Content retrieveInheritedDocumentation(TagletWriter writer,
119114
}
120115

121116
@Override
122-
public Content getInlineTagOutput(Element e, DocTree tag, TagletWriter tagletWriter) {
123-
DocTree inheritTag = (tag.getKind() == DocTree.Kind.INHERIT_DOC) ? null : tag;
124-
return retrieveInheritedDocumentation(tagletWriter, e,
125-
inheritTag, tagletWriter.isFirstSentence);
117+
public Content getInlineTagOutput(Element e, DocTree inheritDoc, TagletWriter tagletWriter) {
118+
return retrieveInheritedDocumentation(tagletWriter, e, inheritDoc, tagletWriter.isFirstSentence);
126119
}
127120
}

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletWriter.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,12 @@ public Content getBlockTagOutput(TagletManager tagletManager,
326326
*
327327
* @param holder the element associated with the doc comment
328328
* @param tagletManager the taglet manager for the current doclet
329-
* @param holderTag the tag that holds this inline tag, or {@code null} if
330-
* there is no tag that holds it
331329
* @param inlineTag the inline tag to be documented
332330
*
333331
* @return the content, or {@code null}
334332
*/
335333
public Content getInlineTagOutput(Element holder,
336334
TagletManager tagletManager,
337-
DocTree holderTag,
338335
DocTree inlineTag) {
339336

340337
Map<String, Taglet> inlineTags = tagletManager.getInlineTaglets();
@@ -346,9 +343,7 @@ public Content getInlineTagOutput(Element holder,
346343
}
347344

348345
try {
349-
Content tagletOutput = t.getInlineTagOutput(holder,
350-
holderTag != null && t.getName().equals("inheritDoc") ? holderTag : inlineTag,
351-
this);
346+
Content tagletOutput = t.getInlineTagOutput(holder, inlineTag, this);
352347
tagletManager.seenTag(t.getName());
353348
return tagletOutput;
354349
} catch (UnsupportedTagletOperationException e) {

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ private DocTreePath getInheritedDocTreePath(DocTree dtree, ExecutableElement ee)
711711
DocFinder.Output inheritedDoc =
712712
DocFinder.search(configuration,
713713
new DocFinder.Input(utils, ee));
714-
return inheritedDoc == null || inheritedDoc.holder == ee
714+
return inheritedDoc.holder == ee
715715
? null
716716
: utils.getCommentHelper(inheritedDoc.holder).getDocTreePath(dtree);
717717
}

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on May 4, 2022

@openjdk-notifier[bot]
Please sign in to comment.