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@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.*; |
bpatel@233 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * Generate Class Hierarchy page for all the Classes in this run. Use |
duke@1 | 37 | * ClassTree for building the Tree. The name of |
duke@1 | 38 | * the generated file is "overview-tree.html" and it is generated in the |
duke@1 | 39 | * current or the destination directory. |
duke@1 | 40 | * |
duke@1 | 41 | * @author Atul M Dambalkar |
bpatel@766 | 42 | * @author Bhavesh Patel (Modified) |
duke@1 | 43 | */ |
duke@1 | 44 | public class TreeWriter extends AbstractTreeWriter { |
duke@1 | 45 | |
duke@1 | 46 | /** |
duke@1 | 47 | * Packages in this run. |
duke@1 | 48 | */ |
duke@1 | 49 | private PackageDoc[] packages; |
duke@1 | 50 | |
duke@1 | 51 | /** |
duke@1 | 52 | * True if there are no packages specified on the command line, |
duke@1 | 53 | * False otherwise. |
duke@1 | 54 | */ |
duke@1 | 55 | private boolean classesonly; |
duke@1 | 56 | |
duke@1 | 57 | /** |
duke@1 | 58 | * Constructor to construct TreeWriter object. |
duke@1 | 59 | * |
duke@1 | 60 | * @param configuration the current configuration of the doclet. |
duke@1 | 61 | * @param filename String filename |
duke@1 | 62 | * @param classtree the tree being built. |
duke@1 | 63 | */ |
duke@1 | 64 | public TreeWriter(ConfigurationImpl configuration, |
duke@1 | 65 | String filename, ClassTree classtree) |
duke@1 | 66 | throws IOException { |
duke@1 | 67 | super(configuration, filename, classtree); |
duke@1 | 68 | packages = configuration.packages; |
duke@1 | 69 | classesonly = packages.length == 0; |
duke@1 | 70 | } |
duke@1 | 71 | |
duke@1 | 72 | /** |
duke@1 | 73 | * Create a TreeWriter object and use it to generate the |
duke@1 | 74 | * "overview-tree.html" file. |
duke@1 | 75 | * |
duke@1 | 76 | * @param classtree the class tree being documented. |
duke@1 | 77 | * @throws DocletAbortException |
duke@1 | 78 | */ |
duke@1 | 79 | public static void generate(ConfigurationImpl configuration, |
duke@1 | 80 | ClassTree classtree) { |
duke@1 | 81 | TreeWriter treegen; |
duke@1 | 82 | String filename = "overview-tree.html"; |
duke@1 | 83 | try { |
duke@1 | 84 | treegen = new TreeWriter(configuration, filename, classtree); |
duke@1 | 85 | treegen.generateTreeFile(); |
duke@1 | 86 | treegen.close(); |
duke@1 | 87 | } catch (IOException exc) { |
duke@1 | 88 | configuration.standardmessage.error( |
duke@1 | 89 | "doclet.exception_encountered", |
duke@1 | 90 | exc.toString(), filename); |
duke@1 | 91 | throw new DocletAbortException(); |
duke@1 | 92 | } |
duke@1 | 93 | } |
duke@1 | 94 | |
duke@1 | 95 | /** |
bpatel@766 | 96 | * Generate the interface hierarchy and class hierarchy. |
duke@1 | 97 | */ |
duke@1 | 98 | public void generateTreeFile() throws IOException { |
bpatel@766 | 99 | Content body = getTreeHeader(); |
bpatel@766 | 100 | Content headContent = getResource("doclet.Hierarchy_For_All_Packages"); |
bpatel@766 | 101 | Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, false, |
bpatel@766 | 102 | HtmlStyle.title, headContent); |
bpatel@766 | 103 | Content div = HtmlTree.DIV(HtmlStyle.header, heading); |
bpatel@766 | 104 | addPackageTreeLinks(div); |
bpatel@766 | 105 | body.addContent(div); |
bpatel@766 | 106 | HtmlTree divTree = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 107 | divTree.addStyle(HtmlStyle.contentContainer); |
bpatel@766 | 108 | addTree(classtree.baseclasses(), "doclet.Class_Hierarchy", divTree); |
bpatel@766 | 109 | addTree(classtree.baseinterfaces(), "doclet.Interface_Hierarchy", divTree); |
bpatel@766 | 110 | addTree(classtree.baseAnnotationTypes(), "doclet.Annotation_Type_Hierarchy", divTree); |
bpatel@766 | 111 | addTree(classtree.baseEnums(), "doclet.Enum_Hierarchy", divTree); |
bpatel@766 | 112 | body.addContent(divTree); |
bpatel@766 | 113 | addNavLinks(false, body); |
bpatel@766 | 114 | addBottom(body); |
bpatel@766 | 115 | printHtmlDocument(null, true, body); |
duke@1 | 116 | } |
duke@1 | 117 | |
duke@1 | 118 | /** |
bpatel@766 | 119 | * Add the links to all the package tree files. |
bpatel@766 | 120 | * |
bpatel@766 | 121 | * @param contentTree the content tree to which the links will be added |
duke@1 | 122 | */ |
bpatel@766 | 123 | protected void addPackageTreeLinks(Content contentTree) { |
duke@1 | 124 | //Do nothing if only unnamed package is used |
duke@1 | 125 | if (packages.length == 1 && packages[0].name().length() == 0) { |
duke@1 | 126 | return; |
duke@1 | 127 | } |
duke@1 | 128 | if (!classesonly) { |
bpatel@766 | 129 | Content span = HtmlTree.SPAN(HtmlStyle.strong, |
bpatel@766 | 130 | getResource("doclet.Package_Hierarchies")); |
bpatel@766 | 131 | contentTree.addContent(span); |
bpatel@766 | 132 | HtmlTree ul = new HtmlTree(HtmlTag.UL); |
bpatel@766 | 133 | ul.addStyle(HtmlStyle.horizontal); |
duke@1 | 134 | for (int i = 0; i < packages.length; i++) { |
duke@1 | 135 | if (packages[i].name().length() == 0) { |
duke@1 | 136 | continue; |
duke@1 | 137 | } |
bpatel@766 | 138 | String link = pathString(packages[i], "package-tree.html"); |
bpatel@766 | 139 | Content li = HtmlTree.LI(getHyperLink( |
bpatel@766 | 140 | link, "", new StringContent(packages[i].name()))); |
duke@1 | 141 | if (i < packages.length - 1) { |
bpatel@766 | 142 | li.addContent(", "); |
duke@1 | 143 | } |
bpatel@766 | 144 | ul.addContent(li); |
duke@1 | 145 | } |
bpatel@766 | 146 | contentTree.addContent(ul); |
duke@1 | 147 | } |
duke@1 | 148 | } |
duke@1 | 149 | |
duke@1 | 150 | /** |
bpatel@766 | 151 | * Get the tree header. |
bpatel@766 | 152 | * |
bpatel@766 | 153 | * @return a content tree for the tree header |
duke@1 | 154 | */ |
bpatel@766 | 155 | protected Content getTreeHeader() { |
bpatel@766 | 156 | String title = configuration.getText("doclet.Window_Class_Hierarchy"); |
bpatel@766 | 157 | Content bodyTree = getBody(true, getWindowTitle(title)); |
bpatel@766 | 158 | addTop(bodyTree); |
bpatel@766 | 159 | addNavLinks(true, bodyTree); |
bpatel@766 | 160 | return bodyTree; |
duke@1 | 161 | } |
duke@1 | 162 | } |