Skip to content

Commit 2e91585

Browse files
committed
8303123: Add line break opportunity to single type parameters
Reviewed-by: jjg
1 parent 094e03d commit 2e91585

File tree

6 files changed

+53
-28
lines changed

6 files changed

+53
-28
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ protected void addModifiersAndType(Element member, TypeMirror type,
202202
if (list != null && !list.isEmpty()) {
203203
Content typeParameters = ((AbstractExecutableMemberWriter) this)
204204
.getTypeParameters((ExecutableElement)member);
205-
code.add(typeParameters);
206-
//Code to avoid ugly wrapping in member summary table.
205+
code.add(typeParameters);
206+
// Add explicit line break between method type parameters and
207+
// return type in member summary table to avoid random wrapping.
207208
if (typeParameters.charCount() > 10) {
208209
code.add(new HtmlTree(TagName.BR));
209210
} else {
@@ -212,7 +213,8 @@ protected void addModifiersAndType(Element member, TypeMirror type,
212213
}
213214
code.add(
214215
writer.getLink(new HtmlLinkInfo(configuration,
215-
HtmlLinkInfo.Kind.LINK_TYPE_PARAMS, type)));
216+
HtmlLinkInfo.Kind.LINK_TYPE_PARAMS, type)
217+
.addLineBreakOpportunitiesInTypeParameters(true)));
216218
}
217219
target.add(code);
218220
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ protected Content getTypeParameterLinks(HtmlLinkInfo linkInfo) {
327327
return links;
328328
}
329329
if (!vars.isEmpty()) {
330+
if (linkInfo.addLineBreakOpportunitiesInTypeParameters()) {
331+
links.add(new HtmlTree(TagName.WBR));
332+
}
330333
links.add("<");
331334
boolean many = false;
332335
for (TypeMirror t : vars) {

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ public enum Kind {
122122
// True iff the preview flags should be skipped for this link.
123123
private boolean skipPreview;
124124

125-
// True if type parameters should be separated by line breaks.
125+
// True if type parameters should be separated by hard line breaks.
126126
private boolean addLineBreaksInTypeParameters = false;
127127

128+
// True if additional <wbr> tags should be added to type parameters
129+
private boolean addLineBreakOpportunitiesInTypeParameters = false;
130+
128131
// True if annotations on type parameters should be shown.
129132
private boolean showTypeParameterAnnotations = false;
130133

@@ -311,6 +314,23 @@ public boolean addLineBreaksInTypeParameters() {
311314
return addLineBreaksInTypeParameters;
312315
}
313316

317+
/**
318+
* Sets the addLineBreakOpportunitiesInTypeParameters flag for this link.
319+
* @param addLineBreakOpportunities the new value
320+
* @return this object
321+
*/
322+
public HtmlLinkInfo addLineBreakOpportunitiesInTypeParameters(boolean addLineBreakOpportunities) {
323+
this.addLineBreakOpportunitiesInTypeParameters = addLineBreakOpportunities;
324+
return this;
325+
}
326+
327+
/**
328+
* {@return true if line break opportunities should be added to type parameters}
329+
*/
330+
public boolean addLineBreakOpportunitiesInTypeParameters() {
331+
return addLineBreakOpportunitiesInTypeParameters;
332+
}
333+
314334
/**
315335
* Set the linkToSelf flag for this link.
316336
* @param linkToSelf the new value

test/langtools/jdk/javadoc/doclet/testJavaFX/TestJavaFX.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -369,16 +369,16 @@ public void test3() {
369369
<div class="col-last odd-row-color method-summary-table method-summary-table-tab\
370370
2 method-summary-table-tab4">&nbsp;</div>
371371
<div class="col-first even-row-color method-summary-table method-summary-table-t\
372-
ab2 method-summary-table-tab4"><code>final java.util.List&lt;java.util.Set&lt;? \
373-
super java.lang.Object&gt;&gt;</code></div>
372+
ab2 method-summary-table-tab4"><code>final java.util.List<wbr>&lt;java.util.Set&\
373+
lt;? super java.lang.Object&gt;&gt;</code></div>
374374
<div class="col-second even-row-color method-summary-table method-summary-table-\
375375
tab2 method-summary-table-tab4"><code><a href="#deltaProperty()" class="member-n\
376376
ame-link">deltaProperty</a>()</code></div>
377377
<div class="col-last even-row-color method-summary-table method-summary-table-ta\
378378
b2 method-summary-table-tab4">&nbsp;</div>
379379
<div class="col-first odd-row-color method-summary-table method-summary-table-ta\
380-
b2 method-summary-table-tab4"><code>final java.util.List&lt;java.lang.String&gt;\
381-
</code></div>
380+
b2 method-summary-table-tab4"><code>final java.util.List<wbr>&lt;java.lang.Strin\
381+
g&gt;</code></div>
382382
<div class="col-second odd-row-color method-summary-table method-summary-table-t\
383383
ab2 method-summary-table-tab4"><code><a href="#gammaProperty()" class="member-na\
384384
me-link">gammaProperty</a>()</code></div>

test/langtools/jdk/javadoc/doclet/testNewLanguageFeatures/TestNewLanguageFeatures.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -272,7 +272,7 @@ void checkTypeParameters() {
272272
></span></div>""",
273273
"""
274274
<div class="col-first even-row-color"><code><a href="../ParamTest.html" title="class\
275-
in pkg2">ParamTest</a>&lt;<a href="../Foo.html" title="class in pkg2">Foo</a>&g\
275+
in pkg2">ParamTest</a><wbr>&lt;<a href="../Foo.html" title="class in pkg2">Foo</a>&g\
276276
t;</code></div>"""
277277
);
278278

@@ -283,7 +283,7 @@ void checkTypeParameters() {
283283
pan></div>""",
284284
"""
285285
<div class="col-first even-row-color"><code><a href="../ParamTest.html" title="class\
286-
in pkg2">ParamTest</a>&lt;<a href="../Foo.html" title="class in pkg2">Foo</a>&\
286+
in pkg2">ParamTest</a><wbr>&lt;<a href="../Foo.html" title="class in pkg2">Foo</a>&\
287287
gt;</code></div>"""
288288
);
289289

@@ -331,9 +331,9 @@ void checkTypeParameters() {
331331
declared as <a href="../ParamTest.html" title="class in pkg2">ParamTest</a></s\
332332
pan></div>""",
333333
"""
334-
<div class="col-first even-row-color"><code><a href="../ParamTest.html" title="class\
335-
in pkg2">ParamTest</a>&lt;<a href="../Foo.html" title="class in pkg2">Foo</a>&\
336-
gt;</code></div>""",
334+
<div class="col-first even-row-color"><code><a href="../ParamTest.html" title="\
335+
class in pkg2">ParamTest</a><wbr>&lt;<a href="../Foo.html" title="class in pkg2\
336+
">Foo</a>&gt;</code></div>""",
337337
"""
338338
<div class="caption"><span>Methods in <a href="../package-summary.html">pkg2</a\
339339
> with type parameters of type <a href="../ParamTest.html" title="class in pkg2\
@@ -342,8 +342,8 @@ void checkTypeParameters() {
342342
<div class="col-first even-row-color"><code>&lt;T extends <a href="../ParamTest.html\
343343
" title="class in pkg2">ParamTest</a>&lt;<a href="../Foo3.html" title="class in\
344344
pkg2">Foo3</a>&gt;&gt;<br><a href="../ParamTest.html" title="class in pkg2">Pa\
345-
ramTest</a>&lt;<a href="../Foo3.html" title="class in pkg2">Foo3</a>&gt;</code>\
346-
</div>"""
345+
ramTest</a><wbr>&lt;<a href="../Foo3.html" title="class in pkg2">Foo3</a>&gt;</\
346+
code></div>"""
347347
);
348348

349349
checkOutput("pkg2/class-use/Foo3.html", true,
@@ -372,8 +372,8 @@ void checkTypeParameters() {
372372
<div class="col-first even-row-color"><code>&lt;T extends <a href="../ParamTest.html\
373373
" title="class in pkg2">ParamTest</a>&lt;<a href="../Foo3.html" title="class in\
374374
pkg2">Foo3</a>&gt;&gt;<br><a href="../ParamTest.html" title="class in pkg2">Pa\
375-
ramTest</a>&lt;<a href="../Foo3.html" title="class in pkg2">Foo3</a>&gt;</code>\
376-
</div>"""
375+
ramTest</a><wbr>&lt;<a href="../Foo3.html" title="class in pkg2">Foo3</a>&gt;</\
376+
code></div>"""
377377
);
378378

379379
// ClassUseTest3: <T extends ParamTest2<List<? extends Foo4>>>
@@ -400,8 +400,8 @@ void checkTypeParameters() {
400400
<div class="col-first even-row-color"><code>&lt;T extends <a href="../ParamTest2.htm\
401401
l" title="class in pkg2">ParamTest2</a>&lt;java.util.List&lt;? extends <a href=\
402402
"../Foo4.html" title="class in pkg2">Foo4</a>&gt;&gt;&gt;<br><a href="../ParamT\
403-
est2.html" title="class in pkg2">ParamTest2</a>&lt;java.util.List&lt;? extends\
404-
<a href="../Foo4.html" title="class in pkg2">Foo4</a>&gt;&gt;</code></div>"""
403+
est2.html" title="class in pkg2">ParamTest2</a><wbr>&lt;java.util.List&lt;? ext\
404+
ends <a href="../Foo4.html" title="class in pkg2">Foo4</a>&gt;&gt;</code></div>"""
405405
);
406406

407407
checkOutput("pkg2/class-use/Foo4.html", true,
@@ -431,8 +431,8 @@ void checkTypeParameters() {
431431
<div class="col-first even-row-color"><code>&lt;T extends <a href="../ParamTest2\
432432
.html" title="class in pkg2">ParamTest2</a>&lt;java.util.List&lt;? extends <a hr\
433433
ef="../Foo4.html" title="class in pkg2">Foo4</a>&gt;&gt;&gt;<br><a href="../Para\
434-
mTest2.html" title="class in pkg2">ParamTest2</a>&lt;java.util.List&lt;? extends\
435-
<a href="../Foo4.html" title="class in pkg2">Foo4</a>&gt;&gt;</code></div>"""
434+
mTest2.html" title="class in pkg2">ParamTest2</a><wbr>&lt;java.util.List&lt;? ex\
435+
tends <a href="../Foo4.html" title="class in pkg2">Foo4</a>&gt;&gt;</code></div>"""
436436
);
437437

438438
// Type parameters in constructor and method args

test/langtools/jdk/javadoc/doclet/testProperty/TestProperty.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -89,8 +89,8 @@ public void testArrays() {
8989
// no tab classes should be used in the property table
9090
"""
9191
<div class="col-first even-row-color"><code>final <a href="ObjectProperty.html" \
92-
title="class in pkg">ObjectProperty</a>&lt;<a href="MyObj.html" title="class in \
93-
pkg">MyObj</a>[]&gt;</code></div>
92+
title="class in pkg">ObjectProperty</a><wbr>&lt;<a href="MyObj.html" title="clas\
93+
s in pkg">MyObj</a>[]&gt;</code></div>
9494
<div class="col-second even-row-color"><code><a href="#badProperty" class="membe\
9595
r-name-link">bad</a></code></div>
9696
<div class="col-last even-row-color">""",
@@ -99,8 +99,8 @@ public void testArrays() {
9999
"""
100100
<div class="col-first even-row-color method-summary-table method-summary-table-t\
101101
ab2 method-summary-table-tab4"><code>final <a href="ObjectProperty.html" title="\
102-
class in pkg">ObjectProperty</a>&lt;<a href="MyObj.html" title="class in pkg">My\
103-
Obj</a>[]&gt;</code></div>
102+
class in pkg">ObjectProperty</a><wbr>&lt;<a href="MyObj.html" title="class in pk\
103+
g">MyObj</a>[]&gt;</code></div>
104104
<div class="col-second even-row-color method-summary-table method-summary-table-\
105105
tab2 method-summary-table-tab4"><code><a href="#badProperty()" class="member-nam\
106106
e-link">badProperty</a>()</code></div>"""

0 commit comments

Comments
 (0)