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