1 /* |
|
2 * Copyright (c) 2016, 2019, 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. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
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 * |
|
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. |
|
24 */ |
|
25 |
|
26 package jdk.javadoc.internal.doclets.formats.html; |
|
27 |
|
28 import java.util.*; |
|
29 |
|
30 import javax.lang.model.element.ModuleElement; |
|
31 import javax.lang.model.element.PackageElement; |
|
32 import javax.lang.model.element.TypeElement; |
|
33 import javax.lang.model.util.ElementFilter; |
|
34 |
|
35 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; |
|
36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; |
|
37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; |
|
38 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; |
|
39 import jdk.javadoc.internal.doclets.toolkit.Content; |
|
40 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
|
41 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
|
42 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
|
43 |
|
44 /** |
|
45 * Class to generate file for each module contents in the left-hand bottom |
|
46 * frame. This will list all the Class Kinds in the module. A click on any |
|
47 * class-kind will update the right-hand frame with the clicked class-kind page. |
|
48 * |
|
49 * <p><b>This is NOT part of any supported API. |
|
50 * If you write code that depends on this, you do so at your own risk. |
|
51 * This code and its internal interfaces are subject to change or |
|
52 * deletion without notice.</b> |
|
53 * |
|
54 * @author Bhavesh Patel |
|
55 */ |
|
56 public class ModuleFrameWriter extends HtmlDocletWriter { |
|
57 |
|
58 /** |
|
59 * The module being documented. |
|
60 */ |
|
61 private final ModuleElement mdle; |
|
62 |
|
63 /** |
|
64 * The classes to be documented. Use this to filter out classes |
|
65 * that will not be documented. |
|
66 */ |
|
67 private SortedSet<TypeElement> documentedClasses; |
|
68 |
|
69 /** |
|
70 * Constructor to construct ModuleFrameWriter object and to generate |
|
71 * "module_name-type-frame.html" file. For example for module "java.base" this will generate file |
|
72 * "java.base-type-frame.html" file. |
|
73 * |
|
74 * @param configuration the configuration of the doclet. |
|
75 * @param moduleElement moduleElement under consideration. |
|
76 */ |
|
77 public ModuleFrameWriter(HtmlConfiguration configuration, ModuleElement moduleElement) { |
|
78 super(configuration, configuration.docPaths.moduleTypeFrame(moduleElement)); |
|
79 this.mdle = moduleElement; |
|
80 if (configuration.getSpecifiedPackageElements().isEmpty()) { |
|
81 documentedClasses = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
|
82 documentedClasses.addAll(configuration.getIncludedTypeElements()); |
|
83 } |
|
84 } |
|
85 |
|
86 /** |
|
87 * Generate a module type summary page for the left-hand bottom frame. |
|
88 * |
|
89 * @param configuration the current configuration of the doclet. |
|
90 * @param moduleElement The package for which "module_name-type-frame.html" is to be generated. |
|
91 * @throws DocFileIOException if there is a problem generating the module summary file |
|
92 */ |
|
93 public static void generate(HtmlConfiguration configuration, ModuleElement moduleElement) |
|
94 throws DocFileIOException { |
|
95 ModuleFrameWriter mdlgen = new ModuleFrameWriter(configuration, moduleElement); |
|
96 String mdlName = moduleElement.getQualifiedName().toString(); |
|
97 Content mdlLabel = new StringContent(mdlName); |
|
98 HtmlTree body = mdlgen.getBody(false, mdlgen.getWindowTitle(mdlName)); |
|
99 HtmlTree htmlTree = HtmlTree.MAIN(); |
|
100 DocPath moduleSummary = configuration.useModuleDirectories |
|
101 ? DocPaths.DOT_DOT.resolve(configuration.docPaths.moduleSummary(moduleElement)) |
|
102 : configuration.docPaths.moduleSummary(moduleElement); |
|
103 Content heading = HtmlTree.HEADING(Headings.PAGE_TITLE_HEADING, HtmlStyle.bar, |
|
104 mdlgen.links.createLink(moduleSummary, mdlLabel, "", "classFrame")); |
|
105 htmlTree.add(heading); |
|
106 HtmlTree div = new HtmlTree(HtmlTag.DIV); |
|
107 div.setStyle(HtmlStyle.indexContainer); |
|
108 mdlgen.addClassListing(div); |
|
109 htmlTree.add(div); |
|
110 body.add(htmlTree); |
|
111 mdlgen.printHtmlDocument( |
|
112 configuration.metakeywords.getMetaKeywordsForModule(moduleElement), |
|
113 "module summary (frame)", |
|
114 body); |
|
115 } |
|
116 |
|
117 /** |
|
118 * Add class listing for all the classes in this module. Divide class |
|
119 * listing as per the class kind and generate separate listing for |
|
120 * Classes, Interfaces, Exceptions and Errors. |
|
121 * |
|
122 * @param contentTree the content tree to which the listing will be added |
|
123 */ |
|
124 protected void addClassListing(HtmlTree contentTree) { |
|
125 List<PackageElement> packagesIn = ElementFilter.packagesIn(mdle.getEnclosedElements()); |
|
126 SortedSet<TypeElement> interfaces = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
|
127 SortedSet<TypeElement> classes = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
|
128 SortedSet<TypeElement> enums = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
|
129 SortedSet<TypeElement> exceptions = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
|
130 SortedSet<TypeElement> errors = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
|
131 SortedSet<TypeElement> annotationTypes = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
|
132 for (PackageElement pkg : packagesIn) { |
|
133 if (utils.isIncluded(pkg)) { |
|
134 interfaces.addAll(utils.getInterfaces(pkg)); |
|
135 classes.addAll(utils.getOrdinaryClasses(pkg)); |
|
136 enums.addAll(utils.getEnums(pkg)); |
|
137 exceptions.addAll(utils.getExceptions(pkg)); |
|
138 errors.addAll(utils.getErrors(pkg)); |
|
139 annotationTypes.addAll(utils.getAnnotationTypes(pkg)); |
|
140 } |
|
141 } |
|
142 addClassKindListing(interfaces, contents.interfaces, contentTree); |
|
143 addClassKindListing(classes, contents.classes, contentTree); |
|
144 addClassKindListing(enums, contents.enums, contentTree); |
|
145 addClassKindListing(exceptions, contents.exceptions, contentTree); |
|
146 addClassKindListing(errors, contents.errors, contentTree); |
|
147 addClassKindListing(annotationTypes, contents.annotationTypes, contentTree); |
|
148 } |
|
149 |
|
150 /** |
|
151 * Add specific class kind listing. Also add label to the listing. |
|
152 * |
|
153 * @param list Iterable list of TypeElements |
|
154 * @param labelContent content tree of the label to be added |
|
155 * @param contentTree the content tree to which the class kind listing will be added |
|
156 */ |
|
157 protected void addClassKindListing(Iterable<TypeElement> list, Content labelContent, |
|
158 HtmlTree contentTree) { |
|
159 SortedSet<TypeElement> tset = utils.filterOutPrivateClasses(list, configuration.javafx); |
|
160 if (!tset.isEmpty()) { |
|
161 boolean printedHeader = false; |
|
162 HtmlTree htmlTree = HtmlTree.SECTION(); |
|
163 HtmlTree ul = new HtmlTree(HtmlTag.UL); |
|
164 ul.setTitle(labelContent); |
|
165 for (TypeElement typeElement : tset) { |
|
166 if (documentedClasses != null && !documentedClasses.contains(typeElement)) { |
|
167 continue; |
|
168 } |
|
169 if (!utils.isCoreClass(typeElement) || !configuration.isGeneratedDoc(typeElement)) { |
|
170 continue; |
|
171 } |
|
172 if (!printedHeader) { |
|
173 Content heading = HtmlTree.HEADING(Headings.CONTENT_HEADING, |
|
174 true, labelContent); |
|
175 htmlTree.add(heading); |
|
176 printedHeader = true; |
|
177 } |
|
178 Content arr_i_name = new StringContent(utils.getSimpleName(typeElement)); |
|
179 if (utils.isInterface(typeElement)) { |
|
180 arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name); |
|
181 } |
|
182 Content link = getLink(new LinkInfoImpl(configuration, |
|
183 LinkInfoImpl.Kind.ALL_CLASSES_FRAME, typeElement).label(arr_i_name).target("classFrame")); |
|
184 Content li = HtmlTree.LI(link); |
|
185 ul.add(li); |
|
186 } |
|
187 htmlTree.add(ul); |
|
188 contentTree.add(htmlTree); |
|
189 } |
|
190 } |
|
191 } |
|