author | hannesw |
Wed, 27 Nov 2019 13:08:16 +0100 | |
changeset 59294 | 48b88b9c11eb |
parent 54350 | 4f9772f4403d |
permissions | -rw-r--r-- |
10 | 1 |
/* |
53863
d001808c57e8
8218998: Add metadata to generated API documentation files
jjg
parents:
53562
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
26 |
package jdk.javadoc.internal.doclets.formats.html; |
10 | 27 |
|
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
28 |
import java.util.SortedSet; |
2216
b124d5c924eb
6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents:
1787
diff
changeset
|
29 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
30 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
31 |
|
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
32 |
import jdk.javadoc.internal.doclets.formats.html.markup.BodyContents; |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
33 |
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
34 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
35 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
36 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; |
49551
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48654
diff
changeset
|
37 |
import jdk.javadoc.internal.doclets.formats.html.markup.Navigation; |
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48654
diff
changeset
|
38 |
import jdk.javadoc.internal.doclets.formats.html.markup.Navigation.PageMode; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
39 |
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
40 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
41 |
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; |
40587 | 42 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
43 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
44 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
2216
b124d5c924eb
6786690: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - DL tag and nesting issue
bpatel
parents:
1787
diff
changeset
|
45 |
|
10 | 46 |
/** |
47 |
* Generate Class Hierarchy page for all the Classes in this run. Use |
|
48 |
* ClassTree for building the Tree. The name of |
|
49 |
* the generated file is "overview-tree.html" and it is generated in the |
|
50 |
* current or the destination directory. |
|
51 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
52 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
53 |
* If you write code that depends on this, you do so at your own risk. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
54 |
* This code and its internal interfaces are subject to change or |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
55 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
56 |
* |
10 | 57 |
* @author Atul M Dambalkar |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
58 |
* @author Bhavesh Patel (Modified) |
10 | 59 |
*/ |
60 |
public class TreeWriter extends AbstractTreeWriter { |
|
61 |
||
62 |
/** |
|
63 |
* Packages in this run. |
|
64 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
65 |
SortedSet<PackageElement> packages; |
10 | 66 |
|
67 |
/** |
|
68 |
* True if there are no packages specified on the command line, |
|
69 |
* False otherwise. |
|
70 |
*/ |
|
40587 | 71 |
private final boolean classesOnly; |
10 | 72 |
|
49551
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48654
diff
changeset
|
73 |
private final Navigation navBar; |
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48654
diff
changeset
|
74 |
|
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
75 |
protected BodyContents bodyContents; |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
76 |
|
10 | 77 |
/** |
78 |
* Constructor to construct TreeWriter object. |
|
79 |
* |
|
80 |
* @param configuration the current configuration of the doclet. |
|
81 |
* @param filename String filename |
|
82 |
* @param classtree the tree being built. |
|
83 |
*/ |
|
45417 | 84 |
public TreeWriter(HtmlConfiguration configuration, DocPath filename, ClassTree classtree) { |
10 | 85 |
super(configuration, filename, classtree); |
86 |
packages = configuration.packages; |
|
40587 | 87 |
classesOnly = packages.isEmpty(); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
88 |
this.navBar = new Navigation(null, configuration, PageMode.TREE, path); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
89 |
this.bodyContents = new BodyContents(); |
10 | 90 |
} |
91 |
||
92 |
/** |
|
93 |
* Create a TreeWriter object and use it to generate the |
|
94 |
* "overview-tree.html" file. |
|
95 |
* |
|
40587 | 96 |
* @param configuration the configuration for this doclet |
10 | 97 |
* @param classtree the class tree being documented. |
40587 | 98 |
* @throws DocFileIOException if there is a problem generating the overview tree page |
10 | 99 |
*/ |
45417 | 100 |
public static void generate(HtmlConfiguration configuration, |
40587 | 101 |
ClassTree classtree) throws DocFileIOException { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
102 |
DocPath filename = DocPaths.OVERVIEW_TREE; |
40587 | 103 |
TreeWriter treegen = new TreeWriter(configuration, filename, classtree); |
104 |
treegen.generateTreeFile(); |
|
10 | 105 |
} |
106 |
||
107 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
108 |
* Generate the interface hierarchy and class hierarchy. |
40587 | 109 |
* |
110 |
* @throws DocFileIOException if there is a problem generating the overview tree page |
|
10 | 111 |
*/ |
40587 | 112 |
public void generateTreeFile() throws DocFileIOException { |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
113 |
HtmlTree body = getTreeHeader(); |
40303 | 114 |
Content headContent = contents.hierarchyForAllPackages; |
53991 | 115 |
Content heading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING, false, |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
116 |
HtmlStyle.title, headContent); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
117 |
Content div = HtmlTree.DIV(HtmlStyle.header, heading); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
118 |
addPackageTreeLinks(div); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
119 |
Content mainContent = new ContentBuilder(); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
120 |
mainContent.add(div); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
121 |
HtmlTree divTree = new HtmlTree(HtmlTag.DIV); |
47846 | 122 |
divTree.setStyle(HtmlStyle.contentContainer); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
123 |
addTree(classtree.baseClasses(), "doclet.Class_Hierarchy", divTree); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
124 |
addTree(classtree.baseInterfaces(), "doclet.Interface_Hierarchy", divTree); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
125 |
addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
126 |
addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree, true); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
127 |
mainContent.add(divTree); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
128 |
HtmlTree footerTree = HtmlTree.FOOTER(); |
49551
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48654
diff
changeset
|
129 |
navBar.setUserFooter(getUserHeaderFooter(false)); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
130 |
footerTree.add(navBar.getContent(false)); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
131 |
addBottom(footerTree); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
132 |
body.add(bodyContents |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
133 |
.addMainContent(mainContent) |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
134 |
.setFooter(footerTree) |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
135 |
.toContent()); |
53880
3f1e9372557f
8219497: Unused parameter in HtmlDocletWriter::printHtmlDocument
jjg
parents:
53879
diff
changeset
|
136 |
printHtmlDocument(null, "class tree", body); |
10 | 137 |
} |
138 |
||
139 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
140 |
* Add the links to all the package tree files. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
141 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
142 |
* @param contentTree the content tree to which the links will be added |
10 | 143 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
144 |
protected void addPackageTreeLinks(Content contentTree) { |
10 | 145 |
//Do nothing if only unnamed package is used |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
146 |
if (isUnnamedPackage()) { |
10 | 147 |
return; |
148 |
} |
|
40587 | 149 |
if (!classesOnly) { |
21478
fa4c7cda1b41
8026567: Use meaningful style names for strong and italic styles.
bpatel
parents:
19667
diff
changeset
|
150 |
Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel, |
40303 | 151 |
contents.packageHierarchies); |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
152 |
contentTree.add(span); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
153 |
HtmlTree ul = new HtmlTree(HtmlTag.UL); |
47846 | 154 |
ul.setStyle(HtmlStyle.horizontal); |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
155 |
int i = 0; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
156 |
for (PackageElement pkg : packages) { |
9606
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
157 |
// If the package name length is 0 or if -nodeprecated option |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
158 |
// is set and the package is marked as deprecated, do not include |
e5a619cb5dd3
6492694: @deprecated tag doesn't work in package-info files.
bpatel
parents:
7681
diff
changeset
|
159 |
// the page in the list of package hierarchies. |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
160 |
if (pkg.isUnnamed() || |
25454
376a52c9540c
8039028: [javadoc] refactor the usage of Util.java
ksrini
parents:
24221
diff
changeset
|
161 |
(configuration.nodeprecated && utils.isDeprecated(pkg))) { |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
162 |
i++; |
10 | 163 |
continue; |
164 |
} |
|
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
165 |
DocPath link = pathString(pkg, DocPaths.PACKAGE_TREE); |
48654
36f58bd6269f
8195796: Reduce the size of relative URLs in generated docs
jjg
parents:
47850
diff
changeset
|
166 |
Content li = HtmlTree.LI(links.createLink(link, |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
167 |
new StringContent(utils.getPackageName(pkg)))); |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
168 |
if (i < packages.size() - 1) { |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
169 |
li.add(", "); |
10 | 170 |
} |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
171 |
ul.add(li); |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
172 |
i++; |
10 | 173 |
} |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
174 |
contentTree.add(ul); |
10 | 175 |
} |
176 |
} |
|
177 |
||
178 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
179 |
* Get the tree header. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
180 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
181 |
* @return a content tree for the tree header |
10 | 182 |
*/ |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
183 |
protected HtmlTree getTreeHeader() { |
52644
43efb4ca6d6c
8214139: Remove wrapper methods from {Base,Html}Configuration
jjg
parents:
49551
diff
changeset
|
184 |
String title = resources.getText("doclet.Window_Class_Hierarchy"); |
54350
4f9772f4403d
8215599: Remove support for javadoc "frames" mode
pmuthuswamy
parents:
54060
diff
changeset
|
185 |
HtmlTree bodyTree = getBody(getWindowTitle(title)); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
186 |
Content headerContent = new ContentBuilder(); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
187 |
addTop(headerContent); |
49551
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48654
diff
changeset
|
188 |
navBar.setUserHeader(getUserHeaderFooter(true)); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
189 |
headerContent.add(navBar.getContent(true)); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
190 |
bodyContents.setHeader(headerContent); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
191 |
return bodyTree; |
10 | 192 |
} |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
193 |
|
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
194 |
private boolean isUnnamedPackage() { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
195 |
return packages.size() == 1 && packages.first().isUnnamed(); |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
196 |
} |
10 | 197 |
} |