Skip to content

Commit 07ecd42

Browse files
committed
8258602: JavaDoc field summary does not indicate final modifier
Reviewed-by: jjg
1 parent 276a1bf commit 07ecd42

File tree

8 files changed

+174
-15
lines changed

8 files changed

+174
-15
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ private void addModifier(Element member, Content code) {
243243
if (utils.isStatic(member)) {
244244
code.add("static ");
245245
}
246+
if (!utils.isEnum(member) && utils.isFinal(member)) {
247+
code.add("final ");
248+
}
246249
}
247250

248251
/**

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/FieldWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public interface FieldWriter extends MemberWriter {
7575
* Adds the preview output for the given member.
7676
*
7777
* @param member the member being documented
78-
* @param annotationDocTree content tree to which the preview information will be added
78+
* @param contentTree content tree to which the preview information will be added
7979
*/
8080
void addPreview(VariableElement member, Content contentTree);
8181

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/Utils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ public boolean isDefault(Element e) {
402402
return e.getModifiers().contains(Modifier.DEFAULT);
403403
}
404404

405+
public boolean isFinal(Element e) {
406+
return e.getModifiers().contains(Modifier.FINAL);
407+
}
408+
405409
public boolean isPackagePrivate(Element e) {
406410
return !(isPublic(e) || isPrivate(e) || isProtected(e));
407411
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void test1() {
7878
<dl class="notes">
7979
<dt>Property description:</dt>""",
8080
"""
81-
<div class="col-first odd-row-color"><code><a href="C.DoubleProperty.html" title\
81+
<div class="col-first odd-row-color"><code>final <a href="C.DoubleProperty.html" title\
8282
="class in pkg1">C.DoubleProperty</a></code></div>
8383
<div class="col-second odd-row-color"><code><a href="#rateProperty" class="membe\
8484
r-name-link">rate</a></code></div>
@@ -181,10 +181,10 @@ public void test1() {
181181
<div class="caption"><span>Properties</span></div>
182182
<div class="summary-table three-column-summary">""",
183183
"""
184-
<div class="col-first even-row-color"><code><a href="C.BooleanProperty.html" title="class in pkg1">C.BooleanProperty</a></code></div>
184+
<div class="col-first even-row-color"><code>final <a href="C.BooleanProperty.html" title="class in pkg1">C.BooleanProperty</a></code></div>
185185
""",
186186
"""
187-
<div class="col-first odd-row-color"><code><a href="C.DoubleProperty.html" title="class in pkg1">C.DoubleProperty</a></code></div>
187+
<div class="col-first odd-row-color"><code>final <a href="C.DoubleProperty.html" title="class in pkg1">C.DoubleProperty</a></code></div>
188188
""");
189189

190190
checkOutput("pkg1/C.html", false,
@@ -335,16 +335,16 @@ public void test3() {
335335
<div class="col-last odd-row-color method-summary-table method-summary-table-tab\
336336
2 method-summary-table-tab4">&nbsp;</div>
337337
<div class="col-first even-row-color method-summary-table method-summary-table-t\
338-
ab2 method-summary-table-tab4"><code>java.util.List&lt;java.util.Set&lt;? super \
339-
java.lang.Object&gt;&gt;</code></div>
338+
ab2 method-summary-table-tab4"><code>final java.util.List&lt;java.util.Set&lt;? \
339+
super java.lang.Object&gt;&gt;</code></div>
340340
<div class="col-second even-row-color method-summary-table method-summary-table-\
341341
tab2 method-summary-table-tab4"><code><a href="#deltaProperty()" class="member-n\
342342
ame-link">deltaProperty</a>()</code></div>
343343
<div class="col-last even-row-color method-summary-table method-summary-table-ta\
344344
b2 method-summary-table-tab4">&nbsp;</div>
345345
<div class="col-first odd-row-color method-summary-table method-summary-table-ta\
346-
b2 method-summary-table-tab4"><code>java.util.List&lt;java.lang.String&gt;</code\
347-
></div>
346+
b2 method-summary-table-tab4"><code>final java.util.List&lt;java.lang.String&gt;\
347+
</code></div>
348348
<div class="col-second odd-row-color method-summary-table method-summary-table-t\
349349
ab2 method-summary-table-tab4"><code><a href="#gammaProperty()" class="member-na\
350350
me-link">gammaProperty</a>()</code></div>

test/langtools/jdk/javadoc/doclet/testMemberSummary/TestMemberSummary.java

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
/*
2525
* @test
2626
* @bug 4951228 6290760 8025633 8026567 8081854 8162363 8175200 8177417 8186332 8182765
27+
* 8258602
2728
* @summary Test the case where the overridden method returns a different
2829
* type than the method in the child class. Make sure the
2930
* documentation is inherited but the return type isn't.
@@ -80,4 +81,101 @@ public void test() {
8081
<h3 id="f(java.lang.Object[])">f</h3>
8182
""");
8283
}
84+
85+
@Test
86+
public void testSummaries() {
87+
javadoc("-d", "out-summaries",
88+
"-private",
89+
"-sourcepath", testSrc,
90+
"pkg3");
91+
checkExit(Exit.OK);
92+
checkOutput("pkg3/Members.html", true,
93+
"""
94+
<div class="caption"><span>Nested Classes</span></div>
95+
<div class="summary-table three-column-summary">
96+
<div class="table-header col-first">Modifier and Type</div>
97+
<div class="table-header col-second">Class</div>
98+
<div class="table-header col-last">Description</div>
99+
<div class="col-first even-row-color"><code>private static interface&nbsp;</code></div>
100+
<div class="col-second even-row-color"><code><a href="Members.A.html" class="type-name-link" title="annotation interface in pkg3">Members.A</a></code></div>
101+
<div class="col-last even-row-color">&nbsp;</div>
102+
<div class="col-first odd-row-color"><code>private static final class&nbsp;</code></div>
103+
<div class="col-second odd-row-color"><code><a href="Members.C.html" class="type-name-link" title="class in pkg3">Members.C</a></code></div>
104+
<div class="col-last odd-row-color">&nbsp;</div>
105+
<div class="col-first even-row-color"><code>private static class&nbsp;</code></div>
106+
<div class="col-second even-row-color"><code><a href="Members.E.html" class="type-name-link" title="enum class in pkg3">Members.E</a></code></div>
107+
<div class="col-last even-row-color">&nbsp;</div>
108+
<div class="col-first odd-row-color"><code>private static interface&nbsp;</code></div>
109+
<div class="col-second odd-row-color"><code><a href="Members.I.html" class="type-name-link" title="interface in pkg3">Members.I</a></code></div>
110+
<div class="col-last odd-row-color">&nbsp;</div>
111+
<div class="col-first even-row-color"><code>private static final class&nbsp;</code></div>
112+
<div class="col-second even-row-color"><code><a href="Members.R.html" class="type-name-link" title="class in pkg3">Members.R</a></code></div>
113+
<div class="col-last even-row-color">&nbsp;</div>
114+
</div>""",
115+
"""
116+
<div class="caption"><span>Fields</span></div>
117+
<div class="summary-table three-column-summary">
118+
<div class="table-header col-first">Modifier and Type</div>
119+
<div class="table-header col-second">Field</div>
120+
<div class="table-header col-last">Description</div>
121+
<div class="col-first even-row-color"><code>private static final int</code></div>
122+
<div class="col-second even-row-color"><code><a href="#F" class="member-name-link">F</a></code></div>
123+
<div class="col-last even-row-color">&nbsp;</div>
124+
</div>""",
125+
"""
126+
<div class="caption"><span>Constructors</span></div>
127+
<div class="summary-table three-column-summary">
128+
<div class="table-header col-first">Modifier</div>
129+
<div class="table-header col-second">Constructor</div>
130+
<div class="table-header col-last">Description</div>
131+
<div class="col-first even-row-color"><code>private </code></div>
132+
<div class="col-constructor-name even-row-color"><code><a href="#%3Cinit%3E()" class="member-name-link">Members</a>()</code></div>
133+
<div class="col-last even-row-color">&nbsp;</div>
134+
</div>
135+
""");
136+
checkOutput("pkg3/Members.A.html", true,
137+
"""
138+
<div class="caption"><span>Required Elements</span></div>
139+
<div class="summary-table three-column-summary">
140+
<div class="table-header col-first">Modifier and Type</div>
141+
<div class="table-header col-second">Required Element</div>
142+
<div class="table-header col-last">Description</div>
143+
<div class="col-first even-row-color"><code>int</code></div>
144+
<div class="col-second even-row-color"><code><a href="#v()" class="member-name-link">v</a></code></div>
145+
<div class="col-last even-row-color">&nbsp;</div>
146+
</div>""",
147+
"""
148+
<div class="caption"><span>Optional Elements</span></div>
149+
<div class="summary-table three-column-summary">
150+
<div class="table-header col-first">Modifier and Type</div>
151+
<div class="table-header col-second">Optional Element</div>
152+
<div class="table-header col-last">Description</div>
153+
<div class="col-first even-row-color"><code><a href="https://download.java.net/java/early_access/jdk17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a></code></div>
154+
<div class="col-second even-row-color"><code><a href="#s()" class="member-name-link">s</a></code></div>
155+
<div class="col-last even-row-color">&nbsp;</div>
156+
</div>
157+
""");
158+
checkOutput("pkg3/Members.E.html", true,
159+
"""
160+
<h2>Enum Constant Summary</h2>
161+
<div class="caption"><span>Enum Constants</span></div>
162+
<div class="summary-table two-column-summary">
163+
<div class="table-header col-first">Enum Constant</div>
164+
<div class="table-header col-last">Description</div>
165+
<div class="col-first even-row-color"><code><a href="#C" class="member-name-link">C</a></code></div>
166+
<div class="col-last even-row-color">&nbsp;</div>
167+
</div>""");
168+
checkOutput("pkg3/Members.R.html", true,
169+
"""
170+
<div class="caption"><span>Fields</span></div>
171+
<div class="summary-table three-column-summary">
172+
<div class="table-header col-first">Modifier and Type</div>
173+
<div class="table-header col-second">Field</div>
174+
<div class="table-header col-last">Description</div>
175+
<div class="col-first even-row-color"><code>private final int</code></div>
176+
<div class="col-second even-row-color"><code><a href="#i" class="member-name-link">i</a></code></div>
177+
<div class="col-last even-row-color">
178+
<div class="block">The field for the <code>i</code> record component.</div>
179+
</div>""");
180+
}
83181
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package pkg3;
25+
26+
/**
27+
* Test class for member and nested class summaries
28+
*/
29+
public class Members {
30+
31+
private Members() {}
32+
33+
private static final int F = 3;
34+
35+
private static final class C {}
36+
37+
private static final void M() {}
38+
39+
private enum E {
40+
C;
41+
}
42+
43+
private interface I {
44+
default void i() {}
45+
}
46+
47+
private @interface A {
48+
int v();
49+
String s() default "";
50+
}
51+
52+
private record R(int i) {}
53+
54+
}

test/langtools/jdk/javadoc/doclet/testOverriddenMethods/TestOverrideMethods.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public void testSummary() {
347347
<div class="block">This is Base::m5.</div>
348348
</div>
349349
<div class="col-first odd-row-color method-summary-table method-summary-table-ta\
350-
b2 method-summary-table-tab4"><code>java.lang.Object</code></div>
350+
b2 method-summary-table-tab4"><code>final java.lang.Object</code></div>
351351
<div class="col-second odd-row-color method-summary-table method-summary-table-t\
352352
ab2 method-summary-table-tab4"><code><a href="#m6()" class="member-name-link">m6\
353353
</a>()</code></div>

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ public void testArrays() {
7777

7878
// no tab classes should be used in the property table
7979
"""
80-
<div class="col-first even-row-color"><code><a href="ObjectProperty.html" title="clas\
81-
s in pkg">ObjectProperty</a>&lt;<a href="MyObj.html" title="class in pkg">MyObj<\
82-
/a>[]&gt;</code></div>
80+
<div class="col-first even-row-color"><code>final <a href="ObjectProperty.html" \
81+
title="class in pkg">ObjectProperty</a>&lt;<a href="MyObj.html" title="class in \
82+
pkg">MyObj</a>[]&gt;</code></div>
8383
<div class="col-second even-row-color"><code><a href="#badProperty" class="membe\
8484
r-name-link">bad</a></code></div>
8585
<div class="col-last even-row-color">""",
8686

8787
// tab classes should be used in the method table
8888
"""
8989
<div class="col-first even-row-color method-summary-table method-summary-table-t\
90-
ab2 method-summary-table-tab4"><code><a href="ObjectProperty.html" title="class in pk\
91-
g">ObjectProperty</a>&lt;<a href="MyObj.html" title="class in pkg">MyObj</a>[]&g\
92-
t;</code></div>
90+
ab2 method-summary-table-tab4"><code>final <a href="ObjectProperty.html" title="\
91+
class in pkg">ObjectProperty</a>&lt;<a href="MyObj.html" title="class in pkg">My\
92+
Obj</a>[]&gt;</code></div>
9393
<div class="col-second even-row-color method-summary-table method-summary-table-\
9494
tab2 method-summary-table-tab4"><code><a href="#badProperty()" class="member-nam\
9595
e-link">badProperty</a>()</code></div>"""

0 commit comments

Comments
 (0)