Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 1997, 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 com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 30 | import com.sun.tools.doclets.internal.toolkit.util.DeprecatedAPIListBuilder; |
duke@1 | 31 | import com.sun.tools.doclets.internal.toolkit.util.*; |
bpatel@766 | 32 | import com.sun.tools.doclets.formats.html.markup.*; |
duke@1 | 33 | |
duke@1 | 34 | /** |
duke@1 | 35 | * Generate File to list all the deprecated classes and class members with the |
duke@1 | 36 | * appropriate links. |
duke@1 | 37 | * |
duke@1 | 38 | * @see java.util.List |
duke@1 | 39 | * @author Atul M Dambalkar |
bpatel@243 | 40 | * @author Bhavesh Patel (Modified) |
duke@1 | 41 | */ |
duke@1 | 42 | public class DeprecatedListWriter extends SubWriterHolderWriter { |
duke@1 | 43 | |
duke@1 | 44 | private static final String[] ANCHORS = new String[] { |
duke@1 | 45 | "interface", "class", "enum", "exception", "error", "annotation_type", |
duke@1 | 46 | "field", "method", "constructor", "enum_constant", |
duke@1 | 47 | "annotation_type_member" |
duke@1 | 48 | }; |
duke@1 | 49 | |
duke@1 | 50 | private static final String[] HEADING_KEYS = new String[] { |
duke@1 | 51 | "doclet.Deprecated_Interfaces", "doclet.Deprecated_Classes", |
duke@1 | 52 | "doclet.Deprecated_Enums", "doclet.Deprecated_Exceptions", |
duke@1 | 53 | "doclet.Deprecated_Errors", |
duke@1 | 54 | "doclet.Deprecated_Annotation_Types", |
duke@1 | 55 | "doclet.Deprecated_Fields", |
duke@1 | 56 | "doclet.Deprecated_Methods", "doclet.Deprecated_Constructors", |
duke@1 | 57 | "doclet.Deprecated_Enum_Constants", |
duke@1 | 58 | "doclet.Deprecated_Annotation_Type_Members" |
duke@1 | 59 | }; |
duke@1 | 60 | |
bpatel@243 | 61 | private static final String[] SUMMARY_KEYS = new String[] { |
bpatel@243 | 62 | "doclet.deprecated_interfaces", "doclet.deprecated_classes", |
bpatel@243 | 63 | "doclet.deprecated_enums", "doclet.deprecated_exceptions", |
bpatel@243 | 64 | "doclet.deprecated_errors", |
bpatel@243 | 65 | "doclet.deprecated_annotation_types", |
bpatel@243 | 66 | "doclet.deprecated_fields", |
bpatel@243 | 67 | "doclet.deprecated_methods", "doclet.deprecated_constructors", |
bpatel@243 | 68 | "doclet.deprecated_enum_constants", |
bpatel@243 | 69 | "doclet.deprecated_annotation_type_members" |
bpatel@243 | 70 | }; |
bpatel@243 | 71 | |
bpatel@243 | 72 | private static final String[] HEADER_KEYS = new String[] { |
bpatel@243 | 73 | "doclet.Interface", "doclet.Class", |
bpatel@243 | 74 | "doclet.Enum", "doclet.Exceptions", |
bpatel@243 | 75 | "doclet.Errors", |
bpatel@243 | 76 | "doclet.AnnotationType", |
bpatel@243 | 77 | "doclet.Field", |
bpatel@243 | 78 | "doclet.Method", "doclet.Constructor", |
bpatel@243 | 79 | "doclet.Enum_Constant", |
bpatel@243 | 80 | "doclet.Annotation_Type_Member" |
bpatel@243 | 81 | }; |
bpatel@243 | 82 | |
duke@1 | 83 | private AbstractMemberWriter[] writers; |
duke@1 | 84 | |
duke@1 | 85 | private ConfigurationImpl configuration; |
duke@1 | 86 | |
duke@1 | 87 | /** |
duke@1 | 88 | * Constructor. |
duke@1 | 89 | * |
duke@1 | 90 | * @param filename the file to be generated. |
duke@1 | 91 | */ |
duke@1 | 92 | public DeprecatedListWriter(ConfigurationImpl configuration, |
duke@1 | 93 | String filename) throws IOException { |
duke@1 | 94 | super(configuration, filename); |
duke@1 | 95 | this.configuration = configuration; |
duke@1 | 96 | NestedClassWriterImpl classW = new NestedClassWriterImpl(this); |
duke@1 | 97 | writers = new AbstractMemberWriter[] |
duke@1 | 98 | {classW, classW, classW, classW, classW, classW, |
duke@1 | 99 | new FieldWriterImpl(this), |
duke@1 | 100 | new MethodWriterImpl(this), |
duke@1 | 101 | new ConstructorWriterImpl(this), |
duke@1 | 102 | new EnumConstantWriterImpl(this), |
duke@1 | 103 | new AnnotationTypeOptionalMemberWriterImpl(this, null)}; |
duke@1 | 104 | } |
duke@1 | 105 | |
duke@1 | 106 | /** |
duke@1 | 107 | * Get list of all the deprecated classes and members in all the Packages |
duke@1 | 108 | * specified on the Command Line. |
duke@1 | 109 | * Then instantiate DeprecatedListWriter and generate File. |
duke@1 | 110 | * |
duke@1 | 111 | * @param configuration the current configuration of the doclet. |
duke@1 | 112 | */ |
duke@1 | 113 | public static void generate(ConfigurationImpl configuration) { |
duke@1 | 114 | String filename = "deprecated-list.html"; |
duke@1 | 115 | try { |
duke@1 | 116 | DeprecatedListWriter depr = |
duke@1 | 117 | new DeprecatedListWriter(configuration, filename); |
duke@1 | 118 | depr.generateDeprecatedListFile( |
duke@1 | 119 | new DeprecatedAPIListBuilder(configuration.root)); |
duke@1 | 120 | depr.close(); |
duke@1 | 121 | } catch (IOException exc) { |
duke@1 | 122 | configuration.standardmessage.error( |
duke@1 | 123 | "doclet.exception_encountered", |
duke@1 | 124 | exc.toString(), filename); |
duke@1 | 125 | throw new DocletAbortException(); |
duke@1 | 126 | } |
duke@1 | 127 | } |
duke@1 | 128 | |
duke@1 | 129 | /** |
bpatel@766 | 130 | * Generate the deprecated API list. |
duke@1 | 131 | * |
duke@1 | 132 | * @param deprapi list of deprecated API built already. |
duke@1 | 133 | */ |
duke@1 | 134 | protected void generateDeprecatedListFile(DeprecatedAPIListBuilder deprapi) |
bpatel@766 | 135 | throws IOException { |
bpatel@766 | 136 | Content body = getHeader(); |
bpatel@766 | 137 | body.addContent(getContentsList(deprapi)); |
bpatel@243 | 138 | String memberTableSummary; |
bpatel@243 | 139 | String[] memberTableHeader = new String[1]; |
bpatel@766 | 140 | HtmlTree div = new HtmlTree(HtmlTag.DIV); |
bpatel@766 | 141 | div.addStyle(HtmlStyle.contentContainer); |
duke@1 | 142 | for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) { |
duke@1 | 143 | if (deprapi.hasDocumentation(i)) { |
bpatel@766 | 144 | addAnchor(deprapi, i, div); |
bpatel@243 | 145 | memberTableSummary = |
bpatel@243 | 146 | configuration.getText("doclet.Member_Table_Summary", |
bpatel@243 | 147 | configuration.getText(HEADING_KEYS[i]), |
bpatel@243 | 148 | configuration.getText(SUMMARY_KEYS[i])); |
bpatel@243 | 149 | memberTableHeader[0] = configuration.getText("doclet.0_and_1", |
bpatel@243 | 150 | configuration.getText(HEADER_KEYS[i]), |
bpatel@243 | 151 | configuration.getText("doclet.Description")); |
bpatel@766 | 152 | writers[i].addDeprecatedAPI(deprapi.getList(i), |
bpatel@766 | 153 | HEADING_KEYS[i], memberTableSummary, memberTableHeader, div); |
duke@1 | 154 | } |
duke@1 | 155 | } |
bpatel@766 | 156 | body.addContent(div); |
bpatel@766 | 157 | addNavLinks(false, body); |
bpatel@766 | 158 | addBottom(body); |
bpatel@766 | 159 | printHtmlDocument(null, true, body); |
duke@1 | 160 | } |
duke@1 | 161 | |
bpatel@766 | 162 | /** |
bpatel@766 | 163 | * Add the index link. |
bpatel@766 | 164 | * |
bpatel@766 | 165 | * @param builder the deprecated list builder |
bpatel@766 | 166 | * @param type the type of list being documented |
bpatel@766 | 167 | * @param contentTree the content tree to which the index link will be added |
bpatel@766 | 168 | */ |
bpatel@766 | 169 | private void addIndexLink(DeprecatedAPIListBuilder builder, |
bpatel@766 | 170 | int type, Content contentTree) { |
duke@1 | 171 | if (builder.hasDocumentation(type)) { |
bpatel@766 | 172 | Content li = HtmlTree.LI(getHyperLink("#" + ANCHORS[type], |
bpatel@766 | 173 | getResource(HEADING_KEYS[type]))); |
bpatel@766 | 174 | contentTree.addContent(li); |
duke@1 | 175 | } |
duke@1 | 176 | } |
duke@1 | 177 | |
duke@1 | 178 | /** |
bpatel@766 | 179 | * Get the contents list. |
bpatel@766 | 180 | * |
bpatel@766 | 181 | * @param deprapi the deprecated list builder |
bpatel@766 | 182 | * @return a content tree for the contents list |
duke@1 | 183 | */ |
bpatel@766 | 184 | public Content getContentsList(DeprecatedAPIListBuilder deprapi) { |
bpatel@766 | 185 | Content headContent = getResource("doclet.Deprecated_API"); |
bpatel@766 | 186 | Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true, |
bpatel@766 | 187 | HtmlStyle.title, headContent); |
bpatel@766 | 188 | Content div = HtmlTree.DIV(HtmlStyle.header, heading); |
bpatel@766 | 189 | Content headingContent = getResource("doclet.Contents"); |
bpatel@766 | 190 | div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true, |
bpatel@766 | 191 | headingContent)); |
bpatel@766 | 192 | Content ul = new HtmlTree(HtmlTag.UL); |
bpatel@766 | 193 | for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) { |
bpatel@766 | 194 | addIndexLink(deprapi, i, ul); |
bpatel@766 | 195 | } |
bpatel@766 | 196 | div.addContent(ul); |
bpatel@766 | 197 | return div; |
duke@1 | 198 | } |
duke@1 | 199 | |
duke@1 | 200 | /** |
bpatel@766 | 201 | * Add the anchor. |
bpatel@766 | 202 | * |
bpatel@766 | 203 | * @param builder the deprecated list builder |
bpatel@766 | 204 | * @param type the type of list being documented |
bpatel@766 | 205 | * @param contentTree the content tree to which the anchor will be added |
duke@1 | 206 | */ |
bpatel@766 | 207 | private void addAnchor(DeprecatedAPIListBuilder builder, int type, Content htmlTree) { |
bpatel@766 | 208 | if (builder.hasDocumentation(type)) { |
bpatel@766 | 209 | htmlTree.addContent(getMarkerAnchor(ANCHORS[type])); |
bpatel@766 | 210 | } |
duke@1 | 211 | } |
duke@1 | 212 | |
duke@1 | 213 | /** |
bpatel@766 | 214 | * Get the header for the deprecated API Listing. |
bpatel@766 | 215 | * |
bpatel@766 | 216 | * @return a content tree for the header |
duke@1 | 217 | */ |
bpatel@766 | 218 | public Content getHeader() { |
bpatel@766 | 219 | String title = configuration.getText("doclet.Window_Deprecated_List"); |
bpatel@766 | 220 | Content bodyTree = getBody(true, getWindowTitle(title)); |
bpatel@766 | 221 | addTop(bodyTree); |
bpatel@766 | 222 | addNavLinks(true, bodyTree); |
bpatel@766 | 223 | return bodyTree; |
bpatel@766 | 224 | } |
bpatel@766 | 225 | |
bpatel@766 | 226 | /** |
bpatel@766 | 227 | * Get the deprecated label. |
bpatel@766 | 228 | * |
bpatel@766 | 229 | * @return a content tree for the deprecated label |
bpatel@766 | 230 | */ |
bpatel@766 | 231 | protected Content getNavLinkDeprecated() { |
bpatel@766 | 232 | Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, deprecatedLabel); |
bpatel@766 | 233 | return li; |
duke@1 | 234 | } |
duke@1 | 235 | } |