Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 1997, 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@766 | 28 | import java.io.*; |
bpatel@766 | 29 | import java.util.*; |
bpatel@766 | 30 | import com.sun.javadoc.*; |
duke@1 | 31 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 32 | import com.sun.tools.doclets.internal.toolkit.util.*; |
bpatel@766 | 33 | import com.sun.tools.doclets.formats.html.markup.*; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * Class to generate file for each package contents in the right-hand |
duke@1 | 37 | * frame. This will list all the Class Kinds in the package. A click on any |
duke@1 | 38 | * class-kind will update the frame with the clicked class-kind page. |
duke@1 | 39 | * |
duke@1 | 40 | * @author Atul M Dambalkar |
bpatel@243 | 41 | * @author Bhavesh Patel (Modified) |
duke@1 | 42 | */ |
duke@1 | 43 | public class PackageWriterImpl extends HtmlDocletWriter |
duke@1 | 44 | implements PackageSummaryWriter { |
duke@1 | 45 | |
duke@1 | 46 | /** |
duke@1 | 47 | * The prev package name in the alpha-order list. |
duke@1 | 48 | */ |
duke@1 | 49 | protected PackageDoc prev; |
duke@1 | 50 | |
duke@1 | 51 | /** |
duke@1 | 52 | * The next package name in the alpha-order list. |
duke@1 | 53 | */ |
duke@1 | 54 | protected PackageDoc next; |
duke@1 | 55 | |
duke@1 | 56 | /** |
duke@1 | 57 | * The package being documented. |
duke@1 | 58 | */ |
duke@1 | 59 | protected PackageDoc packageDoc; |
duke@1 | 60 | |
duke@1 | 61 | /** |
duke@1 | 62 | * The name of the output file. |
duke@1 | 63 | */ |
duke@1 | 64 | private static final String OUTPUT_FILE_NAME = "package-summary.html"; |
duke@1 | 65 | |
duke@1 | 66 | /** |
duke@1 | 67 | * Constructor to construct PackageWriter object and to generate |
duke@1 | 68 | * "package-summary.html" file in the respective package directory. |
duke@1 | 69 | * For example for package "java.lang" this will generate file |
duke@1 | 70 | * "package-summary.html" file in the "java/lang" directory. It will also |
duke@1 | 71 | * create "java/lang" directory in the current or the destination directory |
duke@1 | 72 | * if it doesen't exist. |
duke@1 | 73 | * |
duke@1 | 74 | * @param configuration the configuration of the doclet. |
duke@1 | 75 | * @param packageDoc PackageDoc under consideration. |
duke@1 | 76 | * @param prev Previous package in the sorted array. |
duke@1 | 77 | * @param next Next package in the sorted array. |
duke@1 | 78 | */ |
duke@1 | 79 | public PackageWriterImpl(ConfigurationImpl configuration, |
duke@1 | 80 | PackageDoc packageDoc, PackageDoc prev, PackageDoc next) |
duke@1 | 81 | throws IOException { |
duke@1 | 82 | super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME, |
duke@1 | 83 | DirectoryManager.getRelativePath(packageDoc.name())); |
duke@1 | 84 | this.prev = prev; |
duke@1 | 85 | this.next = next; |
duke@1 | 86 | this.packageDoc = packageDoc; |
duke@1 | 87 | } |
duke@1 | 88 | |
duke@1 | 89 | /** |
duke@1 | 90 | * Return the name of the output file. |
duke@1 | 91 | * |
duke@1 | 92 | * @return the name of the output file. |
duke@1 | 93 | */ |
duke@1 | 94 | public String getOutputFileName() { |
duke@1 | 95 | return OUTPUT_FILE_NAME; |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | /** |
duke@1 | 99 | * {@inheritDoc} |
duke@1 | 100 | */ |
bpatel@766 | 101 | public Content getPackageHeader(String heading) { |
bpatel@766 | 102 | String pkgName = packageDoc.name(); |
bpatel@766 | 103 | Content bodyTree = getBody(true, getWindowTitle(pkgName)); |
bpatel@766 | 104 | addTop(bodyTree); |
bpatel@766 | 105 | addNavLinks(true, bodyTree); |
bpatel@766 | 106 | HtmlTree div = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 107 | div.addStyle(HtmlStyle.header); |
bpatel@766 | 108 | Content annotationContent = new HtmlTree(HtmlTag.P); |
bpatel@766 | 109 | addAnnotationInfo(packageDoc, annotationContent); |
bpatel@766 | 110 | div.addContent(annotationContent); |
bpatel@766 | 111 | Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, |
bpatel@766 | 112 | HtmlStyle.title, packageLabel); |
bpatel@766 | 113 | tHeading.addContent(getSpace()); |
bpatel@766 | 114 | Content packageHead = new RawHtml(heading); |
bpatel@766 | 115 | tHeading.addContent(packageHead); |
bpatel@766 | 116 | div.addContent(tHeading); |
bpatel@766 | 117 | if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) { |
bpatel@766 | 118 | HtmlTree p = new HtmlTree(HtmlTag.P); |
bpatel@766 | 119 | p.addStyle(HtmlStyle.subTitle); |
bpatel@766 | 120 | addSummaryComment(packageDoc, p); |
bpatel@766 | 121 | div.addContent(p); |
bpatel@766 | 122 | Content space = getSpace(); |
bpatel@766 | 123 | Content descLink = getHyperLink("", "package_description", |
bpatel@766 | 124 | descriptionLabel, "", ""); |
bpatel@766 | 125 | Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink); |
bpatel@766 | 126 | div.addContent(descPara); |
duke@1 | 127 | } |
bpatel@766 | 128 | bodyTree.addContent(div); |
bpatel@766 | 129 | return bodyTree; |
duke@1 | 130 | } |
duke@1 | 131 | |
duke@1 | 132 | /** |
duke@1 | 133 | * {@inheritDoc} |
duke@1 | 134 | */ |
bpatel@766 | 135 | public Content getContentHeader() { |
bpatel@766 | 136 | HtmlTree div = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 137 | div.addStyle(HtmlStyle.contentContainer); |
bpatel@766 | 138 | return div; |
bpatel@766 | 139 | } |
bpatel@766 | 140 | |
bpatel@766 | 141 | /** |
bpatel@766 | 142 | * {@inheritDoc} |
bpatel@766 | 143 | */ |
bpatel@766 | 144 | public Content getSummaryHeader() { |
bpatel@766 | 145 | HtmlTree ul = new HtmlTree(HtmlTag.UL); |
bpatel@766 | 146 | ul.addStyle(HtmlStyle.blockList); |
bpatel@766 | 147 | return ul; |
bpatel@766 | 148 | } |
bpatel@766 | 149 | |
bpatel@766 | 150 | /** |
bpatel@766 | 151 | * {@inheritDoc} |
bpatel@766 | 152 | */ |
bpatel@766 | 153 | public void addClassesSummary(ClassDoc[] classes, String label, |
bpatel@766 | 154 | String tableSummary, String[] tableHeader, Content summaryContentTree) { |
bpatel@766 | 155 | if(classes.length > 0) { |
bpatel@766 | 156 | Arrays.sort(classes); |
bpatel@766 | 157 | Content caption = getTableCaption(label); |
bpatel@766 | 158 | Content table = HtmlTree.TABLE(HtmlStyle.packageSummary, 0, 3, 0, |
bpatel@766 | 159 | tableSummary, caption); |
bpatel@766 | 160 | table.addContent(getSummaryTableHeader(tableHeader, "col")); |
bpatel@766 | 161 | Content tbody = new HtmlTree(HtmlTag.TBODY); |
bpatel@766 | 162 | for (int i = 0; i < classes.length; i++) { |
bpatel@766 | 163 | if (!Util.isCoreClass(classes[i]) || |
bpatel@766 | 164 | !configuration.isGeneratedDoc(classes[i])) { |
bpatel@766 | 165 | continue; |
bpatel@766 | 166 | } |
bpatel@766 | 167 | Content classContent = new RawHtml(getLink(new LinkInfoImpl( |
bpatel@766 | 168 | LinkInfoImpl.CONTEXT_PACKAGE, classes[i], false))); |
bpatel@766 | 169 | Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent); |
bpatel@766 | 170 | HtmlTree tr = HtmlTree.TR(tdClass); |
bpatel@766 | 171 | if (i%2 == 0) |
bpatel@766 | 172 | tr.addStyle(HtmlStyle.altColor); |
bpatel@766 | 173 | else |
bpatel@766 | 174 | tr.addStyle(HtmlStyle.rowColor); |
bpatel@766 | 175 | HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD); |
bpatel@766 | 176 | tdClassDescription.addStyle(HtmlStyle.colLast); |
bpatel@766 | 177 | if (Util.isDeprecated(classes[i])) { |
bpatel@766 | 178 | tdClassDescription.addContent(deprecatedLabel); |
bpatel@766 | 179 | if (classes[i].tags("deprecated").length > 0) { |
bpatel@766 | 180 | addSummaryDeprecatedComment(classes[i], |
bpatel@766 | 181 | classes[i].tags("deprecated")[0], tdClassDescription); |
bpatel@766 | 182 | } |
bpatel@766 | 183 | } |
bpatel@766 | 184 | else |
bpatel@766 | 185 | addSummaryComment(classes[i], tdClassDescription); |
bpatel@766 | 186 | tr.addContent(tdClassDescription); |
bpatel@766 | 187 | tbody.addContent(tr); |
bpatel@766 | 188 | } |
bpatel@766 | 189 | table.addContent(tbody); |
bpatel@766 | 190 | Content li = HtmlTree.LI(HtmlStyle.blockList, table); |
bpatel@766 | 191 | summaryContentTree.addContent(li); |
duke@1 | 192 | } |
duke@1 | 193 | } |
duke@1 | 194 | |
duke@1 | 195 | /** |
duke@1 | 196 | * {@inheritDoc} |
duke@1 | 197 | */ |
bpatel@766 | 198 | public void addPackageDescription(Content packageContentTree) { |
bpatel@766 | 199 | if (packageDoc.inlineTags().length > 0) { |
bpatel@766 | 200 | packageContentTree.addContent(getMarkerAnchor("package_description")); |
bpatel@766 | 201 | Content h2Content = new StringContent( |
bpatel@766 | 202 | configuration.getText("doclet.Package_Description", |
bpatel@766 | 203 | packageDoc.name())); |
bpatel@766 | 204 | packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, |
bpatel@766 | 205 | true, h2Content)); |
bpatel@766 | 206 | addInlineComment(packageDoc, packageContentTree); |
duke@1 | 207 | } |
duke@1 | 208 | } |
duke@1 | 209 | |
duke@1 | 210 | /** |
duke@1 | 211 | * {@inheritDoc} |
duke@1 | 212 | */ |
bpatel@766 | 213 | public void addPackageTags(Content packageContentTree) { |
bpatel@766 | 214 | addTagsInfo(packageDoc, packageContentTree); |
duke@1 | 215 | } |
duke@1 | 216 | |
duke@1 | 217 | /** |
bpatel@766 | 218 | * {@inheritDoc} |
duke@1 | 219 | */ |
bpatel@766 | 220 | public void addPackageFooter(Content contentTree) { |
bpatel@766 | 221 | addNavLinks(false, contentTree); |
bpatel@766 | 222 | addBottom(contentTree); |
duke@1 | 223 | } |
duke@1 | 224 | |
duke@1 | 225 | /** |
bpatel@766 | 226 | * {@inheritDoc} |
duke@1 | 227 | */ |
bpatel@766 | 228 | public void printDocument(Content contentTree) { |
bpatel@766 | 229 | printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc), |
bpatel@766 | 230 | true, contentTree); |
bpatel@766 | 231 | } |
bpatel@766 | 232 | |
bpatel@766 | 233 | /** |
bpatel@766 | 234 | * Get "Use" link for this pacakge in the navigation bar. |
bpatel@766 | 235 | * |
bpatel@766 | 236 | * @return a content tree for the class use link |
bpatel@766 | 237 | */ |
bpatel@766 | 238 | protected Content getNavLinkClassUse() { |
bpatel@766 | 239 | Content useLink = getHyperLink("package-use.html", "", |
bpatel@766 | 240 | useLabel, "", ""); |
bpatel@766 | 241 | Content li = HtmlTree.LI(useLink); |
bpatel@766 | 242 | return li; |
bpatel@766 | 243 | } |
bpatel@766 | 244 | |
bpatel@766 | 245 | /** |
bpatel@766 | 246 | * Get "PREV PACKAGE" link in the navigation bar. |
bpatel@766 | 247 | * |
bpatel@766 | 248 | * @return a content tree for the previous link |
bpatel@766 | 249 | */ |
bpatel@766 | 250 | public Content getNavLinkPrevious() { |
bpatel@766 | 251 | Content li; |
duke@1 | 252 | if (prev == null) { |
bpatel@766 | 253 | li = HtmlTree.LI(prevpackageLabel); |
duke@1 | 254 | } else { |
duke@1 | 255 | String path = DirectoryManager.getRelativePath(packageDoc.name(), |
duke@1 | 256 | prev.name()); |
bpatel@766 | 257 | li = HtmlTree.LI(getHyperLink(path + "package-summary.html", "", |
bpatel@766 | 258 | prevpackageLabel, "", "")); |
duke@1 | 259 | } |
bpatel@766 | 260 | return li; |
duke@1 | 261 | } |
duke@1 | 262 | |
duke@1 | 263 | /** |
bpatel@766 | 264 | * Get "NEXT PACKAGE" link in the navigation bar. |
bpatel@766 | 265 | * |
bpatel@766 | 266 | * @return a content tree for the next link |
duke@1 | 267 | */ |
bpatel@766 | 268 | public Content getNavLinkNext() { |
bpatel@766 | 269 | Content li; |
duke@1 | 270 | if (next == null) { |
bpatel@766 | 271 | li = HtmlTree.LI(nextpackageLabel); |
duke@1 | 272 | } else { |
duke@1 | 273 | String path = DirectoryManager.getRelativePath(packageDoc.name(), |
duke@1 | 274 | next.name()); |
bpatel@766 | 275 | li = HtmlTree.LI(getHyperLink(path + "package-summary.html", "", |
bpatel@766 | 276 | nextpackageLabel, "", "")); |
duke@1 | 277 | } |
bpatel@766 | 278 | return li; |
duke@1 | 279 | } |
duke@1 | 280 | |
duke@1 | 281 | /** |
bpatel@766 | 282 | * Get "Tree" link in the navigation bar. This will be link to the package |
duke@1 | 283 | * tree file. |
bpatel@766 | 284 | * |
bpatel@766 | 285 | * @return a content tree for the tree link |
duke@1 | 286 | */ |
bpatel@766 | 287 | protected Content getNavLinkTree() { |
bpatel@766 | 288 | Content useLink = getHyperLink("package-tree.html", "", |
bpatel@766 | 289 | treeLabel, "", ""); |
bpatel@766 | 290 | Content li = HtmlTree.LI(useLink); |
bpatel@766 | 291 | return li; |
duke@1 | 292 | } |
duke@1 | 293 | |
duke@1 | 294 | /** |
duke@1 | 295 | * Highlight "Package" in the navigation bar, as this is the package page. |
bpatel@766 | 296 | * |
bpatel@766 | 297 | * @return a content tree for the package link |
duke@1 | 298 | */ |
bpatel@766 | 299 | protected Content getNavLinkPackage() { |
bpatel@766 | 300 | Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel); |
bpatel@766 | 301 | return li; |
duke@1 | 302 | } |
duke@1 | 303 | } |