Skip to content

Commit d086757

Browse files
8254052: improve type specificity of TagletWriter and friends
Reviewed-by: hannesw
1 parent 8600d0d commit d086757

22 files changed

+141
-104
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import javax.lang.model.element.TypeElement;
3232

33-
import com.sun.source.doctree.DocTree;
33+
import com.sun.source.doctree.DeprecatedTree;
3434
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
3535
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
3636
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
@@ -165,7 +165,7 @@ protected void addTableRow(Table table, TypeElement klass) {
165165
ContentBuilder description = new ContentBuilder();
166166
if (utils.isDeprecated(klass)) {
167167
description.add(getDeprecatedPhrase(klass));
168-
List<? extends DocTree> tags = utils.getDeprecatedTrees(klass);
168+
List<? extends DeprecatedTree> tags = utils.getDeprecatedTrees(klass);
169169
if (!tags.isEmpty()) {
170170
addSummaryDeprecatedComment(klass, tags.get(0), description);
171171
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javax.lang.model.type.TypeMirror;
4242
import javax.lang.model.util.SimpleElementVisitor8;
4343

44+
import com.sun.source.doctree.DeprecatedTree;
4445
import com.sun.source.doctree.DocTree;
4546
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
4647
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
@@ -507,7 +508,7 @@ public boolean isFunctionalInterface() {
507508

508509
@Override
509510
public void addClassDeprecationInfo(Content classInfoTree) {
510-
List<? extends DocTree> deprs = utils.getBlockTags(typeElement, DocTree.Kind.DEPRECATED);
511+
List<? extends DeprecatedTree> deprs = utils.getDeprecatedTrees(typeElement);
511512
if (utils.isDeprecated(typeElement)) {
512513
Content deprLabel = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(typeElement));
513514
Content div = HtmlTree.DIV(HtmlStyle.deprecationBlock, deprLabel);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package jdk.javadoc.internal.doclets.formats.html;
2727

28+
import com.sun.source.doctree.DeprecatedTree;
2829
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
2930
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
3031

@@ -397,7 +398,7 @@ protected void addDeprecatedAPI(SortedSet<Element> deprList, String id, String h
397398
link = getDeprecatedLink(e);
398399
}
399400
Content desc = new ContentBuilder();
400-
List<? extends DocTree> tags = utils.getDeprecatedTrees(e);
401+
List<? extends DeprecatedTree> tags = utils.getDeprecatedTrees(e);
401402
if (!tags.isEmpty()) {
402403
addInlineDeprecatedComment(e, tags.get(0), desc);
403404
} else {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.sun.source.doctree.AttributeTree;
5858
import com.sun.source.doctree.AttributeTree.ValueKind;
5959
import com.sun.source.doctree.CommentTree;
60+
import com.sun.source.doctree.DeprecatedTree;
6061
import com.sun.source.doctree.DocRootTree;
6162
import com.sun.source.doctree.DocTree;
6263
import com.sun.source.doctree.DocTree.Kind;
@@ -1167,7 +1168,7 @@ public Content getDeprecatedPhrase(Element e) {
11671168
* @param tag the inline tag to be added
11681169
* @param htmltree the content tree to which the comment will be added
11691170
*/
1170-
public void addInlineDeprecatedComment(Element e, DocTree tag, Content htmltree) {
1171+
public void addInlineDeprecatedComment(Element e, DeprecatedTree tag, Content htmltree) {
11711172
CommentHelper ch = utils.getCommentHelper(e);
11721173
addCommentTags(e, ch.getBody(tag), true, false, false, htmltree);
11731174
}
@@ -1193,7 +1194,7 @@ public void addSummaryComment(Element element, List<? extends DocTree> firstSent
11931194
addCommentTags(element, firstSentenceTags, false, true, true, htmltree);
11941195
}
11951196

1196-
public void addSummaryDeprecatedComment(Element element, DocTree tag, Content htmltree) {
1197+
public void addSummaryDeprecatedComment(Element element, DeprecatedTree tag, Content htmltree) {
11971198
CommentHelper ch = utils.getCommentHelper(element);
11981199
List<? extends DocTree> body = ch.getBody(tag);
11991200
addCommentTags(element, ch.getFirstSentenceTrees(body), true, true, true, htmltree);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import com.sun.source.doctree.DocTree;
3535

36+
import com.sun.source.doctree.SerialTree;
3637
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
3738
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
3839
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
@@ -165,7 +166,7 @@ public void addMemberDescription(VariableElement field, Content contentTree) {
165166
if (!utils.getFullBody(field).isEmpty()) {
166167
writer.addInlineComment(field, contentTree);
167168
}
168-
List<? extends DocTree> tags = utils.getBlockTags(field, DocTree.Kind.SERIAL);
169+
List<? extends SerialTree> tags = utils.getSerialTrees(field);
169170
if (!tags.isEmpty()) {
170171
writer.addInlineComment(field, tags.get(0), contentTree);
171172
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import javax.lang.model.element.PackageElement;
3838
import javax.lang.model.element.TypeElement;
3939

40-
import com.sun.source.doctree.DocTree;
40+
import com.sun.source.doctree.DeprecatedTree;
4141

4242
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
4343
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
@@ -300,13 +300,12 @@ protected void addTagDescription(IndexItem item, Content dlTree) {
300300
* @param contentTree the content tree to which the comment will be added
301301
*/
302302
protected void addComment(Element element, Content contentTree) {
303-
List<? extends DocTree> tags;
304303
Content span = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(element));
305304
HtmlTree div = new HtmlTree(TagName.DIV);
306305
div.setStyle(HtmlStyle.deprecationBlock);
307306
if (utils.isDeprecated(element)) {
308307
div.add(span);
309-
tags = utils.getBlockTags(element, DocTree.Kind.DEPRECATED);
308+
List<? extends DeprecatedTree> tags = utils.getDeprecatedTrees(element);
310309
if (!tags.isEmpty())
311310
addInlineDeprecatedComment(element, tags.get(0), div);
312311
contentTree.add(div);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import javax.lang.model.element.TypeElement;
4141
import javax.lang.model.util.ElementFilter;
4242

43+
import com.sun.source.doctree.DeprecatedTree;
4344
import com.sun.source.doctree.DocTree;
4445
import jdk.javadoc.doclet.DocletEnvironment.ModuleMode;
4546
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
@@ -369,14 +370,14 @@ public void computeModulesData() {
369370
}
370371
});
371372
// Generate the map of all services listed using @provides, and the description.
372-
utils.getBlockTags(mdle, DocTree.Kind.PROVIDES).forEach(tree -> {
373+
utils.getProvidesTrees(mdle).forEach(tree -> {
373374
TypeElement t = ch.getServiceType(tree);
374375
if (t != null) {
375376
providesTrees.put(t, commentTagsToContent(tree, mdle, ch.getDescription(tree), false, true));
376377
}
377378
});
378379
// Generate the map of all services listed using @uses, and the description.
379-
utils.getBlockTags(mdle, DocTree.Kind.USES).forEach(tree -> {
380+
utils.getUsesTrees(mdle).forEach(tree -> {
380381
TypeElement t = ch.getServiceType(tree);
381382
if (t != null) {
382383
usesTrees.put(t, commentTagsToContent(tree, mdle, ch.getDescription(tree), false, true));
@@ -802,7 +803,7 @@ public void addProvidesList(Table table) {
802803
* @param div the content tree to which the deprecation information will be added
803804
*/
804805
public void addDeprecationInfo(Content div) {
805-
List<? extends DocTree> deprs = utils.getBlockTags(mdle, DocTree.Kind.DEPRECATED);
806+
List<? extends DeprecatedTree> deprs = utils.getDeprecatedTrees(mdle);
806807
if (utils.isDeprecated(mdle)) {
807808
CommentHelper ch = utils.getCommentHelper(mdle);
808809
HtmlTree deprDiv = new HtmlTree(TagName.DIV);
@@ -860,9 +861,8 @@ public void printDocument(Content contentTree) throws DocFileIOException {
860861
* @param pkg the PackageDoc that is added
861862
*/
862863
public void addPackageDeprecationInfo(Content li, PackageElement pkg) {
863-
List<? extends DocTree> deprs;
864864
if (utils.isDeprecated(pkg)) {
865-
deprs = utils.getDeprecatedTrees(pkg);
865+
List<? extends DeprecatedTree> deprs = utils.getDeprecatedTrees(pkg);
866866
HtmlTree deprDiv = new HtmlTree(TagName.DIV);
867867
deprDiv.setStyle(HtmlStyle.deprecationBlock);
868868
Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(pkg));

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import javax.lang.model.element.PackageElement;
3333
import javax.lang.model.element.TypeElement;
3434

35+
import com.sun.source.doctree.DeprecatedTree;
3536
import com.sun.source.doctree.DocTree;
3637
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
3738
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
@@ -142,7 +143,7 @@ public Content getContentHeader() {
142143
* @param div the content tree to which the deprecation information will be added
143144
*/
144145
public void addDeprecationInfo(Content div) {
145-
List<? extends DocTree> deprs = utils.getBlockTags(packageElement, DocTree.Kind.DEPRECATED);
146+
List<? extends DeprecatedTree> deprs = utils.getDeprecatedTrees(packageElement);
146147
if (utils.isDeprecated(packageElement)) {
147148
CommentHelper ch = utils.getCommentHelper(packageElement);
148149
HtmlTree deprDiv = new HtmlTree(TagName.DIV);
@@ -223,7 +224,7 @@ public void addClassesSummary(SortedSet<TypeElement> classes, String label,
223224
ContentBuilder description = new ContentBuilder();
224225
if (utils.isDeprecated(klass)) {
225226
description.add(getDeprecatedPhrase(klass));
226-
List<? extends DocTree> tags = utils.getDeprecatedTrees(klass);
227+
List<? extends DeprecatedTree> tags = utils.getDeprecatedTrees(klass);
227228
if (!tags.isEmpty()) {
228229
addSummaryDeprecatedComment(klass, tags.get(0), description);
229230
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import javax.lang.model.element.Element;
3131
import javax.lang.model.element.TypeElement;
3232

33+
import com.sun.source.doctree.DeprecatedTree;
3334
import com.sun.source.doctree.DocTree;
3435
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
3536
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
@@ -108,7 +109,7 @@ protected void addIndexComment(Element member, Content contentTree) {
108109
*/
109110
protected void addIndexComment(Element member, List<? extends DocTree> firstSentenceTags,
110111
Content tdSummary) {
111-
List<? extends DocTree> deprs = utils.getBlockTags(member, DocTree.Kind.DEPRECATED);
112+
List<? extends DeprecatedTree> deprs = utils.getDeprecatedTrees(member);
112113
Content div;
113114
if (utils.isDeprecated(member)) {
114115
Content deprLabel = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, getDeprecatedPhrase(member));

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@
3737
import javax.lang.model.type.TypeMirror;
3838
import javax.lang.model.util.SimpleElementVisitor14;
3939

40+
import com.sun.source.doctree.DeprecatedTree;
4041
import com.sun.source.doctree.DocTree;
4142
import com.sun.source.doctree.IndexTree;
43+
import com.sun.source.doctree.LiteralTree;
4244
import com.sun.source.doctree.ParamTree;
45+
import com.sun.source.doctree.ReturnTree;
46+
import com.sun.source.doctree.SeeTree;
4347
import com.sun.source.doctree.SystemPropertyTree;
48+
import com.sun.source.doctree.ThrowsTree;
4449
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
4550
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
4651
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
@@ -109,16 +114,15 @@ protected Content codeTagOutput(Element element, DocTree tag) {
109114
}
110115

111116
@Override
112-
protected Content indexTagOutput(Element element, DocTree tag) {
117+
protected Content indexTagOutput(Element element, IndexTree tag) {
113118
CommentHelper ch = utils.getCommentHelper(element);
114-
IndexTree itt = (IndexTree) tag;
115119

116-
String tagText = ch.getText(itt.getSearchTerm());
120+
String tagText = ch.getText(tag.getSearchTerm());
117121
if (tagText.charAt(0) == '"' && tagText.charAt(tagText.length() - 1) == '"') {
118122
tagText = tagText.substring(1, tagText.length() - 1)
119123
.replaceAll("\\s+", " ");
120124
}
121-
String desc = ch.getText(itt.getDescription());
125+
String desc = ch.getText(tag.getDescription());
122126

123127
return createAnchorAndSearchIndex(element, tagText, desc, tag);
124128
}
@@ -137,7 +141,7 @@ public Content getDocRootOutput() {
137141
public Content deprecatedTagOutput(Element element) {
138142
ContentBuilder result = new ContentBuilder();
139143
CommentHelper ch = utils.getCommentHelper(element);
140-
List<? extends DocTree> deprs = utils.getBlockTags(element, DocTree.Kind.DEPRECATED);
144+
List<? extends DeprecatedTree> deprs = utils.getDeprecatedTrees(element);
141145
if (utils.isTypeElement(element)) {
142146
if (utils.isDeprecated(element)) {
143147
result.add(HtmlTree.SPAN(HtmlStyle.deprecatedLabel,
@@ -171,7 +175,7 @@ public Content deprecatedTagOutput(Element element) {
171175
}
172176

173177
@Override
174-
protected Content literalTagOutput(Element element, DocTree tag) {
178+
protected Content literalTagOutput(Element element, LiteralTree tag) {
175179
CommentHelper ch = utils.getCommentHelper(element);
176180
Content result = new StringContent(utils.normalizeNewlines(ch.getText(tag)));
177181
return result;
@@ -191,12 +195,12 @@ public Content getParamHeader(ParamTaglet.ParamKind kind) {
191195

192196
@Override
193197
@SuppressWarnings("preview")
194-
public Content paramTagOutput(Element element, DocTree paramTag, String paramName) {
198+
public Content paramTagOutput(Element element, ParamTree paramTag, String paramName) {
195199
ContentBuilder body = new ContentBuilder();
196200
CommentHelper ch = utils.getCommentHelper(element);
197201
// define id attributes for state components so that generated descriptions may refer to them
198202
boolean defineID = (element.getKind() == ElementKind.RECORD)
199-
&& (paramTag instanceof ParamTree) && !((ParamTree) paramTag).isTypeParameter();
203+
&& !paramTag.isTypeParameter();
200204
Content nameTree = new StringContent(paramName);
201205
body.add(HtmlTree.CODE(defineID ? HtmlTree.SPAN_ID("param-" + paramName, nameTree) : nameTree));
202206
body.add(" - ");
@@ -206,7 +210,7 @@ public Content paramTagOutput(Element element, DocTree paramTag, String paramNam
206210
}
207211

208212
@Override
209-
public Content returnTagOutput(Element element, DocTree returnTag) {
213+
public Content returnTagOutput(Element element, ReturnTree returnTag) {
210214
CommentHelper ch = utils.getCommentHelper(element);
211215
return new ContentBuilder(
212216
HtmlTree.DT(contents.returns),
@@ -215,7 +219,7 @@ public Content returnTagOutput(Element element, DocTree returnTag) {
215219
}
216220

217221
@Override
218-
public Content seeTagOutput(Element holder, List<? extends DocTree> seeTags) {
222+
public Content seeTagOutput(Element holder, List<? extends SeeTree> seeTags) {
219223
ContentBuilder body = new ContentBuilder();
220224
for (DocTree dt : seeTags) {
221225
appendSeparatorIfNotEmpty(body);
@@ -279,9 +283,8 @@ public Content simpleBlockTagOutput(Element element, List<? extends DocTree> sim
279283
}
280284

281285
@Override
282-
protected Content systemPropertyTagOutput(Element element, DocTree tag) {
283-
SystemPropertyTree itt = (SystemPropertyTree) tag;
284-
String tagText = itt.getPropertyName().toString();
286+
protected Content systemPropertyTagOutput(Element element, SystemPropertyTree tag) {
287+
String tagText = tag.getPropertyName().toString();
285288
return HtmlTree.CODE(createAnchorAndSearchIndex(element, tagText,
286289
resources.getText("doclet.System_Property"), tag));
287290
}
@@ -292,7 +295,7 @@ public Content getThrowsHeader() {
292295
}
293296

294297
@Override
295-
public Content throwsTagOutput(Element element, DocTree throwsTag, TypeMirror substituteType) {
298+
public Content throwsTagOutput(Element element, ThrowsTree throwsTag, TypeMirror substituteType) {
296299
ContentBuilder body = new ContentBuilder();
297300
CommentHelper ch = utils.getCommentHelper(element);
298301
Element exception = ch.getException(throwsTag);

0 commit comments

Comments
 (0)