Skip to content

Commit

Permalink
8266779: Use <wbr> instead of ZERO_WIDTH_SPACE
Browse files Browse the repository at this point in the history
Reviewed-by: prappo
  • Loading branch information
hns committed May 10, 2021
1 parent 0cc7833 commit 8851cb6
Show file tree
Hide file tree
Showing 25 changed files with 371 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.DocletConstants;

Expand Down Expand Up @@ -91,7 +92,7 @@ protected Content getSummaryLink(Element member) {
}
String signature = utils.flatSignature((ExecutableElement) member, typeElement);
if (signature.length() > 2) {
content.add(Entity.ZERO_WIDTH_SPACE);
content.add(new HtmlTree(TagName.WBR));
}
content.add(signature);

Expand Down Expand Up @@ -209,8 +210,8 @@ public Boolean visitDeclared(DeclaredType t, Void unused) {
protected void addParameters(ExecutableElement member, Content htmltree) {
Content paramTree = getParameters(member, false);
if (paramTree.charCount() > 2) {
// only add zero-width-space for non-empty parameters
htmltree.add(Entity.ZERO_WIDTH_SPACE);
// only add <wbr> for non-empty parameters
htmltree.add(new HtmlTree(TagName.WBR));
}
htmltree.add(paramTree);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import javax.lang.model.type.TypeMirror;

import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.Entity;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.TagName;
import jdk.javadoc.internal.doclets.toolkit.BaseConfiguration;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.Resources;
Expand Down Expand Up @@ -171,7 +171,7 @@ protected Content getTypeParameterLinks(LinkInfo linkInfo) {
for (TypeMirror t : vars) {
if (many) {
links.add(",");
links.add(Entity.ZERO_WIDTH_SPACE);
links.add(new HtmlTree(TagName.WBR));
if (((HtmlLinkInfo) linkInfo).getContext() == HtmlLinkInfo.Kind.MEMBER_TYPE_PARAMS) {
links.add(DocletConstants.NL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ private void appendParametersAndExceptions(Content htmlTree, int lastLineSeparat
// empty parameters are added without packing
htmlTree.add(parameters);
} else {
htmlTree.add(Entity.ZERO_WIDTH_SPACE)
htmlTree.add(new HtmlTree(TagName.WBR))
.add(HtmlTree.SPAN(HtmlStyle.parameters, parameters));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ public class Entity extends Content {
public static final Entity GREATER_THAN = new Entity("&gt;");
public static final Entity AMPERSAND = new Entity("&amp;");
public static final Entity NO_BREAK_SPACE = new Entity("&nbsp;");
public static final Entity ZERO_WIDTH_SPACE = new Entity("&#8203;") {
@Override
public int charCount() {
return 0;
}
};

public final String text;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,8 @@ public boolean isValid() {
(hasAttr(HtmlAttr.TYPE) && hasContent()));
case SPAN:
return (hasAttr(HtmlAttr.ID) || hasContent());
case WBR:
return (!hasContent());
default :
return hasContent();
}
Expand All @@ -942,6 +944,7 @@ public boolean isInline() {
switch (tagName) {
case A: case BUTTON: case BR: case CODE: case EM: case I: case IMG:
case LABEL: case SMALL: case SPAN: case STRONG: case SUB: case SUP:
case WBR:
return true;
default:
return false;
Expand All @@ -957,7 +960,7 @@ public boolean isInline() {
*/
public boolean isVoid() {
switch (tagName) {
case BR: case HR: case IMG: case INPUT: case LINK: case META:
case BR: case HR: case IMG: case INPUT: case LINK: case META: case WBR:
return true;
default:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public enum TagName {
TH,
TITLE,
TR,
UL;
UL,
WBR;

public final String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void test() {
"""
<section class="detail" id="&lt;init&gt;()">""",
"""
<a href="#%3Cinit%3E(int)" class="member-name-link">Outer</a>&#8203;(int&nbsp;i)""",
<a href="#%3Cinit%3E(int)" class="member-name-link">Outer</a><wbr>(int&nbsp;i)""",
"""
<section class="detail" id="&lt;init&gt;(int)">""");

Expand All @@ -79,7 +79,7 @@ public void test() {
"""
<section class="detail" id="&lt;init&gt;()">""",
"""
<a href="#%3Cinit%3E(int)" class="member-name-link">Inner</a>&#8203;(int&nbsp;i)""",
<a href="#%3Cinit%3E(int)" class="member-name-link">Inner</a><wbr>(int&nbsp;i)""",
"""
<section class="detail" id="&lt;init&gt;(int)">""");

Expand All @@ -89,7 +89,7 @@ public void test() {
"""
<section class="detail" id="&lt;init&gt;()">""",
"""
<a href="#%3Cinit%3E(int)" class="member-name-link">NestedInner</a>&#8203;(int&nbsp;i)""",
<a href="#%3Cinit%3E(int)" class="member-name-link">NestedInner</a><wbr>(int&nbsp;i)""",
"""
<section class="detail" id="&lt;init&gt;(int)">""");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,11 @@ public void test() {
<div class="col-last odd-row-color">
<div class="deprecation-comment">class_test5 passes. This is the second sentence of deprecated description for a method.</div>
</div>
<div class="col-summary-item-name even-row-color"><a href="pkg/TestClass.html#overloadedMethod(int)">pkg.TestClass.overloadedMethod&#8203;(int)</a></div>
<div class="col-summary-item-name even-row-color"><a href="pkg/TestClass.html#overloadedMethod(int)">pkg.TestClass.overloadedMethod<wbr>(int)</a></div>
<div class="col-last even-row-color">
<div class="deprecation-comment">class_test7 passes. Overloaded method 2.</div>
</div>
<div class="col-summary-item-name odd-row-color"><a href="pkg/TestClass.html#overloadedMethod(java.lang.String)">pkg.TestClass.overloadedMethod&#8203;(String)</a></div>
<div class="col-summary-item-name odd-row-color"><a href="pkg/TestClass.html#overloadedMethod(java.lang.String)">pkg.TestClass.overloadedMethod<wbr>(String)</a></div>
<div class="col-last odd-row-color">
<div class="deprecation-comment">class_test6 passes. Overloaded method 1.</div>
</div>""",
Expand All @@ -375,7 +375,7 @@ public void test() {
<div class="col-last odd-row-color">
<div class="deprecation-comment">class_test3 passes. This is the second sentence of deprecated description for a constructor.</div>
</div>
<div class="col-summary-item-name even-row-color"><a href="pkg/TestClass.html#%3Cinit%3E(java.lang.String)">pkg.TestClass&#8203;(String)</a></div>
<div class="col-summary-item-name even-row-color"><a href="pkg/TestClass.html#%3Cinit%3E(java.lang.String)">pkg.TestClass<wbr>(String)</a></div>
<div class="col-last even-row-color">
<div class="deprecation-comment">class_test4 passes. Overloaded constructor.</div>
</div>""");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2021, 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 @@ -68,7 +68,7 @@ public void test1(Path base) throws Exception {
"Constructor Summary",
"Modifier", "Constructor",
"private", """
<a href="#%3Cinit%3E(int)" class="member-name-link">TestEnum</a>&#8203;(int&nbsp;val)""");
<a href="#%3Cinit%3E(int)" class="member-name-link">TestEnum</a><wbr>(int&nbsp;val)""");
checkOutput("index-all.html", true,
"""
<a href="pkg/TestEnum.html#%3Cinit%3E(int)" class="member-name-link">TestEnum(int)</a>""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ r interface in java.util" class="external-link">List</a>&lt;? extends <a href="h
<li><code><a href="http://example.com/docs/api/java.base/java/util/Map.html" title="\
class or interface in java.util" class="external-link">Map</a>&lt;<a href="http://ex\
ample.com/docs/api/java.base/java/lang/String.html" title="class or interface in jav\
a.lang" class="external-link">String</a>,&#8203;? extends <a href="http://example.co\
m/docs/api/java.base/java/lang/CharSequence.html" title="class or interface in java.\
lang" class="external-link">CharSequence</a>&gt;</code></li>
a.lang" class="external-link">String</a>,<wbr>? extends <a href="http://example.com/\
docs/api/java.base/java/lang/CharSequence.html" title="class or interface in java.la\
ng" class="external-link">CharSequence</a>&gt;</code></li>
<li><code><a href="http://example.com/docs/api/java.base/java/util/Map.html" title="\
class or interface in java.util" class="external-link">Map</a>&lt;<a href="http://ex\
ample.com/docs/api/java.base/java/lang/String.html" title="class or interface in jav\
a.lang" class="external-link">String</a>,&#8203;? super <a href="A.html" title="clas\
s in pkg1">A</a>&lt;<a href="http://example.com/docs/api/java.base/java/lang/String.\
html" title="class or interface in java.lang" class="external-link">String</a>,&#820\
3;? extends <a href="http://example.com/docs/api/java.base/java/lang/RuntimeExceptio\
n.html" title="class or interface in java.lang" class="external-link">RuntimeExcepti\
on</a>&gt;&gt;</code></li>
a.lang" class="external-link">String</a>,<wbr>? super <a href="A.html" title="class \
in pkg1">A</a>&lt;<a href="http://example.com/docs/api/java.base/java/lang/String.ht\
ml" title="class or interface in java.lang" class="external-link">String</a>,<wbr>? \
extends <a href="http://example.com/docs/api/java.base/java/lang/RuntimeException.ht\
ml" title="class or interface in java.lang" class="external-link">RuntimeException</\
a>&gt;&gt;</code></li>
<li><a href="#someMethod(java.util.List,int)"><code>someMethod(List&lt;Number&gt;, i\
nt)</code></a></li>
<li><a href="#otherMethod(java.util.Map,double)"><code>otherMethod(Map&lt;String, ? \
Expand All @@ -97,8 +97,8 @@ class or interface in java.util" class="external-link">Map</a>&lt;<a href="http:
"""
<div class="block"><code><a href="A.html" title="class in pkg1">A</a>&lt;<a href="h\
ttp://example.com/docs/api/java.base/java/lang/String.html" title="class or interfa\
ce in java.lang" class="external-link">String</a>,&#8203;<a href="A.SomeException.h\
tml" title="class in pkg1">A.SomeException</a>&gt;</code>
ce in java.lang" class="external-link">String</a>,<wbr><a href="A.SomeException.htm\
l" title="class in pkg1">A.SomeException</a>&gt;</code>
<a href="http://example.com/docs/api/java.base/java/util/Map.html" title="class or\
interface in java.util" class="external-link">link to generic type with label</a>\
</div>""",
Expand All @@ -109,8 +109,8 @@ interface in java.util" class="external-link">link to generic type with label</a
<ul class="see-list-long">
<li><code><a href="A.html" title="class in pkg1">A</a>&lt;<a href="http://example.c\
om/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang\
" class="external-link">String</a>,&#8203;<a href="A.SomeException.html" title="cla\
ss in pkg1">A.SomeException</a>&gt;</code></li>
" class="external-link">String</a>,<wbr><a href="A.SomeException.html" title="class\
in pkg1">A.SomeException</a>&gt;</code></li>
<li><a href="http://example.com/docs/api/java.base/java/util/List.html" title="clas\
s or interface in java.util" class="external-link"><code>Link to generic type with \
label</code></a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ void checkHtmlTableContents() {
ab2 method-summary-table-tab4"><code>void</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-\
tab2 method-summary-table-tab4"><code><a href="#method1(int,int)" class="member-\
name-link">method1</a>&#8203;(int&nbsp;a,
name-link">method1</a><wbr>(int&nbsp;a,
int&nbsp;b)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-ta\
b2 method-summary-table-tab4">
Expand All @@ -631,8 +631,8 @@ void checkHtmlTableContents() {
kg1">C1</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-\
tab2 method-summary-table-tab4"><code><a href="#method(pkg1.C1)" class="member-n\
ame-link">method</a>&#8203;(<a href="../pkg1/C1.html" title="class \
in pkg1">C1</a>&nbsp;param)</code></div>
ame-link">method</a><wbr>(<a href="../pkg1/C1.html" title="class in pkg1">C1</a>\
&nbsp;param)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-ta\
b2 method-summary-table-tab4">
<div class="block">A sample method.</div>
Expand Down Expand Up @@ -680,8 +680,8 @@ void checkHtmlTableContents() {
<div class="col-first even-row-color"><code><a href="../C2.html" title="class in pkg2">C2</a></code></div>
<div class="col-second even-row-color"><span class="type-name-label">C1.</span><\
code><a href="../../pkg1/C1.html#method(pkg2.C2)" class="member-name-link">metho\
d</a>&#8203;(<a href="../C2.html" title="class in pkg2">C2</a>&nbsp\
;param)</code></div>
d</a><wbr>(<a href="../C2.html" title="class in pkg2">C2</a>&nbsp;param)</code><\
/div>
<div class="col-last even-row-color">
<div class="block">Method thats does some processing.</div>
</div>""");
Expand Down Expand Up @@ -769,7 +769,7 @@ void checkHtmlTableContentsNoComment() {
ab2 method-summary-table-tab4"><code>void</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-\
tab2 method-summary-table-tab4"><code><a href="#method1(int,int)" class="member-\
name-link">method1</a>&#8203;(int&nbsp;a,
name-link">method1</a><wbr>(int&nbsp;a,
int&nbsp;b)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-ta\
b2 method-summary-table-tab4"></div>""");
Expand All @@ -785,8 +785,8 @@ void checkHtmlTableContentsNoComment() {
kg1">C1</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-\
tab2 method-summary-table-tab4"><code><a href="#method(pkg1.C1)" class="member-n\
ame-link">method</a>&#8203;(<a href="../pkg1/C1.html" title="class in pkg1">C1</\
a>&nbsp;param)</code></div>
ame-link">method</a><wbr>(<a href="../pkg1/C1.html" title="class in pkg1">C1</a>\
&nbsp;param)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-ta\
b2 method-summary-table-tab4"></div>""");

Expand Down Expand Up @@ -827,7 +827,7 @@ void checkHtmlTableContentsNoComment() {
<div class="col-first even-row-color"><code><a href="../C2.html" title="class in pkg2">C2</a></code></div>
<div class="col-second even-row-color"><span class="type-name-label">C1.</span><\
code><a href="../../pkg1/C1.html#method(pkg2.C2)" class="member-name-link">metho\
d</a>&#8203;(<a href="../C2.html" title="class in pkg2">C2</a>&nbsp;param)</code></div>
d</a><wbr>(<a href="../C2.html" title="class in pkg2">C2</a>&nbsp;param)</code></div>
<div class="col-last even-row-color"></div>""");

// Package use documentation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, 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 @@ -52,7 +52,7 @@ public void test() {
"""
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span c\
lass="type-parameters">&lt;T&gt;</span>&nbsp;<span class="return-type">void</spa\
n>&nbsp;<span class="element-name">m</span>&#8203;<span class="parameters">(T&nbsp;t1,
n>&nbsp;<span class="element-name">m</span><wbr><span class="parameters">(T&nbsp;t1,
T&nbsp;t2)</span>
throws <span class="exceptions">java.lang.Exception</span></div>""");

Expand Down

1 comment on commit 8851cb6

@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.