Skip to content

Commit

Permalink
8303123: Add line break opportunity to single type parameters
Browse files Browse the repository at this point in the history
Reviewed-by: jjg
  • Loading branch information
hns committed Apr 3, 2023
1 parent 094e03d commit 2e91585
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ protected void addModifiersAndType(Element member, TypeMirror type,
if (list != null && !list.isEmpty()) {
Content typeParameters = ((AbstractExecutableMemberWriter) this)
.getTypeParameters((ExecutableElement)member);
code.add(typeParameters);
//Code to avoid ugly wrapping in member summary table.
code.add(typeParameters);
// Add explicit line break between method type parameters and
// return type in member summary table to avoid random wrapping.
if (typeParameters.charCount() > 10) {
code.add(new HtmlTree(TagName.BR));
} else {
Expand All @@ -212,7 +213,8 @@ protected void addModifiersAndType(Element member, TypeMirror type,
}
code.add(
writer.getLink(new HtmlLinkInfo(configuration,
HtmlLinkInfo.Kind.LINK_TYPE_PARAMS, type)));
HtmlLinkInfo.Kind.LINK_TYPE_PARAMS, type)
.addLineBreakOpportunitiesInTypeParameters(true)));
}
target.add(code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ protected Content getTypeParameterLinks(HtmlLinkInfo linkInfo) {
return links;
}
if (!vars.isEmpty()) {
if (linkInfo.addLineBreakOpportunitiesInTypeParameters()) {
links.add(new HtmlTree(TagName.WBR));
}
links.add("<");
boolean many = false;
for (TypeMirror t : vars) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ public enum Kind {
// True iff the preview flags should be skipped for this link.
private boolean skipPreview;

// True if type parameters should be separated by line breaks.
// True if type parameters should be separated by hard line breaks.
private boolean addLineBreaksInTypeParameters = false;

// True if additional <wbr> tags should be added to type parameters
private boolean addLineBreakOpportunitiesInTypeParameters = false;

// True if annotations on type parameters should be shown.
private boolean showTypeParameterAnnotations = false;

Expand Down Expand Up @@ -311,6 +314,23 @@ public boolean addLineBreaksInTypeParameters() {
return addLineBreaksInTypeParameters;
}

/**
* Sets the addLineBreakOpportunitiesInTypeParameters flag for this link.
* @param addLineBreakOpportunities the new value
* @return this object
*/
public HtmlLinkInfo addLineBreakOpportunitiesInTypeParameters(boolean addLineBreakOpportunities) {
this.addLineBreakOpportunitiesInTypeParameters = addLineBreakOpportunities;
return this;
}

/**
* {@return true if line break opportunities should be added to type parameters}
*/
public boolean addLineBreakOpportunitiesInTypeParameters() {
return addLineBreakOpportunitiesInTypeParameters;
}

/**
* Set the linkToSelf flag for this link.
* @param linkToSelf the new value
Expand Down
10 changes: 5 additions & 5 deletions test/langtools/jdk/javadoc/doclet/testJavaFX/TestJavaFX.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -369,16 +369,16 @@ public void test3() {
<div class="col-last odd-row-color method-summary-table method-summary-table-tab\
2 method-summary-table-tab4">&nbsp;</div>
<div class="col-first even-row-color method-summary-table method-summary-table-t\
ab2 method-summary-table-tab4"><code>final java.util.List&lt;java.util.Set&lt;? \
super java.lang.Object&gt;&gt;</code></div>
ab2 method-summary-table-tab4"><code>final java.util.List<wbr>&lt;java.util.Set&\
lt;? super java.lang.Object&gt;&gt;</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-\
tab2 method-summary-table-tab4"><code><a href="#deltaProperty()" class="member-n\
ame-link">deltaProperty</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-ta\
b2 method-summary-table-tab4">&nbsp;</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-ta\
b2 method-summary-table-tab4"><code>final java.util.List&lt;java.lang.String&gt;\
</code></div>
b2 method-summary-table-tab4"><code>final java.util.List<wbr>&lt;java.lang.Strin\
g&gt;</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-t\
ab2 method-summary-table-tab4"><code><a href="#gammaProperty()" class="member-na\
me-link">gammaProperty</a>()</code></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -272,7 +272,7 @@ void checkTypeParameters() {
></span></div>""",
"""
<div class="col-first even-row-color"><code><a href="../ParamTest.html" title="class\
in pkg2">ParamTest</a>&lt;<a href="../Foo.html" title="class in pkg2">Foo</a>&g\
in pkg2">ParamTest</a><wbr>&lt;<a href="../Foo.html" title="class in pkg2">Foo</a>&g\
t;</code></div>"""
);

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

Expand Down Expand Up @@ -331,9 +331,9 @@ void checkTypeParameters() {
declared as <a href="../ParamTest.html" title="class in pkg2">ParamTest</a></s\
pan></div>""",
"""
<div class="col-first even-row-color"><code><a href="../ParamTest.html" title="class\
in pkg2">ParamTest</a>&lt;<a href="../Foo.html" title="class in pkg2">Foo</a>&\
gt;</code></div>""",
<div class="col-first even-row-color"><code><a href="../ParamTest.html" title="\
class in pkg2">ParamTest</a><wbr>&lt;<a href="../Foo.html" title="class in pkg2\
">Foo</a>&gt;</code></div>""",
"""
<div class="caption"><span>Methods in <a href="../package-summary.html">pkg2</a\
> with type parameters of type <a href="../ParamTest.html" title="class in pkg2\
Expand All @@ -342,8 +342,8 @@ void checkTypeParameters() {
<div class="col-first even-row-color"><code>&lt;T extends <a href="../ParamTest.html\
" title="class in pkg2">ParamTest</a>&lt;<a href="../Foo3.html" title="class in\
pkg2">Foo3</a>&gt;&gt;<br><a href="../ParamTest.html" title="class in pkg2">Pa\
ramTest</a>&lt;<a href="../Foo3.html" title="class in pkg2">Foo3</a>&gt;</code>\
</div>"""
ramTest</a><wbr>&lt;<a href="../Foo3.html" title="class in pkg2">Foo3</a>&gt;</\
code></div>"""
);

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

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

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

// Type parameters in constructor and method args
Expand Down
10 changes: 5 additions & 5 deletions test/langtools/jdk/javadoc/doclet/testProperty/TestProperty.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -89,8 +89,8 @@ public void testArrays() {
// no tab classes should be used in the property table
"""
<div class="col-first even-row-color"><code>final <a href="ObjectProperty.html" \
title="class in pkg">ObjectProperty</a>&lt;<a href="MyObj.html" title="class in \
pkg">MyObj</a>[]&gt;</code></div>
title="class in pkg">ObjectProperty</a><wbr>&lt;<a href="MyObj.html" title="clas\
s in pkg">MyObj</a>[]&gt;</code></div>
<div class="col-second even-row-color"><code><a href="#badProperty" class="membe\
r-name-link">bad</a></code></div>
<div class="col-last even-row-color">""",
Expand All @@ -99,8 +99,8 @@ public void testArrays() {
"""
<div class="col-first even-row-color method-summary-table method-summary-table-t\
ab2 method-summary-table-tab4"><code>final <a href="ObjectProperty.html" title="\
class in pkg">ObjectProperty</a>&lt;<a href="MyObj.html" title="class in pkg">My\
Obj</a>[]&gt;</code></div>
class in pkg">ObjectProperty</a><wbr>&lt;<a href="MyObj.html" title="class in pk\
g">MyObj</a>[]&gt;</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-\
tab2 method-summary-table-tab4"><code><a href="#badProperty()" class="member-nam\
e-link">badProperty</a>()</code></div>"""
Expand Down

1 comment on commit 2e91585

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.