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) 1998, 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 |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
28 |
import javax.lang.model.element.PackageElement; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
29 |
|
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
30 |
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
|
31 |
import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
32 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
33 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
34 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; |
49551
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48759
diff
changeset
|
35 |
import jdk.javadoc.internal.doclets.formats.html.markup.Navigation; |
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48759
diff
changeset
|
36 |
import jdk.javadoc.internal.doclets.formats.html.markup.Navigation.PageMode; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
37 |
import jdk.javadoc.internal.doclets.toolkit.Content; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
38 |
import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; |
40587 | 39 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
40 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
41 |
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
42 |
|
10 | 43 |
|
44 |
/** |
|
45 |
* Class to generate Tree page for a package. The name of the file generated is |
|
46 |
* "package-tree.html" and it is generated in the respective package directory. |
|
47 |
* |
|
14260
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
48 |
* <p><b>This is NOT part of any supported API. |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
49 |
* 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
|
50 |
* 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
|
51 |
* deletion without notice.</b> |
727a84636f12
8000665: fix "internal API" comments on javadoc files
jjg
parents:
14258
diff
changeset
|
52 |
* |
10 | 53 |
* @author Atul M Dambalkar |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
54 |
* @author Bhavesh Patel (Modified) |
10 | 55 |
*/ |
56 |
public class PackageTreeWriter extends AbstractTreeWriter { |
|
57 |
||
58 |
/** |
|
59 |
* Package for which tree is to be generated. |
|
60 |
*/ |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
61 |
protected PackageElement packageElement; |
10 | 62 |
|
49551
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48759
diff
changeset
|
63 |
private final Navigation navBar; |
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48759
diff
changeset
|
64 |
|
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
65 |
private final BodyContents bodyContents = new BodyContents(); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
66 |
|
10 | 67 |
/** |
68 |
* Constructor. |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
69 |
* @param configuration the configuration |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
70 |
* @param path the docpath to generate files into |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
71 |
* @param packageElement the current package |
10 | 72 |
*/ |
48756
ce608a09a666
8196027: Remove "Prev" and "Next" links from the javadoc navigation
bpatel
parents:
48654
diff
changeset
|
73 |
public PackageTreeWriter(HtmlConfiguration configuration, DocPath path, PackageElement packageElement) { |
14357
faf9cde2817b
8000741: refactor javadoc to use abstraction to handle relative paths
jjg
parents:
14260
diff
changeset
|
74 |
super(configuration, path, |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
75 |
new ClassTree(configuration.typeElementCatalog.allClasses(packageElement), configuration)); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
76 |
this.packageElement = packageElement; |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
77 |
this.navBar = new Navigation(packageElement, configuration, PageMode.TREE, path); |
10 | 78 |
} |
79 |
||
80 |
/** |
|
81 |
* Construct a PackageTreeWriter object and then use it to generate the |
|
82 |
* package tree page. |
|
83 |
* |
|
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
84 |
* @param configuration the configuration for this run. |
10 | 85 |
* @param pkg Package for which tree file is to be generated. |
86 |
* @param noDeprecated If true, do not generate any information for |
|
87 |
* deprecated classe or interfaces. |
|
40587 | 88 |
* @throws DocFileIOException if there is a problem generating the package tree page |
10 | 89 |
*/ |
45417 | 90 |
public static void generate(HtmlConfiguration configuration, |
48756
ce608a09a666
8196027: Remove "Prev" and "Next" links from the javadoc navigation
bpatel
parents:
48654
diff
changeset
|
91 |
PackageElement pkg, boolean noDeprecated) |
40587 | 92 |
throws DocFileIOException { |
48759
ffa68af7da87
8195795: Organize output files by module/package, not just package
jjg
parents:
48756
diff
changeset
|
93 |
DocPath path = configuration.docPaths.forPackage(pkg).resolve(DocPaths.PACKAGE_TREE); |
48756
ce608a09a666
8196027: Remove "Prev" and "Next" links from the javadoc navigation
bpatel
parents:
48654
diff
changeset
|
94 |
PackageTreeWriter packgen = new PackageTreeWriter(configuration, path, pkg); |
40587 | 95 |
packgen.generatePackageTreeFile(); |
10 | 96 |
} |
97 |
||
98 |
/** |
|
99 |
* Generate a separate tree file for each package. |
|
40587 | 100 |
* @throws DocFileIOException if there is a problem generating the package tree file |
10 | 101 |
*/ |
40587 | 102 |
protected void generatePackageTreeFile() throws DocFileIOException { |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
103 |
HtmlTree body = getPackageTreeHeader(); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
104 |
Content mainContent = new ContentBuilder(); |
40303 | 105 |
Content headContent = contents.getContent("doclet.Hierarchy_For_Package", |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
106 |
utils.getPackageName(packageElement)); |
53991 | 107 |
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
|
108 |
HtmlStyle.title, headContent); |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
109 |
Content div = HtmlTree.DIV(HtmlStyle.header, heading); |
24221
2376793dd33b
8038583: [javadoc] Refactor uses of arrays to Collections
ksrini
parents:
21478
diff
changeset
|
110 |
if (configuration.packages.size() > 1) { |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
111 |
addLinkToMainTree(div); |
10 | 112 |
} |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
113 |
mainContent.add(div); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
114 |
HtmlTree divTree = new HtmlTree(HtmlTag.DIV); |
47846 | 115 |
divTree.setStyle(HtmlStyle.contentContainer); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
116 |
addTree(classtree.baseClasses(), "doclet.Class_Hierarchy", divTree); |
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
117 |
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
|
118 |
addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree); |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
119 |
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
|
120 |
mainContent.add(divTree); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
121 |
bodyContents.addMainContent(mainContent); |
53562 | 122 |
HtmlTree footer = HtmlTree.FOOTER(); |
49551
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48759
diff
changeset
|
123 |
navBar.setUserFooter(getUserHeaderFooter(false)); |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
124 |
footer.add(navBar.getContent(false)); |
53562 | 125 |
addBottom(footer); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
126 |
bodyContents.setFooter(footer); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
127 |
body.add(bodyContents.toContent()); |
53880
3f1e9372557f
8219497: Unused parameter in HtmlDocletWriter::printHtmlDocument
jjg
parents:
53879
diff
changeset
|
128 |
printHtmlDocument(null, getDescription("tree", packageElement), body); |
10 | 129 |
} |
130 |
||
131 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
132 |
* Get the package tree header. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
133 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
134 |
* @return a content tree for the header |
10 | 135 |
*/ |
29957
7740f9657f56
8072945: Javadoc should generate valid and compliant HTML5 output
bpatel
parents:
25874
diff
changeset
|
136 |
protected HtmlTree getPackageTreeHeader() { |
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
29957
diff
changeset
|
137 |
String packageName = packageElement.isUnnamed() ? "" : utils.getPackageName(packageElement); |
52644
43efb4ca6d6c
8214139: Remove wrapper methods from {Base,Html}Configuration
jjg
parents:
49551
diff
changeset
|
138 |
String title = packageName + " " + resources.getText("doclet.Window_Class_Hierarchy"); |
54350
4f9772f4403d
8215599: Remove support for javadoc "frames" mode
pmuthuswamy
parents:
54060
diff
changeset
|
139 |
HtmlTree bodyTree = getBody(getWindowTitle(title)); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
140 |
Content headerContent = new ContentBuilder(); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
141 |
addTop(headerContent); |
49551
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48759
diff
changeset
|
142 |
Content linkContent = getModuleLink(utils.elementUtils.getModuleOf(packageElement), |
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48759
diff
changeset
|
143 |
contents.moduleLabel); |
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48759
diff
changeset
|
144 |
navBar.setNavLinkModule(linkContent); |
0d4786e42471
8196200: Implement a navigation builder in javadoc
bpatel
parents:
48759
diff
changeset
|
145 |
navBar.setUserHeader(getUserHeaderFooter(true)); |
59294
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
146 |
headerContent.add(navBar.getContent(true)); |
48b88b9c11eb
8223378: CSS solution for navbar problem with <a> elements is not ideal
hannesw
parents:
54350
diff
changeset
|
147 |
bodyContents.setHeader(headerContent); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
148 |
return bodyTree; |
10 | 149 |
} |
150 |
||
151 |
/** |
|
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
152 |
* Add a link to the tree for all the packages. |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
153 |
* |
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
154 |
* @param div the content tree to which the link will be added |
10 | 155 |
*/ |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
156 |
protected void addLinkToMainTree(Content div) { |
21478
fa4c7cda1b41
8026567: Use meaningful style names for strong and italic styles.
bpatel
parents:
19667
diff
changeset
|
157 |
Content span = HtmlTree.SPAN(HtmlStyle.packageHierarchyLabel, |
40303 | 158 |
contents.packageHierarchies); |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
159 |
div.add(span); |
7614
cfadc977ca75
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents:
5520
diff
changeset
|
160 |
HtmlTree ul = new HtmlTree (HtmlTag.UL); |
47846 | 161 |
ul.setStyle(HtmlStyle.horizontal); |
54060
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
162 |
ul.add(getNavLinkMainTree(resources.getText("doclet.All_Packages"))); |
53a95878619f
8220202: Simplify/standardize method naming for HtmlTree
jjg
parents:
53991
diff
changeset
|
163 |
div.add(ul); |
10 | 164 |
} |
165 |
} |