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.tools.doclets.internal.toolkit.util.*;
31 import com.sun.tools.doclets.internal.toolkit.*;
32 import com.sun.tools.doclets.formats.html.markup.*;
33 import com.sun.javadoc.*;
35 /**
36 * Abstract class to print the class hierarchy page for all the Classes. This
37 * is sub-classed by {@link PackageTreeWriter} and {@link TreeWriter} to
38 * generate the Package Tree and global Tree(for all the classes and packages)
39 * pages.
40 *
41 * @author Atul M Dambalkar
42 */
43 public abstract class AbstractTreeWriter extends HtmlDocletWriter {
45 /**
46 * The class and interface tree built by using {@link ClassTree}
47 */
48 protected final ClassTree classtree;
50 private static final String LI_CIRCLE = "circle";
52 /**
53 * Constructor initilises classtree variable. This constructor will be used
54 * while generating global tree file "overview-tree.html".
55 *
56 * @param filename File to be generated.
57 * @param classtree Tree built by {@link ClassTree}.
58 * @throws IOException
59 * @throws DocletAbortException
60 */
61 protected AbstractTreeWriter(ConfigurationImpl configuration,
62 String filename, ClassTree classtree)
63 throws IOException {
64 super(configuration, filename);
65 this.classtree = classtree;
66 }
68 /**
69 * Create appropriate directory for the package and also initilise the
70 * relative path from this generated file to the current or
71 * the destination directory. This constructor will be used while
72 * generating "package tree" file.
73 *
74 * @param path Directories in this path will be created if they are not
75 * already there.
76 * @param filename Name of the package tree file to be generated.
77 * @param classtree The tree built using {@link ClassTree}.
78 * for the package pkg.
79 * @param pkg PackageDoc for which tree file will be generated.
80 * @throws IOException
81 * @throws DocletAbortException
82 */
83 protected AbstractTreeWriter(ConfigurationImpl configuration,
84 String path, String filename,
85 ClassTree classtree, PackageDoc pkg)
86 throws IOException {
87 super(configuration,
88 path, filename, DirectoryManager.getRelativePath(pkg.name()));
89 this.classtree = classtree;
90 }
92 /**
93 * Add each level of the class tree. For each sub-class or
94 * sub-interface indents the next level information.
95 * Recurses itself to add subclasses info.
96 *
97 * @param parent the superclass or superinterface of the list
98 * @param list list of the sub-classes at this level
99 * @param isEnum true if we are generating a tree for enums
100 * @param contentTree the content tree to which the level information will be added
101 */
102 protected void addLevelInfo(ClassDoc parent, List<ClassDoc> list,
103 boolean isEnum, Content contentTree) {
104 int size = list.size();
105 if (size > 0) {
106 Content ul = new HtmlTree(HtmlTag.UL);
107 for (int i = 0; i < size; i++) {
108 ClassDoc local = list.get(i);
109 HtmlTree li = new HtmlTree(HtmlTag.LI);
110 li.addAttr(HtmlAttr.TYPE, LI_CIRCLE);
111 addPartialInfo(local, li);
112 addExtendsImplements(parent, local, li);
113 addLevelInfo(local, classtree.subs(local, isEnum),
114 isEnum, li); // Recurse
115 ul.addContent(li);
116 }
117 contentTree.addContent(ul);
118 }
119 }
121 /**
122 * Add the heading for the tree depending upon tree type if it's a
123 * Class Tree or Interface tree.
124 *
125 * @param list List of classes which are at the most base level, all the
126 * other classes in this run will derive from these classes
127 * @param heading heading for the tree
128 * @param div the content tree to which the tree will be added
129 */
130 protected void addTree(List<ClassDoc> list, String heading, Content div) {
131 if (list.size() > 0) {
132 ClassDoc firstClassDoc = list.get(0);
133 Content headingContent = getResource(heading);
134 div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
135 headingContent));
136 addLevelInfo(!firstClassDoc.isInterface()? firstClassDoc : null,
137 list, list == classtree.baseEnums(), div);
138 }
139 }
141 /**
142 * Add information regarding the classes which this class extends or
143 * implements.
144 *
145 * @param parent the parent class of the class being documented
146 * @param cd the classdoc under consideration
147 * @param contentTree the content tree to which the information will be added
148 */
149 protected void addExtendsImplements(ClassDoc parent, ClassDoc cd,
150 Content contentTree) {
151 ClassDoc[] interfaces = cd.interfaces();
152 if (interfaces.length > (cd.isInterface()? 1 : 0)) {
153 Arrays.sort(interfaces);
154 int counter = 0;
155 for (int i = 0; i < interfaces.length; i++) {
156 if (parent != interfaces[i]) {
157 if (! (interfaces[i].isPublic() ||
158 Util.isLinkable(interfaces[i], configuration()))) {
159 continue;
160 }
161 if (counter == 0) {
162 if (cd.isInterface()) {
163 contentTree.addContent(" (");
164 contentTree.addContent(getResource("doclet.also"));
165 contentTree.addContent(" extends ");
166 } else {
167 contentTree.addContent(" (implements ");
168 }
169 } else {
170 contentTree.addContent(", ");
171 }
172 addPreQualifiedClassLink(LinkInfoImpl.CONTEXT_TREE,
173 interfaces[i], contentTree);
174 counter++;
175 }
176 }
177 if (counter > 0) {
178 contentTree.addContent(")");
179 }
180 }
181 }
183 /**
184 * Add information about the class kind, if it's a "class" or "interface".
185 *
186 * @param cd the class being documented
187 * @param contentTree the content tree to which the information will be added
188 */
189 protected void addPartialInfo(ClassDoc cd, Content contentTree) {
190 addPreQualifiedStrongClassLink(LinkInfoImpl.CONTEXT_TREE, cd, contentTree);
191 }
193 /**
194 * Get the tree label for the navigation bar.
195 *
196 * @return a content tree for the tree label
197 */
198 protected Content getNavLinkTree() {
199 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, treeLabel);
200 return li;
201 }
202 }