|
25 | 25 |
|
26 | 26 | package jdk.javadoc.internal.doclets.formats.html;
|
27 | 27 |
|
| 28 | +import java.util.ArrayList; |
28 | 29 | import java.util.EnumSet;
|
29 | 30 | import java.util.List;
|
30 | 31 | import java.util.Set;
|
|
53 | 54 | import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
|
54 | 55 | import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
|
55 | 56 | import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml;
|
| 57 | +import jdk.javadoc.internal.doclets.formats.html.markup.TagName; |
56 | 58 | import jdk.javadoc.internal.doclets.formats.html.markup.Text;
|
57 | 59 | import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
|
58 | 60 | import jdk.javadoc.internal.doclets.toolkit.Content;
|
@@ -141,6 +143,9 @@ Context within(DocTree tree) {
|
141 | 143 | private final Contents contents;
|
142 | 144 | private final Context context;
|
143 | 145 |
|
| 146 | + // Threshold for length of @see tag label for switching from inline to block layout. |
| 147 | + private static final int SEE_TAG_MAX_INLINE_LENGTH = 30; |
| 148 | + |
144 | 149 | /**
|
145 | 150 | * Creates a taglet writer.
|
146 | 151 | *
|
@@ -310,48 +315,47 @@ public Content returnTagOutput(Element element, ReturnTree returnTag, boolean in
|
310 | 315 |
|
311 | 316 | @Override
|
312 | 317 | public Content seeTagOutput(Element holder, List<? extends SeeTree> seeTags) {
|
313 |
| - ContentBuilder body = new ContentBuilder(); |
| 318 | + List<Content> links = new ArrayList<>(); |
314 | 319 | for (DocTree dt : seeTags) {
|
315 |
| - appendSeparatorIfNotEmpty(body); |
316 |
| - body.add(htmlWriter.seeTagToContent(holder, dt, context.within(dt))); |
| 320 | + links.add(htmlWriter.seeTagToContent(holder, dt, context.within(dt))); |
317 | 321 | }
|
318 | 322 | if (utils.isVariableElement(holder) && ((VariableElement)holder).getConstantValue() != null &&
|
319 | 323 | htmlWriter instanceof ClassWriterImpl) {
|
320 | 324 | //Automatically add link to constant values page for constant fields.
|
321 |
| - appendSeparatorIfNotEmpty(body); |
322 | 325 | DocPath constantsPath =
|
323 | 326 | htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES);
|
324 | 327 | String whichConstant =
|
325 | 328 | ((ClassWriterImpl) htmlWriter).getTypeElement().getQualifiedName() + "." +
|
326 | 329 | utils.getSimpleName(holder);
|
327 | 330 | DocLink link = constantsPath.fragment(whichConstant);
|
328 |
| - body.add(htmlWriter.links.createLink(link, |
| 331 | + links.add(htmlWriter.links.createLink(link, |
329 | 332 | Text.of(resources.getText("doclet.Constants_Summary"))));
|
330 | 333 | }
|
331 | 334 | if (utils.isClass(holder) && utils.isSerializable((TypeElement)holder)) {
|
332 | 335 | //Automatically add link to serialized form page for serializable classes.
|
333 | 336 | if (SerializedFormBuilder.serialInclude(utils, holder) &&
|
334 | 337 | SerializedFormBuilder.serialInclude(utils, utils.containingPackage(holder))) {
|
335 |
| - appendSeparatorIfNotEmpty(body); |
336 | 338 | DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM);
|
337 | 339 | DocLink link = serialPath.fragment(utils.getFullyQualifiedName(holder));
|
338 |
| - body.add(htmlWriter.links.createLink(link, |
| 340 | + links.add(htmlWriter.links.createLink(link, |
339 | 341 | Text.of(resources.getText("doclet.Serialized_Form"))));
|
340 | 342 | }
|
341 | 343 | }
|
342 |
| - if (body.isEmpty()) |
343 |
| - return body; |
| 344 | + if (links.isEmpty()) { |
| 345 | + return Text.EMPTY; |
| 346 | + } |
| 347 | + // Use a different style if any link label is longer than 30 chars or contains commas. |
| 348 | + boolean hasLongLabels = links.stream() |
| 349 | + .anyMatch(c -> c.charCount() > SEE_TAG_MAX_INLINE_LENGTH || c.toString().contains(",")); |
| 350 | + HtmlTree seeList = new HtmlTree(TagName.UL) |
| 351 | + .setStyle(hasLongLabels ? HtmlStyle.seeListLong : HtmlStyle.seeList); |
| 352 | + links.stream().filter(Content::isValid).forEach(item -> { |
| 353 | + seeList.add(HtmlTree.LI(item)); |
| 354 | + }); |
344 | 355 |
|
345 | 356 | return new ContentBuilder(
|
346 | 357 | HtmlTree.DT(contents.seeAlso),
|
347 |
| - HtmlTree.DD(body)); |
348 |
| - } |
349 |
| - |
350 |
| - private void appendSeparatorIfNotEmpty(ContentBuilder body) { |
351 |
| - if (!body.isEmpty()) { |
352 |
| - body.add(", "); |
353 |
| - body.add(DocletConstants.NL); |
354 |
| - } |
| 358 | + HtmlTree.DD(seeList)); |
355 | 359 | }
|
356 | 360 |
|
357 | 361 | @Override
|
|
0 commit comments