Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.doclets.formats.html; |
duke@1 | 27 | |
bpatel@233 | 28 | import java.io.*; |
bpatel@233 | 29 | |
bpatel@233 | 30 | import com.sun.javadoc.*; |
duke@1 | 31 | import com.sun.tools.doclets.internal.toolkit.util.*; |
bpatel@766 | 32 | import com.sun.tools.doclets.formats.html.markup.*; |
bpatel@766 | 33 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * Class to generate Tree page for a package. The name of the file generated is |
duke@1 | 37 | * "package-tree.html" and it is generated in the respective package directory. |
duke@1 | 38 | * |
duke@1 | 39 | * @author Atul M Dambalkar |
bpatel@766 | 40 | * @author Bhavesh Patel (Modified) |
duke@1 | 41 | */ |
duke@1 | 42 | public class PackageTreeWriter extends AbstractTreeWriter { |
duke@1 | 43 | |
duke@1 | 44 | /** |
duke@1 | 45 | * Package for which tree is to be generated. |
duke@1 | 46 | */ |
duke@1 | 47 | protected PackageDoc packagedoc; |
duke@1 | 48 | |
duke@1 | 49 | /** |
duke@1 | 50 | * The previous package name in the alpha-order list. |
duke@1 | 51 | */ |
duke@1 | 52 | protected PackageDoc prev; |
duke@1 | 53 | |
duke@1 | 54 | /** |
duke@1 | 55 | * The next package name in the alpha-order list. |
duke@1 | 56 | */ |
duke@1 | 57 | protected PackageDoc next; |
duke@1 | 58 | |
duke@1 | 59 | /** |
duke@1 | 60 | * Constructor. |
duke@1 | 61 | * @throws IOException |
duke@1 | 62 | * @throws DocletAbortException |
duke@1 | 63 | */ |
duke@1 | 64 | public PackageTreeWriter(ConfigurationImpl configuration, |
duke@1 | 65 | String path, String filename, |
duke@1 | 66 | PackageDoc packagedoc, |
duke@1 | 67 | PackageDoc prev, PackageDoc next) |
duke@1 | 68 | throws IOException { |
duke@1 | 69 | super(configuration, path, filename, |
duke@1 | 70 | new ClassTree( |
duke@1 | 71 | configuration.classDocCatalog.allClasses(packagedoc), |
duke@1 | 72 | configuration), |
duke@1 | 73 | packagedoc); |
duke@1 | 74 | this.packagedoc = packagedoc; |
duke@1 | 75 | this.prev = prev; |
duke@1 | 76 | this.next = next; |
duke@1 | 77 | } |
duke@1 | 78 | |
duke@1 | 79 | /** |
duke@1 | 80 | * Construct a PackageTreeWriter object and then use it to generate the |
duke@1 | 81 | * package tree page. |
duke@1 | 82 | * |
duke@1 | 83 | * @param pkg Package for which tree file is to be generated. |
duke@1 | 84 | * @param prev Previous package in the alpha-ordered list. |
duke@1 | 85 | * @param next Next package in the alpha-ordered list. |
duke@1 | 86 | * @param noDeprecated If true, do not generate any information for |
duke@1 | 87 | * deprecated classe or interfaces. |
duke@1 | 88 | * @throws DocletAbortException |
duke@1 | 89 | */ |
duke@1 | 90 | public static void generate(ConfigurationImpl configuration, |
duke@1 | 91 | PackageDoc pkg, PackageDoc prev, |
duke@1 | 92 | PackageDoc next, boolean noDeprecated) { |
duke@1 | 93 | PackageTreeWriter packgen; |
duke@1 | 94 | String path = DirectoryManager.getDirectoryPath(pkg); |
duke@1 | 95 | String filename = "package-tree.html"; |
duke@1 | 96 | try { |
duke@1 | 97 | packgen = new PackageTreeWriter(configuration, path, filename, pkg, |
duke@1 | 98 | prev, next); |
duke@1 | 99 | packgen.generatePackageTreeFile(); |
duke@1 | 100 | packgen.close(); |
duke@1 | 101 | } catch (IOException exc) { |
duke@1 | 102 | configuration.standardmessage.error( |
duke@1 | 103 | "doclet.exception_encountered", |
duke@1 | 104 | exc.toString(), filename); |
duke@1 | 105 | throw new DocletAbortException(); |
duke@1 | 106 | } |
duke@1 | 107 | } |
duke@1 | 108 | |
duke@1 | 109 | /** |
duke@1 | 110 | * Generate a separate tree file for each package. |
duke@1 | 111 | */ |
duke@1 | 112 | protected void generatePackageTreeFile() throws IOException { |
bpatel@766 | 113 | Content body = getPackageTreeHeader(); |
bpatel@766 | 114 | Content headContent = getResource("doclet.Hierarchy_For_Package", |
bpatel@766 | 115 | Util.getPackageName(packagedoc)); |
bpatel@766 | 116 | Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, |
bpatel@766 | 117 | HtmlStyle.title, headContent); |
bpatel@766 | 118 | Content div = HtmlTree.DIV(HtmlStyle.header, heading); |
duke@1 | 119 | if (configuration.packages.length > 1) { |
bpatel@766 | 120 | addLinkToMainTree(div); |
duke@1 | 121 | } |
bpatel@766 | 122 | body.addContent(div); |
bpatel@766 | 123 | HtmlTree divTree = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 124 | divTree.addStyle(HtmlStyle.contentContainer); |
bpatel@766 | 125 | addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree); |
bpatel@766 | 126 | addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree); |
bpatel@766 | 127 | addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree); |
bpatel@766 | 128 | addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree); |
bpatel@766 | 129 | body.addContent(divTree); |
bpatel@766 | 130 | addNavLinks(false, body); |
bpatel@766 | 131 | addBottom(body); |
bpatel@766 | 132 | printHtmlDocument(null, true, body); |
duke@1 | 133 | } |
duke@1 | 134 | |
duke@1 | 135 | /** |
bpatel@766 | 136 | * Get the package tree header. |
bpatel@766 | 137 | * |
bpatel@766 | 138 | * @return a content tree for the header |
duke@1 | 139 | */ |
bpatel@766 | 140 | protected Content getPackageTreeHeader() { |
bpatel@766 | 141 | String title = packagedoc.name() + " " + |
bpatel@766 | 142 | configuration.getText("doclet.Window_Class_Hierarchy"); |
bpatel@766 | 143 | Content bodyTree = getBody(true, getWindowTitle(title)); |
bpatel@766 | 144 | addTop(bodyTree); |
bpatel@766 | 145 | addNavLinks(true, bodyTree); |
bpatel@766 | 146 | return bodyTree; |
duke@1 | 147 | } |
duke@1 | 148 | |
duke@1 | 149 | /** |
bpatel@766 | 150 | * Add a link to the tree for all the packages. |
bpatel@766 | 151 | * |
bpatel@766 | 152 | * @param div the content tree to which the link will be added |
duke@1 | 153 | */ |
bpatel@766 | 154 | protected void addLinkToMainTree(Content div) { |
bpatel@766 | 155 | Content span = HtmlTree.SPAN(HtmlStyle.strong, |
bpatel@766 | 156 | getResource("doclet.Package_Hierarchies")); |
bpatel@766 | 157 | div.addContent(span); |
bpatel@766 | 158 | HtmlTree ul = new HtmlTree (HtmlTag.UL); |
bpatel@766 | 159 | ul.addStyle(HtmlStyle.horizontal); |
bpatel@766 | 160 | ul.addContent(getNavLinkMainTree(configuration.getText("doclet.All_Packages"))); |
bpatel@766 | 161 | div.addContent(ul); |
duke@1 | 162 | } |
duke@1 | 163 | |
duke@1 | 164 | /** |
bpatel@766 | 165 | * Get link for the previous package tree file. |
bpatel@766 | 166 | * |
bpatel@766 | 167 | * @return a content tree for the link |
duke@1 | 168 | */ |
bpatel@766 | 169 | protected Content getNavLinkPrevious() { |
duke@1 | 170 | if (prev == null) { |
bpatel@766 | 171 | return getNavLinkPrevious(null); |
duke@1 | 172 | } else { |
duke@1 | 173 | String path = DirectoryManager.getRelativePath(packagedoc.name(), |
bpatel@766 | 174 | prev.name()); |
bpatel@766 | 175 | return getNavLinkPrevious(path + "package-tree.html"); |
duke@1 | 176 | } |
duke@1 | 177 | } |
duke@1 | 178 | |
duke@1 | 179 | /** |
bpatel@766 | 180 | * Get link for the next package tree file. |
bpatel@766 | 181 | * |
bpatel@766 | 182 | * @return a content tree for the link |
duke@1 | 183 | */ |
bpatel@766 | 184 | protected Content getNavLinkNext() { |
duke@1 | 185 | if (next == null) { |
bpatel@766 | 186 | return getNavLinkNext(null); |
duke@1 | 187 | } else { |
duke@1 | 188 | String path = DirectoryManager.getRelativePath(packagedoc.name(), |
bpatel@766 | 189 | next.name()); |
bpatel@766 | 190 | return getNavLinkNext(path + "package-tree.html"); |
duke@1 | 191 | } |
duke@1 | 192 | } |
duke@1 | 193 | |
duke@1 | 194 | /** |
bpatel@766 | 195 | * Get link to the package summary page for the package of this tree. |
bpatel@766 | 196 | * |
bpatel@766 | 197 | * @return a content tree for the package link |
duke@1 | 198 | */ |
bpatel@766 | 199 | protected Content getNavLinkPackage() { |
bpatel@766 | 200 | Content linkContent = getHyperLink("package-summary.html", "", |
bpatel@766 | 201 | packageLabel); |
bpatel@766 | 202 | Content li = HtmlTree.LI(linkContent); |
bpatel@766 | 203 | return li; |
duke@1 | 204 | } |
duke@1 | 205 | } |