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