Skip to content

Commit 83ea863

Browse files
8253559: The INDEX page should link to Serialized Form and Constant Values pages
Reviewed-by: hannesw
1 parent e66c6bb commit 83ea863

File tree

14 files changed

+100
-44
lines changed

14 files changed

+100
-44
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
4949
import jdk.javadoc.internal.doclets.toolkit.util.DocLink;
5050
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
51+
import jdk.javadoc.internal.doclets.toolkit.util.IndexItem;
5152

5253

5354
/**
@@ -60,11 +61,6 @@
6061
*/
6162
public class ConstantsSummaryWriterImpl extends HtmlDocletWriter implements ConstantsSummaryWriter {
6263

63-
/**
64-
* The configuration used in this run of the standard doclet.
65-
*/
66-
HtmlConfiguration configuration;
67-
6864
/**
6965
* The current class being documented.
7066
*/
@@ -81,14 +77,15 @@ public class ConstantsSummaryWriterImpl extends HtmlDocletWriter implements Cons
8177

8278
private final BodyContents bodyContents = new BodyContents();
8379

80+
private boolean hasConstants = false;
81+
8482
/**
8583
* Construct a ConstantsSummaryWriter.
8684
* @param configuration the configuration used in this run
8785
* of the standard doclet.
8886
*/
8987
public ConstantsSummaryWriterImpl(HtmlConfiguration configuration) {
9088
super(configuration, DocPaths.CONSTANT_VALUES);
91-
this.configuration = configuration;
9289
constantsTableHeader = new TableHeader(
9390
contents.modifierAndTypeLabel, contents.constantFieldLabel, contents.valueLabel);
9491
this.navBar = new Navigation(null, configuration, PageMode.CONSTANT_VALUES, path);
@@ -184,6 +181,7 @@ public Content getClassConstantHeader() {
184181
@Override
185182
public void addClassConstant(Content summariesTree, Content classConstantTree) {
186183
summaryTree.add(classConstantTree);
184+
hasConstants = true;
187185
}
188186

189187
@Override
@@ -283,5 +281,10 @@ public void addFooter() {
283281
public void printDocument(Content contentTree) throws DocFileIOException {
284282
contentTree.add(bodyContents);
285283
printHtmlDocument(null, "summary of constants", contentTree);
284+
285+
if (hasConstants && configuration.mainIndex != null) {
286+
configuration.mainIndex.add(IndexItem.of(IndexItem.Category.TAGS,
287+
resources.getText("doclet.Constants_Summary"), path));
288+
}
286289
}
287290
}

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

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package jdk.javadoc.internal.doclets.formats.html;
2727

28+
import java.util.Collection;
2829
import java.util.EnumMap;
2930
import java.util.Objects;
3031
import java.util.regex.Matcher;
@@ -103,7 +104,6 @@ public class Contents {
103104
public final Content fieldDetailsLabel;
104105
public final Content fieldSummaryLabel;
105106
public final Content fields;
106-
public final Content framesLabel;
107107
public final Content fromLabel;
108108
public final Content functionalInterface;
109109
public final Content functionalInterfaceMessage;
@@ -141,7 +141,6 @@ public class Contents {
141141
public final Content navServices;
142142
public final Content nestedClassSummary;
143143
public final Content newPage;
144-
public final Content noFramesLabel;
145144
public final Content noScriptMessage;
146145
public final Content openModuleLabel;
147146
public final Content openedTo;
@@ -189,10 +188,10 @@ public class Contents {
189188
Contents(HtmlConfiguration configuration) {
190189
this.resources = configuration.getDocResources();
191190

192-
allClassesLabel = getNonBreakContent("doclet.All_Classes");
191+
allClassesLabel = getNonBreakResource("doclet.All_Classes");
193192
allImplementedInterfacesLabel = getContent("doclet.All_Implemented_Interfaces");
194-
allModulesLabel = getNonBreakContent("doclet.All_Modules");
195-
allPackagesLabel = getNonBreakContent("doclet.All_Packages");
193+
allModulesLabel = getNonBreakResource("doclet.All_Modules");
194+
allPackagesLabel = getNonBreakResource("doclet.All_Packages");
196195
allSuperinterfacesLabel = getContent("doclet.All_Superinterfaces");
197196
also = getContent("doclet.also");
198197
annotationTypeOptionalMemberLabel = getContent("doclet.Annotation_Type_Optional_Member");
@@ -239,7 +238,6 @@ public class Contents {
239238
fieldSummaryLabel = getContent("doclet.Field_Summary");
240239
fieldLabel = getContent("doclet.Field");
241240
fields = getContent("doclet.Fields");
242-
framesLabel = getContent("doclet.Frames");
243241
fromLabel = getContent("doclet.From");
244242
functionalInterface = getContent("doclet.Functional_Interface");
245243
functionalInterfaceMessage = getContent("doclet.Functional_Interface_Message");
@@ -277,7 +275,6 @@ public class Contents {
277275
navServices = getContent("doclet.navServices");
278276
nestedClassSummary = getContent("doclet.Nested_Class_Summary");
279277
newPage = new Comment(resources.getText("doclet.New_Page"));
280-
noFramesLabel = getNonBreakContent("doclet.No_Frames");
281278
noScriptMessage = getContent("doclet.No_Script_Message");
282279
openedTo = getContent("doclet.OpenedTo");
283280
openModuleLabel = getContent("doclet.Open_Module");
@@ -400,6 +397,27 @@ public Content getContent(String key, Object o0, Object o1, Object o2) {
400397
return c;
401398
}
402399

400+
/**
401+
* Returns content composed of items joined together with the specified separator.
402+
*
403+
* @param separator the separator
404+
* @param items the items
405+
* @return the content
406+
*/
407+
public Content join(Content separator, Collection<Content> items) {
408+
Content result = new ContentBuilder();
409+
boolean first = true;
410+
for (Content c : items) {
411+
if (first) {
412+
first = false;
413+
} else {
414+
result.add(separator);
415+
}
416+
result.add(c);
417+
}
418+
return result;
419+
}
420+
403421
/**
404422
* Gets a {@code Content} object, containing the string for
405423
* a given key in the doclet's resources, substituting
@@ -409,8 +427,19 @@ public Content getContent(String key, Object o0, Object o1, Object o2) {
409427
* @param key the key for the desired string
410428
* @return a content tree for the string
411429
*/
412-
private Content getNonBreakContent(String key) {
413-
String text = resources.getText(key); // TODO: cache
430+
private Content getNonBreakResource(String key) {
431+
return getNonBreakString(resources.getText(key));
432+
}
433+
434+
/**
435+
* Gets a {@code Content} object for a string, substituting
436+
* <code>&nbsp;</code> for any space characters found in
437+
* the named resource string.
438+
*
439+
* @param text the string
440+
* @return a content tree for the string
441+
*/
442+
public Content getNonBreakString(String text) {
414443
Content c = new ContentBuilder();
415444
int start = 0;
416445
int p;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
5050
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
5151
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
52+
import jdk.javadoc.internal.doclets.toolkit.util.IndexItem;
5253

5354
/**
5455
* Generate File to list all the deprecated classes and class members with the
@@ -300,6 +301,11 @@ protected void generateDeprecatedListFile(DeprecatedAPIListBuilder deprapi)
300301
String description = "deprecated elements";
301302
body.add(bodyContents);
302303
printHtmlDocument(null, description, body);
304+
305+
if (!deprapi.isEmpty() && configuration.mainIndex != null) {
306+
configuration.mainIndex.add(IndexItem.of(IndexItem.Category.TAGS,
307+
resources.getText("doclet.Deprecated_API"), path));
308+
}
303309
}
304310

305311
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,14 @@ protected void generateOtherFiles(DocletEnvironment docEnv, ClassTree classtree)
171171
if (options.createIndex()) {
172172
SystemPropertiesWriter.generate(configuration);
173173
configuration.mainIndex.addElements();
174-
IndexWriter.generate(configuration);
175174
IndexBuilder allClassesIndex = new IndexBuilder(configuration, nodeprecated, true);
176175
allClassesIndex.addElements();
177176
AllClassesIndexWriter.generate(configuration, allClassesIndex);
178177
if (!configuration.packages.isEmpty()) {
179178
AllPackagesIndexWriter.generate(configuration);
180179
}
181180
configuration.mainIndex.createSearchIndexFiles();
181+
IndexWriter.generate(configuration);
182182
}
183183

184184
if (options.createOverview()) {

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.List;
2929
import java.util.ListIterator;
3030
import java.util.SortedSet;
31+
import java.util.stream.Collectors;
32+
import java.util.stream.Stream;
3133

3234
import javax.lang.model.element.Element;
3335
import javax.lang.model.element.ElementKind;
@@ -369,22 +371,14 @@ protected void addLinksForIndexes(List<Character> allFirstCharacters, Content co
369371
}
370372

371373
contentTree.add(new HtmlTree(TagName.BR));
372-
373-
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.ALLCLASSES_INDEX),
374-
contents.allClassesLabel));
375-
376-
if (!configuration.packages.isEmpty()) {
377-
contentTree.add(getVerticalSeparator());
378-
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.ALLPACKAGES_INDEX),
379-
contents.allPackagesLabel));
380-
}
381-
382-
boolean anySystemProperties = !mainIndex.getItems(DocTree.Kind.SYSTEM_PROPERTY).isEmpty();
383-
if (anySystemProperties) {
384-
contentTree.add(getVerticalSeparator());
385-
contentTree.add(links.createLink(pathToRoot.resolve(DocPaths.SYSTEM_PROPERTIES),
386-
contents.systemPropertiesLabel));
387-
}
374+
List<Content> pageLinks = Stream.of(IndexItem.Category.values())
375+
.flatMap(c -> mainIndex.getItems(c).stream())
376+
.filter(i -> !(i.isElementItem() || i.isTagItem()))
377+
.sorted((i1,i2)-> utils.compareStrings(i1.getLabel(), i2.getLabel()))
378+
.map(i -> links.createLink(pathToRoot.resolve(i.getUrl()),
379+
contents.getNonBreakString(i.getLabel())))
380+
.collect(Collectors.toList());
381+
contentTree.add(contents.join(getVerticalSeparator(), pageLinks));
388382
}
389383

390384
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter;
4141
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
4242
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
43+
import jdk.javadoc.internal.doclets.toolkit.util.IndexItem;
4344

4445
/**
4546
* Generates the Serialized Form Information Page, <i>serialized-form.html</i>.
@@ -250,6 +251,11 @@ public void addFooter() {
250251
public void printDocument(Content serializedTree) throws DocFileIOException {
251252
serializedTree.add(bodyContents);
252253
printHtmlDocument(null, "serialized forms", serializedTree);
254+
255+
if (configuration.mainIndex != null) {
256+
configuration.mainIndex.add(IndexItem.of(IndexItem.Category.TAGS,
257+
resources.getText("doclet.Serialized_Form"), path));
258+
}
253259
}
254260

255261
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ protected void buildSystemPropertiesPage() throws DocFileIOException {
126126
.addMainContent(mainContent)
127127
.setFooter(footer));
128128
printHtmlDocument(null, "system properties", body);
129+
130+
if (configuration.mainIndex != null) {
131+
configuration.mainIndex.add(IndexItem.of(IndexItem.Category.TAGS, title, path));
132+
}
129133
}
130134

131135
/**

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/standard.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ doclet.Functional_Interface_Message=\
112112
This is a functional interface and can therefore be used as the assignment target for a lambda \
113113
expression or method reference.
114114
doclet.also=also
115-
doclet.Frames=Frames
116-
doclet.No_Frames=No Frames
117115
doclet.Package_Hierarchies=Package Hierarchies:
118116
doclet.Hierarchy_For_Package=Hierarchy For Package {0}
119117
doclet.Hierarchy_For_All_Packages=Hierarchy For All Packages

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class DeprecatedAPIListBuilder {
4949
private final Map<DeprElementKind, SortedSet<Element>> deprecatedMap;
5050
private final BaseConfiguration configuration;
5151
private final Utils utils;
52+
5253
public enum DeprElementKind {
5354
REMOVAL,
5455
MODULE,
@@ -65,6 +66,7 @@ public enum DeprElementKind {
6566
ENUM_CONSTANT,
6667
ANNOTATION_TYPE_MEMBER // no ElementKind mapping
6768
};
69+
6870
/**
6971
* Constructor.
7072
*
@@ -81,6 +83,10 @@ public DeprecatedAPIListBuilder(BaseConfiguration configuration) {
8183
buildDeprecatedAPIInfo();
8284
}
8385

86+
public boolean isEmpty() {
87+
return deprecatedMap.values().stream().allMatch(Collection::isEmpty);
88+
}
89+
8490
/**
8591
* Build the sorted list of all the deprecated APIs in this run.
8692
* Build separate lists for deprecated modules, packages, classes, constructors,

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,13 @@ public void addElements() {
163163
public void add(IndexItem item) {
164164
Objects.requireNonNull(item);
165165

166-
itemsByFirstChar.computeIfAbsent(keyCharacter(item.getLabel()),
166+
if (item.isElementItem() || item.isTagItem()) {
167+
// don't put summary-page items in the A-Z index:
168+
// they are listed separately, at the top of the index page
169+
itemsByFirstChar.computeIfAbsent(keyCharacter(item.getLabel()),
167170
c -> new TreeSet<>(mainComparator))
168-
.add(item);
171+
.add(item);
172+
}
169173

170174
itemsByCategory.computeIfAbsent(item.getCategory(),
171175
c -> new TreeSet<>(mainComparator))
@@ -210,7 +214,7 @@ public SortedSet<IndexItem> getItems(IndexItem.Category cat) {
210214
public SortedSet<IndexItem> getItems(DocTree.Kind kind) {
211215
Objects.requireNonNull(kind);
212216
return itemsByCategory.getOrDefault(IndexItem.Category.TAGS, Collections.emptySortedSet()).stream()
213-
.filter(i -> i.getDocTree().getKind() == kind)
217+
.filter(i -> i.isKind(kind))
214218
.collect(Collectors.toCollection(() -> new TreeSet<>(mainComparator)));
215219
}
216220

0 commit comments

Comments
 (0)