1 /* 2 * Copyright (c) 2016, 2018, 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.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.Links; 40 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 41 import jdk.javadoc.internal.doclets.toolkit.Content; 42 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; 43 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 44 45 /** 46 * Class to generate file for each module contents in the left-hand bottom 47 * frame. This will list all the Class Kinds in the module. A click on any 48 * class-kind will update the right-hand frame with the clicked class-kind page. 49 * 50 * <p><b>This is NOT part of any supported API. 51 * If you write code that depends on this, you do so at your own risk. 52 * This code and its internal interfaces are subject to change or 53 * deletion without notice.</b> 54 * 55 * @author Bhavesh Patel 56 */ 57 public class ModuleFrameWriter extends HtmlDocletWriter { 58 59 /** 60 * The module being documented. 61 */ 62 private final ModuleElement mdle; 63 64 /** 65 * The classes to be documented. Use this to filter out classes 66 * that will not be documented. 67 */ 68 private SortedSet<TypeElement> documentedClasses; 69 70 /** 71 * Constructor to construct ModuleFrameWriter object and to generate 72 * "module_name-type-frame.html" file. For example for module "java.base" this will generate file 73 * "java.base-type-frame.html" file. 74 * 75 * @param configuration the configuration of the doclet. 76 * @param moduleElement moduleElement under consideration. 77 */ 78 public ModuleFrameWriter(HtmlConfiguration configuration, ModuleElement moduleElement) { 79 super(configuration, configuration.docPaths.moduleTypeFrame(moduleElement)); 80 this.mdle = moduleElement; 81 if (configuration.getSpecifiedPackageElements().isEmpty()) { 82 documentedClasses = new TreeSet<>(utils.makeGeneralPurposeComparator()); 83 documentedClasses.addAll(configuration.getIncludedTypeElements()); 84 } 85 } 86 87 /** 88 * Generate a module type summary page for the left-hand bottom frame. 89 * 90 * @param configuration the current configuration of the doclet. 91 * @param moduleElement The package for which "module_name-type-frame.html" is to be generated. 92 * @throws DocFileIOException if there is a problem generating the module summary file 93 */ 94 public static void generate(HtmlConfiguration configuration, ModuleElement moduleElement) 95 throws DocFileIOException { 96 ModuleFrameWriter mdlgen = new ModuleFrameWriter(configuration, moduleElement); 97 String mdlName = moduleElement.getQualifiedName().toString(); 98 Content mdlLabel = new StringContent(mdlName); 99 HtmlTree body = mdlgen.getBody(false, mdlgen.getWindowTitle(mdlName)); 100 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.MAIN)) 101 ? HtmlTree.MAIN() 102 : body; 103 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar, 104 mdlgen.links.createLink(configuration.docPaths.moduleSummary(moduleElement), mdlLabel, "", "classFrame")); 105 htmlTree.addContent(heading); 106 HtmlTree div = new HtmlTree(HtmlTag.DIV); 107 div.setStyle(HtmlStyle.indexContainer); 108 mdlgen.addClassListing(div); 109 htmlTree.addContent(div); 110 if (configuration.allowTag(HtmlTag.MAIN)) { 111 body.addContent(htmlTree); 112 } 113 mdlgen.printHtmlDocument( 114 configuration.metakeywords.getMetaKeywordsForModule(moduleElement), false, 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 = (configuration.allowTag(HtmlTag.SECTION)) 163 ? HtmlTree.SECTION() 164 : contentTree; 165 HtmlTree ul = new HtmlTree(HtmlTag.UL); 166 ul.setTitle(labelContent); 167 for (TypeElement typeElement : tset) { 168 if (documentedClasses != null && !documentedClasses.contains(typeElement)) { 169 continue; 170 } 171 if (!utils.isCoreClass(typeElement) || !configuration.isGeneratedDoc(typeElement)) { 172 continue; 173 } 174 if (!printedHeader) { 175 Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, 176 true, labelContent); 177 htmlTree.addContent(heading); 178 printedHeader = true; 179 } 180 Content arr_i_name = new StringContent(utils.getSimpleName(typeElement)); 181 if (utils.isInterface(typeElement)) { 182 arr_i_name = HtmlTree.SPAN(HtmlStyle.interfaceName, arr_i_name); 183 } 184 Content link = getLink(new LinkInfoImpl(configuration, 185 LinkInfoImpl.Kind.ALL_CLASSES_FRAME, typeElement).label(arr_i_name).target("classFrame")); 186 Content li = HtmlTree.LI(link); 187 ul.addContent(li); 188 } 189 htmlTree.addContent(ul); 190 if (configuration.allowTag(HtmlTag.SECTION)) { 191 contentTree.addContent(htmlTree); 192 } 193 } 194 } 195 }