40229
|
1 |
/*
|
45417
|
2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
|
40229
|
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.HtmlConstants;
|
|
36 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
|
|
37 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
|
|
38 |
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
|
|
39 |
import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
|
|
40 |
import jdk.javadoc.internal.doclets.toolkit.Content;
|
40587
|
41 |
import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException;
|
40229
|
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 |
*/
|
40303
|
61 |
private final ModuleElement mdle;
|
40229
|
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 |
*/
|
45417
|
77 |
public ModuleFrameWriter(HtmlConfiguration configuration, ModuleElement moduleElement) {
|
40229
|
78 |
super(configuration, DocPaths.moduleTypeFrame(moduleElement));
|
|
79 |
this.mdle = moduleElement;
|
42277
|
80 |
if (configuration.getSpecifiedPackageElements().isEmpty()) {
|
40229
|
81 |
documentedClasses = new TreeSet<>(utils.makeGeneralPurposeComparator());
|
42277
|
82 |
documentedClasses.addAll(configuration.getIncludedTypeElements());
|
40229
|
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.
|
40587
|
91 |
* @throws DocFileIOException if there is a problem generating the module summary file
|
40229
|
92 |
*/
|
45417
|
93 |
public static void generate(HtmlConfiguration configuration, ModuleElement moduleElement)
|
40587
|
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 = (configuration.allowTag(HtmlTag.MAIN))
|
|
100 |
? HtmlTree.MAIN()
|
|
101 |
: body;
|
|
102 |
Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
|
|
103 |
mdlgen.getHyperLink(DocPaths.moduleSummary(moduleElement), mdlLabel, "", "classFrame"));
|
|
104 |
htmlTree.addContent(heading);
|
|
105 |
HtmlTree div = new HtmlTree(HtmlTag.DIV);
|
47846
|
106 |
div.setStyle(HtmlStyle.indexContainer);
|
40587
|
107 |
mdlgen.addClassListing(div);
|
|
108 |
htmlTree.addContent(div);
|
|
109 |
if (configuration.allowTag(HtmlTag.MAIN)) {
|
|
110 |
body.addContent(htmlTree);
|
40229
|
111 |
}
|
40587
|
112 |
mdlgen.printHtmlDocument(
|
|
113 |
configuration.metakeywords.getMetaKeywordsForModule(moduleElement), false, body);
|
40229
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
* Add class listing for all the classes in this module. Divide class
|
|
118 |
* listing as per the class kind and generate separate listing for
|
|
119 |
* Classes, Interfaces, Exceptions and Errors.
|
|
120 |
*
|
|
121 |
* @param contentTree the content tree to which the listing will be added
|
|
122 |
*/
|
|
123 |
protected void addClassListing(HtmlTree contentTree) {
|
|
124 |
List<PackageElement> packagesIn = ElementFilter.packagesIn(mdle.getEnclosedElements());
|
|
125 |
SortedSet<TypeElement> interfaces = new TreeSet<>(utils.makeGeneralPurposeComparator());
|
|
126 |
SortedSet<TypeElement> classes = new TreeSet<>(utils.makeGeneralPurposeComparator());
|
|
127 |
SortedSet<TypeElement> enums = new TreeSet<>(utils.makeGeneralPurposeComparator());
|
|
128 |
SortedSet<TypeElement> exceptions = new TreeSet<>(utils.makeGeneralPurposeComparator());
|
|
129 |
SortedSet<TypeElement> errors = new TreeSet<>(utils.makeGeneralPurposeComparator());
|
|
130 |
SortedSet<TypeElement> annotationTypes = new TreeSet<>(utils.makeGeneralPurposeComparator());
|
|
131 |
for (PackageElement pkg : packagesIn) {
|
|
132 |
if (utils.isIncluded(pkg)) {
|
|
133 |
interfaces.addAll(utils.getInterfaces(pkg));
|
|
134 |
classes.addAll(utils.getOrdinaryClasses(pkg));
|
|
135 |
enums.addAll(utils.getEnums(pkg));
|
|
136 |
exceptions.addAll(utils.getExceptions(pkg));
|
|
137 |
errors.addAll(utils.getErrors(pkg));
|
|
138 |
annotationTypes.addAll(utils.getAnnotationTypes(pkg));
|
|
139 |
}
|
|
140 |
}
|
40303
|
141 |
addClassKindListing(interfaces, contents.interfaces, contentTree);
|
|
142 |
addClassKindListing(classes, contents.classes, contentTree);
|
|
143 |
addClassKindListing(enums, contents.enums, contentTree);
|
|
144 |
addClassKindListing(exceptions, contents.exceptions, contentTree);
|
|
145 |
addClassKindListing(errors, contents.errors, contentTree);
|
|
146 |
addClassKindListing(annotationTypes, contents.annotationTypes, contentTree);
|
40229
|
147 |
}
|
|
148 |
|
|
149 |
/**
|
|
150 |
* Add specific class kind listing. Also add label to the listing.
|
|
151 |
*
|
|
152 |
* @param list Iterable list of TypeElements
|
|
153 |
* @param labelContent content tree of the label to be added
|
|
154 |
* @param contentTree the content tree to which the class kind listing will be added
|
|
155 |
*/
|
|
156 |
protected void addClassKindListing(Iterable<TypeElement> list, Content labelContent,
|
|
157 |
HtmlTree contentTree) {
|
|
158 |
SortedSet<TypeElement> tset = utils.filterOutPrivateClasses(list, configuration.javafx);
|
|
159 |
if (!tset.isEmpty()) {
|
|
160 |
boolean printedHeader = false;
|
|
161 |
HtmlTree htmlTree = (configuration.allowTag(HtmlTag.SECTION))
|
|
162 |
? HtmlTree.SECTION()
|
|
163 |
: contentTree;
|
|
164 |
HtmlTree ul = new HtmlTree(HtmlTag.UL);
|
|
165 |
ul.setTitle(labelContent);
|
|
166 |
for (TypeElement typeElement : tset) {
|
|
167 |
if (documentedClasses != null && !documentedClasses.contains(typeElement)) {
|
|
168 |
continue;
|
|
169 |
}
|
|
170 |
if (!utils.isCoreClass(typeElement) || !configuration.isGeneratedDoc(typeElement)) {
|
|
171 |
continue;
|
|
172 |
}
|
|
173 |
if (!printedHeader) {
|
|
174 |
Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
|
|
175 |
true, labelContent);
|
|
176 |
htmlTree.addContent(heading);
|
|
177 |
printedHeader = true;
|
|
178 |
}
|
|
179 |
Content arr_i_name = new StringContent(utils.getSimpleName(typeElement));
|
|
180 |
if (utils.isInterface(typeElement)) {
|
|
181 |
arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name);
|
|
182 |
}
|
|
183 |
Content link = getLink(new LinkInfoImpl(configuration,
|
|
184 |
LinkInfoImpl.Kind.ALL_CLASSES_FRAME, typeElement).label(arr_i_name).target("classFrame"));
|
|
185 |
Content li = HtmlTree.LI(link);
|
|
186 |
ul.addContent(li);
|
|
187 |
}
|
|
188 |
htmlTree.addContent(ul);
|
|
189 |
if (configuration.allowTag(HtmlTag.SECTION)) {
|
|
190 |
contentTree.addContent(htmlTree);
|
|
191 |
}
|
|
192 |
}
|
|
193 |
}
|
|
194 |
}
|