Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 2001, 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@766 | 28 | import java.io.*; |
bpatel@766 | 29 | import java.util.*; |
bpatel@766 | 30 | import com.sun.javadoc.*; |
duke@1 | 31 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 32 | import com.sun.tools.doclets.internal.toolkit.util.*; |
bpatel@766 | 33 | import com.sun.tools.doclets.formats.html.markup.*; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * Write the Constants Summary Page in HTML format. |
duke@1 | 37 | * |
duke@1 | 38 | * @author Jamie Ho |
bpatel@243 | 39 | * @author Bhavesh Patel (Modified) |
duke@1 | 40 | * @since 1.4 |
duke@1 | 41 | */ |
duke@1 | 42 | public class ConstantsSummaryWriterImpl extends HtmlDocletWriter |
duke@1 | 43 | implements ConstantsSummaryWriter { |
duke@1 | 44 | |
duke@1 | 45 | /** |
duke@1 | 46 | * The configuration used in this run of the standard doclet. |
duke@1 | 47 | */ |
duke@1 | 48 | ConfigurationImpl configuration; |
duke@1 | 49 | |
duke@1 | 50 | /** |
duke@1 | 51 | * The current class being documented. |
duke@1 | 52 | */ |
duke@1 | 53 | private ClassDoc currentClassDoc; |
duke@1 | 54 | |
bpatel@243 | 55 | private final String constantsTableSummary; |
bpatel@243 | 56 | |
bpatel@243 | 57 | private final String[] constantsTableHeader; |
bpatel@243 | 58 | |
duke@1 | 59 | /** |
duke@1 | 60 | * Construct a ConstantsSummaryWriter. |
duke@1 | 61 | * @param configuration the configuration used in this run |
duke@1 | 62 | * of the standard doclet. |
duke@1 | 63 | */ |
duke@1 | 64 | public ConstantsSummaryWriterImpl(ConfigurationImpl configuration) |
duke@1 | 65 | throws IOException { |
duke@1 | 66 | super(configuration, ConfigurationImpl.CONSTANTS_FILE_NAME); |
duke@1 | 67 | this.configuration = configuration; |
bpatel@243 | 68 | constantsTableSummary = configuration.getText("doclet.Constants_Table_Summary", |
bpatel@243 | 69 | configuration.getText("doclet.Constants_Summary")); |
bpatel@243 | 70 | constantsTableHeader = new String[] { |
bpatel@243 | 71 | getModifierTypeHeader(), |
bpatel@243 | 72 | configuration.getText("doclet.ConstantField"), |
bpatel@243 | 73 | configuration.getText("doclet.Value") |
bpatel@243 | 74 | }; |
duke@1 | 75 | } |
duke@1 | 76 | |
duke@1 | 77 | /** |
duke@1 | 78 | * {@inheritDoc} |
duke@1 | 79 | */ |
bpatel@766 | 80 | public Content getHeader() { |
bpatel@766 | 81 | String label = configuration.getText("doclet.Constants_Summary"); |
bpatel@766 | 82 | Content bodyTree = getBody(true, getWindowTitle(label)); |
bpatel@766 | 83 | addTop(bodyTree); |
bpatel@766 | 84 | addNavLinks(true, bodyTree); |
bpatel@766 | 85 | return bodyTree; |
duke@1 | 86 | } |
duke@1 | 87 | |
duke@1 | 88 | /** |
duke@1 | 89 | * {@inheritDoc} |
duke@1 | 90 | */ |
bpatel@766 | 91 | public Content getContentsHeader() { |
bpatel@766 | 92 | return new HtmlTree(HtmlTag.UL); |
duke@1 | 93 | } |
duke@1 | 94 | |
duke@1 | 95 | /** |
duke@1 | 96 | * {@inheritDoc} |
duke@1 | 97 | */ |
bpatel@766 | 98 | public void addLinkToPackageContent(PackageDoc pkg, String parsedPackageName, |
bpatel@766 | 99 | Set<String> printedPackageHeaders, Content contentListTree) { |
bpatel@766 | 100 | String packageName = pkg.name(); |
bpatel@766 | 101 | //add link to summary |
bpatel@766 | 102 | Content link; |
bpatel@766 | 103 | if (packageName.length() == 0) { |
bpatel@766 | 104 | link = getHyperLink("#" + DocletConstants.UNNAMED_PACKAGE_ANCHOR, |
bpatel@766 | 105 | "", defaultPackageLabel, "", ""); |
bpatel@766 | 106 | } else { |
bpatel@766 | 107 | Content packageNameContent = getPackageLabel(parsedPackageName); |
bpatel@766 | 108 | packageNameContent.addContent(".*"); |
bpatel@766 | 109 | link = getHyperLink("#" + parsedPackageName, |
bpatel@766 | 110 | "", packageNameContent, "", ""); |
bpatel@766 | 111 | printedPackageHeaders.add(parsedPackageName); |
bpatel@766 | 112 | } |
bpatel@766 | 113 | contentListTree.addContent(HtmlTree.LI(link)); |
duke@1 | 114 | } |
duke@1 | 115 | |
duke@1 | 116 | /** |
duke@1 | 117 | * {@inheritDoc} |
duke@1 | 118 | */ |
bpatel@766 | 119 | public Content getContentsList(Content contentListTree) { |
bpatel@766 | 120 | Content titleContent = getResource( |
bpatel@766 | 121 | "doclet.Constants_Summary"); |
bpatel@766 | 122 | Content pHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, |
bpatel@766 | 123 | HtmlStyle.title, titleContent); |
bpatel@766 | 124 | Content div = HtmlTree.DIV(HtmlStyle.header, pHeading); |
bpatel@766 | 125 | Content headingContent = getResource( |
bpatel@766 | 126 | "doclet.Contents"); |
bpatel@766 | 127 | div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, |
bpatel@766 | 128 | headingContent)); |
bpatel@766 | 129 | div.addContent(contentListTree); |
bpatel@766 | 130 | return div; |
duke@1 | 131 | } |
duke@1 | 132 | |
duke@1 | 133 | /** |
duke@1 | 134 | * {@inheritDoc} |
duke@1 | 135 | */ |
bpatel@766 | 136 | public Content getConstantSummaries() { |
bpatel@766 | 137 | HtmlTree summariesDiv = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 138 | summariesDiv.addStyle(HtmlStyle.constantValuesContainer); |
bpatel@766 | 139 | return summariesDiv; |
duke@1 | 140 | } |
duke@1 | 141 | |
duke@1 | 142 | /** |
duke@1 | 143 | * {@inheritDoc} |
duke@1 | 144 | */ |
bpatel@766 | 145 | public void addPackageName(PackageDoc pkg, String parsedPackageName, |
bpatel@766 | 146 | Content summariesTree) { |
bpatel@766 | 147 | Content pkgNameContent; |
bpatel@766 | 148 | if (parsedPackageName.length() == 0) { |
bpatel@766 | 149 | summariesTree.addContent(getMarkerAnchor( |
bpatel@766 | 150 | DocletConstants.UNNAMED_PACKAGE_ANCHOR)); |
bpatel@766 | 151 | pkgNameContent = defaultPackageLabel; |
bpatel@766 | 152 | } else { |
bpatel@766 | 153 | summariesTree.addContent(getMarkerAnchor( |
bpatel@766 | 154 | parsedPackageName)); |
bpatel@766 | 155 | pkgNameContent = getPackageLabel(parsedPackageName); |
bpatel@766 | 156 | } |
bpatel@766 | 157 | Content headingContent = new StringContent(".*"); |
bpatel@766 | 158 | Content heading = HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING, true, |
bpatel@766 | 159 | pkgNameContent); |
bpatel@766 | 160 | heading.addContent(headingContent); |
bpatel@766 | 161 | summariesTree.addContent(heading); |
bpatel@766 | 162 | } |
bpatel@766 | 163 | |
bpatel@766 | 164 | /** |
bpatel@766 | 165 | * {@inheritDoc} |
bpatel@766 | 166 | */ |
bpatel@766 | 167 | public Content getClassConstantHeader() { |
bpatel@766 | 168 | HtmlTree ul = new HtmlTree(HtmlTag.UL); |
bpatel@766 | 169 | ul.addStyle(HtmlStyle.blockList); |
bpatel@766 | 170 | return ul; |
bpatel@766 | 171 | } |
bpatel@766 | 172 | |
bpatel@766 | 173 | /** |
bpatel@766 | 174 | * Get the table caption and header for the constant summary table |
bpatel@766 | 175 | * |
bpatel@766 | 176 | * @param cd classdoc to be documented |
bpatel@766 | 177 | * @return constant members header content |
bpatel@766 | 178 | */ |
bpatel@766 | 179 | public Content getConstantMembersHeader(ClassDoc cd) { |
duke@1 | 180 | //generate links backward only to public classes. |
duke@1 | 181 | String classlink = (cd.isPublic() || cd.isProtected())? |
duke@1 | 182 | getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, cd, |
duke@1 | 183 | false)) : |
duke@1 | 184 | cd.qualifiedName(); |
duke@1 | 185 | String name = cd.containingPackage().name(); |
duke@1 | 186 | if (name.length() > 0) { |
bpatel@766 | 187 | return getClassName(name + "." + classlink); |
duke@1 | 188 | } else { |
bpatel@766 | 189 | return getClassName(classlink); |
duke@1 | 190 | } |
duke@1 | 191 | } |
duke@1 | 192 | |
duke@1 | 193 | /** |
bpatel@766 | 194 | * Get the class name in the table caption and the table header. |
bpatel@766 | 195 | * |
bpatel@766 | 196 | * @param classStr the class name to print. |
bpatel@766 | 197 | * @return the table caption and header |
bpatel@766 | 198 | */ |
bpatel@766 | 199 | protected Content getClassName(String classStr) { |
bpatel@766 | 200 | Content table = HtmlTree.TABLE(0, 3, 0, constantsTableSummary, |
bpatel@766 | 201 | getTableCaption(classStr)); |
bpatel@766 | 202 | table.addContent(getSummaryTableHeader(constantsTableHeader, "col")); |
bpatel@766 | 203 | return table; |
bpatel@766 | 204 | } |
bpatel@766 | 205 | |
bpatel@766 | 206 | /** |
duke@1 | 207 | * {@inheritDoc} |
duke@1 | 208 | */ |
bpatel@766 | 209 | public void addConstantMembers(ClassDoc cd, List<FieldDoc> fields, |
bpatel@766 | 210 | Content classConstantTree) { |
bpatel@766 | 211 | currentClassDoc = cd; |
bpatel@766 | 212 | Content tbody = new HtmlTree(HtmlTag.TBODY); |
bpatel@766 | 213 | for (int i = 0; i < fields.size(); ++i) { |
bpatel@766 | 214 | HtmlTree tr = new HtmlTree(HtmlTag.TR); |
bpatel@766 | 215 | if (i%2 == 0) |
bpatel@766 | 216 | tr.addStyle(HtmlStyle.altColor); |
bpatel@766 | 217 | else |
bpatel@766 | 218 | tr.addStyle(HtmlStyle.rowColor); |
bpatel@766 | 219 | addConstantMember(fields.get(i), tr); |
bpatel@766 | 220 | tbody.addContent(tr); |
bpatel@766 | 221 | } |
bpatel@766 | 222 | Content table = getConstantMembersHeader(cd); |
bpatel@766 | 223 | table.addContent(tbody); |
bpatel@766 | 224 | Content li = HtmlTree.LI(HtmlStyle.blockList, table); |
bpatel@766 | 225 | classConstantTree.addContent(li); |
duke@1 | 226 | } |
duke@1 | 227 | |
duke@1 | 228 | /** |
bpatel@766 | 229 | * Add the row for the constant summary table. |
bpatel@766 | 230 | * |
bpatel@766 | 231 | * @param member the field to be documented. |
bpatel@766 | 232 | * @param trTree an htmltree object for the table row |
duke@1 | 233 | */ |
bpatel@766 | 234 | private void addConstantMember(FieldDoc member, HtmlTree trTree) { |
bpatel@766 | 235 | trTree.addContent(getTypeColumn(member)); |
bpatel@766 | 236 | trTree.addContent(getNameColumn(member)); |
bpatel@766 | 237 | trTree.addContent(getValue(member)); |
duke@1 | 238 | } |
duke@1 | 239 | |
bpatel@766 | 240 | /** |
bpatel@766 | 241 | * Get the type column for the constant summary table row. |
bpatel@766 | 242 | * |
bpatel@766 | 243 | * @param member the field to be documented. |
bpatel@766 | 244 | * @return the type column of the constant table row |
bpatel@766 | 245 | */ |
bpatel@766 | 246 | private Content getTypeColumn(FieldDoc member) { |
bpatel@766 | 247 | Content anchor = getMarkerAnchor(currentClassDoc.qualifiedName() + |
bpatel@766 | 248 | "." + member.name()); |
bpatel@766 | 249 | Content tdType = HtmlTree.TD(HtmlStyle.colFirst, anchor); |
bpatel@766 | 250 | Content code = new HtmlTree(HtmlTag.CODE); |
bpatel@766 | 251 | StringTokenizer mods = new StringTokenizer(member.modifiers()); |
bpatel@766 | 252 | while(mods.hasMoreTokens()) { |
bpatel@766 | 253 | Content modifier = new StringContent(mods.nextToken()); |
bpatel@766 | 254 | code.addContent(modifier); |
bpatel@766 | 255 | code.addContent(getSpace()); |
duke@1 | 256 | } |
bpatel@766 | 257 | Content type = new RawHtml(getLink(new LinkInfoImpl( |
bpatel@766 | 258 | LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, member.type()))); |
bpatel@766 | 259 | code.addContent(type); |
bpatel@766 | 260 | tdType.addContent(code); |
bpatel@766 | 261 | return tdType; |
bpatel@766 | 262 | } |
bpatel@766 | 263 | |
bpatel@766 | 264 | /** |
bpatel@766 | 265 | * Get the name column for the constant summary table row. |
bpatel@766 | 266 | * |
bpatel@766 | 267 | * @param member the field to be documented. |
bpatel@766 | 268 | * @return the name column of the constant table row |
bpatel@766 | 269 | */ |
bpatel@766 | 270 | private Content getNameColumn(FieldDoc member) { |
bpatel@766 | 271 | Content nameContent = new RawHtml(getDocLink( |
bpatel@766 | 272 | LinkInfoImpl.CONTEXT_CONSTANT_SUMMARY, member, member.name(), false)); |
bpatel@766 | 273 | Content code = HtmlTree.CODE(nameContent); |
bpatel@766 | 274 | return HtmlTree.TD(code); |
bpatel@766 | 275 | } |
bpatel@766 | 276 | |
bpatel@766 | 277 | /** |
bpatel@766 | 278 | * Get the value column for the constant summary table row. |
bpatel@766 | 279 | * |
bpatel@766 | 280 | * @param member the field to be documented. |
bpatel@766 | 281 | * @return the value column of the constant table row |
bpatel@766 | 282 | */ |
bpatel@766 | 283 | private Content getValue(FieldDoc member) { |
bpatel@766 | 284 | Content valueContent = new StringContent(member.constantValueExpression()); |
bpatel@766 | 285 | Content code = HtmlTree.CODE(valueContent); |
bpatel@766 | 286 | return HtmlTree.TD(HtmlStyle.colLast, code); |
duke@1 | 287 | } |
duke@1 | 288 | |
duke@1 | 289 | /** |
duke@1 | 290 | * {@inheritDoc} |
duke@1 | 291 | */ |
bpatel@766 | 292 | public void addFooter(Content contentTree) { |
bpatel@766 | 293 | addNavLinks(false, contentTree); |
bpatel@766 | 294 | addBottom(contentTree); |
duke@1 | 295 | } |
duke@1 | 296 | |
duke@1 | 297 | /** |
duke@1 | 298 | * {@inheritDoc} |
duke@1 | 299 | */ |
bpatel@766 | 300 | public void printDocument(Content contentTree) { |
bpatel@766 | 301 | printHtmlDocument(null, true, contentTree); |
duke@1 | 302 | } |
duke@1 | 303 | } |