This repository has been archived by the owner on Aug 27, 2022. It is now read-only.
/
AllClassesIndexWriter.java
183 lines (172 loc) · 7.73 KB
/
AllClassesIndexWriter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright (c) 2018, 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.javadoc.internal.doclets.formats.html;
import java.util.ArrayList;
import java.util.List;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import com.sun.source.doctree.DocTree;
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents;
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
import jdk.javadoc.internal.doclets.formats.html.markup.Navigation;
import jdk.javadoc.internal.doclets.formats.html.markup.Navigation.PageMode;
import jdk.javadoc.internal.doclets.formats.html.markup.Table;
import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
import jdk.javadoc.internal.doclets.toolkit.util.IndexBuilder;
/**
* Generate the file with list of all the classes in this run.
*/
public class AllClassesIndexWriter extends HtmlDocletWriter {
/**
* Index of all the classes.
*/
protected IndexBuilder indexBuilder;
/**
* Construct AllClassesIndexWriter object. Also initializes the indexBuilder variable in this
* class.
*
* @param configuration The current configuration
* @param filename Path to the file which is getting generated.
* @param indexBuilder Unicode based Index from {@link IndexBuilder}
*/
public AllClassesIndexWriter(HtmlConfiguration configuration,
DocPath filename, IndexBuilder indexBuilder) {
super(configuration, filename);
this.indexBuilder = indexBuilder;
}
/**
* Create AllClassesIndexWriter object.
*
* @param configuration The current configuration
* @param indexBuilder IndexBuilder object for all classes index.
* @throws DocFileIOException
*/
public static void generate(HtmlConfiguration configuration,
IndexBuilder indexBuilder) throws DocFileIOException {
generate(configuration, indexBuilder, DocPaths.ALLCLASSES_INDEX);
}
private static void generate(HtmlConfiguration configuration, IndexBuilder indexBuilder,
DocPath fileName) throws DocFileIOException {
AllClassesIndexWriter allClassGen = new AllClassesIndexWriter(configuration,
fileName, indexBuilder);
allClassGen.buildAllClassesFile();
}
/**
* Print all the classes in the file.
*/
protected void buildAllClassesFile() throws DocFileIOException {
String label = resources.getText("doclet.All_Classes");
Content header = new ContentBuilder();
addTop(header);
Navigation navBar = new Navigation(null, configuration, PageMode.ALLCLASSES, path);
navBar.setUserHeader(getUserHeaderFooter(true));
header.add(navBar.getContent(true));
Content allClassesContent = new ContentBuilder();
addContents(allClassesContent);
Content mainContent = new ContentBuilder();
mainContent.add(allClassesContent);
Content footer = HtmlTree.FOOTER();
navBar.setUserFooter(getUserHeaderFooter(false));
footer.add(navBar.getContent(false));
addBottom(footer);
HtmlTree bodyTree = getBody(getWindowTitle(label));
bodyTree.add(new BodyContents()
.setHeader(header)
.addMainContent(mainContent)
.setFooter(footer)
.toContent());
printHtmlDocument(null, "class index", bodyTree);
}
/**
* Add all types to the content tree.
*
* @param content HtmlTree content to which the links will be added
*/
protected void addContents(Content content) {
Table table = new Table(HtmlStyle.typeSummary)
.setHeader(new TableHeader(contents.classLabel, contents.descriptionLabel))
.setRowScopeColumn(1)
.setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colLast)
.setDefaultTab(resources.getText("doclet.All_Classes"))
.addTab(resources.interfaceSummary, utils::isInterface)
.addTab(resources.classSummary, e -> utils.isOrdinaryClass((TypeElement)e))
.addTab(resources.enumSummary, utils::isEnum)
.addTab(resources.exceptionSummary, e -> utils.isException((TypeElement)e))
.addTab(resources.errorSummary, e -> utils.isError((TypeElement)e))
.addTab(resources.annotationTypeSummary, utils::isAnnotationType)
.setTabScript(i -> "show(" + i + ");");
for (Character unicode : indexBuilder.keys()) {
for (Element element : indexBuilder.getMemberList(unicode)) {
TypeElement typeElement = (TypeElement) element;
if (!utils.isCoreClass(typeElement)) {
continue;
}
addTableRow(table, typeElement);
}
}
Content titleContent = contents.allClassesLabel;
Content pHeading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING, true,
HtmlStyle.title, titleContent);
Content headerDiv = HtmlTree.DIV(HtmlStyle.header, pHeading);
content.add(headerDiv);
if (!table.isEmpty()) {
content.add(table.toContent());
if (table.needsScript()) {
getMainBodyScript().append(table.getScript());
}
}
}
/**
* Add table row.
*
* @param table the table to which the row will be added
* @param klass the type to be added to the table
*/
protected void addTableRow(Table table, TypeElement klass) {
List<Content> rowContents = new ArrayList<>();
Content classLink = getLink(new LinkInfoImpl(
configuration, LinkInfoImpl.Kind.INDEX, klass));
ContentBuilder description = new ContentBuilder();
if (utils.isDeprecated(klass)) {
description.add(getDeprecatedPhrase(klass));
List<? extends DocTree> tags = utils.getDeprecatedTrees(klass);
if (!tags.isEmpty()) {
addSummaryDeprecatedComment(klass, tags.get(0), description);
}
} else {
addSummaryComment(klass, description);
}
rowContents.add(classLink);
rowContents.add(description);
table.addRow(klass, rowContents);
}
}