Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
1 /*
2 * Copyright (c) 1998, 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.util.*;
32 import com.sun.tools.doclets.internal.toolkit.*;
33 import com.sun.tools.doclets.formats.html.markup.*;
35 /**
36 * Class to generate file for each package contents in the left-hand bottom
37 * frame. This will list all the Class Kinds in the package. A click on any
38 * class-kind will update the right-hand frame with the clicked class-kind page.
39 *
40 * @author Atul M Dambalkar
41 * @author Bhavesh Patel (Modified)
42 */
43 public class PackageFrameWriter extends HtmlDocletWriter {
45 /**
46 * The package being documented.
47 */
48 private PackageDoc packageDoc;
50 /**
51 * The classes to be documented. Use this to filter out classes
52 * that will not be documented.
53 */
54 private Set<ClassDoc> documentedClasses;
56 /**
57 * The name of the output file.
58 */
59 public static final String OUTPUT_FILE_NAME = "package-frame.html";
61 /**
62 * Constructor to construct PackageFrameWriter object and to generate
63 * "package-frame.html" file in the respective package directory.
64 * For example for package "java.lang" this will generate file
65 * "package-frame.html" file in the "java/lang" directory. It will also
66 * create "java/lang" directory in the current or the destination directory
67 * if it doesen't exist.
68 *
69 * @param configuration the configuration of the doclet.
70 * @param packageDoc PackageDoc under consideration.
71 */
72 public PackageFrameWriter(ConfigurationImpl configuration,
73 PackageDoc packageDoc)
74 throws IOException {
75 super(configuration, DirectoryManager.getDirectoryPath(packageDoc), OUTPUT_FILE_NAME, DirectoryManager.getRelativePath(packageDoc));
76 this.packageDoc = packageDoc;
77 if (configuration.root.specifiedPackages().length == 0) {
78 documentedClasses = new HashSet<ClassDoc>(Arrays.asList(configuration.root.classes()));
79 }
80 }
82 /**
83 * Generate a package summary page for the left-hand bottom frame. Construct
84 * the PackageFrameWriter object and then uses it generate the file.
85 *
86 * @param configuration the current configuration of the doclet.
87 * @param packageDoc The package for which "pacakge-frame.html" is to be generated.
88 */
89 public static void generate(ConfigurationImpl configuration,
90 PackageDoc packageDoc) {
91 PackageFrameWriter packgen;
92 try {
93 packgen = new PackageFrameWriter(configuration, packageDoc);
94 String pkgName = Util.getPackageName(packageDoc);
95 Content body = packgen.getBody(false, packgen.getWindowTitle(pkgName));
96 Content pkgNameContent = new StringContent(pkgName);
97 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, HtmlStyle.bar,
98 packgen.getTargetPackageLink(packageDoc, "classFrame", pkgNameContent));
99 body.addContent(heading);
100 HtmlTree div = new HtmlTree(HtmlTag.DIV);
101 div.addStyle(HtmlStyle.indexContainer);
102 packgen.addClassListing(div);
103 body.addContent(div);
104 packgen.printHtmlDocument(
105 configuration.metakeywords.getMetaKeywords(packageDoc), false, body);
106 packgen.close();
107 } catch (IOException exc) {
108 configuration.standardmessage.error(
109 "doclet.exception_encountered",
110 exc.toString(), OUTPUT_FILE_NAME);
111 throw new DocletAbortException();
112 }
113 }
115 /**
116 * Add class listing for all the classes in this package. Divide class
117 * listing as per the class kind and generate separate listing for
118 * Classes, Interfaces, Exceptions and Errors.
119 *
120 * @param contentTree the content tree to which the listing will be added
121 */
122 protected void addClassListing(Content contentTree) {
123 Configuration config = configuration();
124 if (packageDoc.isIncluded()) {
125 addClassKindListing(packageDoc.interfaces(),
126 getResource("doclet.Interfaces"), contentTree);
127 addClassKindListing(packageDoc.ordinaryClasses(),
128 getResource("doclet.Classes"), contentTree);
129 addClassKindListing(packageDoc.enums(),
130 getResource("doclet.Enums"), contentTree);
131 addClassKindListing(packageDoc.exceptions(),
132 getResource("doclet.Exceptions"), contentTree);
133 addClassKindListing(packageDoc.errors(),
134 getResource("doclet.Errors"), contentTree);
135 addClassKindListing(packageDoc.annotationTypes(),
136 getResource("doclet.AnnotationTypes"), contentTree);
137 } else {
138 String name = Util.getPackageName(packageDoc);
139 addClassKindListing(config.classDocCatalog.interfaces(name),
140 getResource("doclet.Interfaces"), contentTree);
141 addClassKindListing(config.classDocCatalog.ordinaryClasses(name),
142 getResource("doclet.Classes"), contentTree);
143 addClassKindListing(config.classDocCatalog.enums(name),
144 getResource("doclet.Enums"), contentTree);
145 addClassKindListing(config.classDocCatalog.exceptions(name),
146 getResource("doclet.Exceptions"), contentTree);
147 addClassKindListing(config.classDocCatalog.errors(name),
148 getResource("doclet.Errors"), contentTree);
149 addClassKindListing(config.classDocCatalog.annotationTypes(name),
150 getResource("doclet.AnnotationTypes"), contentTree);
151 }
152 }
154 /**
155 * Add specific class kind listing. Also add label to the listing.
156 *
157 * @param arr Array of specific class kinds, namely Class or Interface or Exception or Error
158 * @param labelContent content tree of the label to be added
159 * @param contentTree the content tree to which the class kind listing will be added
160 */
161 protected void addClassKindListing(ClassDoc[] arr, Content labelContent,
162 Content contentTree) {
163 if(arr.length > 0) {
164 Arrays.sort(arr);
165 boolean printedHeader = false;
166 HtmlTree ul = new HtmlTree(HtmlTag.UL);
167 ul.addAttr(HtmlAttr.TITLE, labelContent.toString());
168 for (int i = 0; i < arr.length; i++) {
169 if (documentedClasses != null &&
170 !documentedClasses.contains(arr[i])) {
171 continue;
172 }
173 if (!Util.isCoreClass(arr[i]) || !
174 configuration.isGeneratedDoc(arr[i])) {
175 continue;
176 }
177 if (!printedHeader) {
178 Content heading = HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING,
179 true, labelContent);
180 contentTree.addContent(heading);
181 printedHeader = true;
182 }
183 Content link = new RawHtml (getLink(new LinkInfoImpl(
184 LinkInfoImpl.PACKAGE_FRAME, arr[i],
185 (arr[i].isInterface() ? italicsText(arr[i].name()) :
186 arr[i].name()),"classFrame")));
187 Content li = HtmlTree.LI(link);
188 ul.addContent(li);
189 }
190 contentTree.addContent(ul);
191 }
192 }
193 }