Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 1998, 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 | |
duke@1 | 28 | import java.io.*; |
duke@1 | 29 | import java.util.*; |
duke@1 | 30 | |
bpatel@766 | 31 | import com.sun.javadoc.*; |
bpatel@766 | 32 | import com.sun.tools.doclets.internal.toolkit.*; |
bpatel@766 | 33 | import com.sun.tools.doclets.internal.toolkit.util.*; |
bpatel@766 | 34 | import com.sun.tools.doclets.formats.html.markup.*; |
bpatel@766 | 35 | |
duke@1 | 36 | /** |
duke@1 | 37 | * Generate the file with list of all the classes in this run. This page will be |
duke@1 | 38 | * used in the left-hand bottom frame, when "All Classes" link is clicked in |
duke@1 | 39 | * the left-hand top frame. The name of the generated file is |
duke@1 | 40 | * "allclasses-frame.html". |
duke@1 | 41 | * |
duke@1 | 42 | * @author Atul M Dambalkar |
duke@1 | 43 | * @author Doug Kramer |
bpatel@766 | 44 | * @author Bhavesh Patel (Modified) |
duke@1 | 45 | */ |
duke@1 | 46 | public class AllClassesFrameWriter extends HtmlDocletWriter { |
duke@1 | 47 | |
duke@1 | 48 | /** |
duke@1 | 49 | * The name of the output file with frames |
duke@1 | 50 | */ |
duke@1 | 51 | public static final String OUTPUT_FILE_NAME_FRAMES = "allclasses-frame.html"; |
duke@1 | 52 | |
duke@1 | 53 | /** |
duke@1 | 54 | * The name of the output file without frames |
duke@1 | 55 | */ |
duke@1 | 56 | public static final String OUTPUT_FILE_NAME_NOFRAMES = "allclasses-noframe.html"; |
duke@1 | 57 | |
duke@1 | 58 | /** |
duke@1 | 59 | * Index of all the classes. |
duke@1 | 60 | */ |
duke@1 | 61 | protected IndexBuilder indexbuilder; |
duke@1 | 62 | |
duke@1 | 63 | /** |
bpatel@766 | 64 | * BR tag to be used within a document tree. |
bpatel@766 | 65 | */ |
bpatel@766 | 66 | final HtmlTree BR = new HtmlTree(HtmlTag.BR); |
bpatel@766 | 67 | |
bpatel@766 | 68 | /** |
duke@1 | 69 | * Construct AllClassesFrameWriter object. Also initilises the indexbuilder |
duke@1 | 70 | * variable in this class. |
duke@1 | 71 | * @throws IOException |
duke@1 | 72 | * @throws DocletAbortException |
duke@1 | 73 | */ |
duke@1 | 74 | public AllClassesFrameWriter(ConfigurationImpl configuration, |
duke@1 | 75 | String filename, IndexBuilder indexbuilder) |
duke@1 | 76 | throws IOException { |
duke@1 | 77 | super(configuration, filename); |
duke@1 | 78 | this.indexbuilder = indexbuilder; |
duke@1 | 79 | } |
duke@1 | 80 | |
duke@1 | 81 | /** |
duke@1 | 82 | * Create AllClassesFrameWriter object. Then use it to generate the |
duke@1 | 83 | * "allclasses-frame.html" file. Generate the file in the current or the |
duke@1 | 84 | * destination directory. |
duke@1 | 85 | * |
duke@1 | 86 | * @param indexbuilder IndexBuilder object for all classes index. |
duke@1 | 87 | * @throws DocletAbortException |
duke@1 | 88 | */ |
duke@1 | 89 | public static void generate(ConfigurationImpl configuration, |
duke@1 | 90 | IndexBuilder indexbuilder) { |
duke@1 | 91 | AllClassesFrameWriter allclassgen; |
duke@1 | 92 | String filename = OUTPUT_FILE_NAME_FRAMES; |
duke@1 | 93 | try { |
duke@1 | 94 | allclassgen = new AllClassesFrameWriter(configuration, |
duke@1 | 95 | filename, indexbuilder); |
bpatel@766 | 96 | allclassgen.buildAllClassesFile(true); |
duke@1 | 97 | allclassgen.close(); |
duke@1 | 98 | filename = OUTPUT_FILE_NAME_NOFRAMES; |
duke@1 | 99 | allclassgen = new AllClassesFrameWriter(configuration, |
duke@1 | 100 | filename, indexbuilder); |
bpatel@766 | 101 | allclassgen.buildAllClassesFile(false); |
duke@1 | 102 | allclassgen.close(); |
duke@1 | 103 | } catch (IOException exc) { |
duke@1 | 104 | configuration.standardmessage. |
duke@1 | 105 | error("doclet.exception_encountered", |
duke@1 | 106 | exc.toString(), filename); |
duke@1 | 107 | throw new DocletAbortException(); |
duke@1 | 108 | } |
duke@1 | 109 | } |
duke@1 | 110 | |
duke@1 | 111 | /** |
bpatel@766 | 112 | * Print all the classes in the file. |
duke@1 | 113 | * @param wantFrames True if we want frames. |
duke@1 | 114 | */ |
bpatel@766 | 115 | protected void buildAllClassesFile(boolean wantFrames) throws IOException { |
duke@1 | 116 | String label = configuration.getText("doclet.All_Classes"); |
bpatel@766 | 117 | Content body = getBody(false, getWindowTitle(label)); |
bpatel@766 | 118 | Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, |
bpatel@766 | 119 | HtmlStyle.bar, allclassesLabel); |
bpatel@766 | 120 | body.addContent(heading); |
bpatel@766 | 121 | Content ul = new HtmlTree(HtmlTag.UL); |
bpatel@766 | 122 | // Generate the class links and add it to the tdFont tree. |
bpatel@766 | 123 | addAllClasses(ul, wantFrames); |
bpatel@766 | 124 | Content div = HtmlTree.DIV(HtmlStyle.indexContainer, ul); |
bpatel@766 | 125 | body.addContent(div); |
bpatel@766 | 126 | printHtmlDocument(null, false, body); |
duke@1 | 127 | } |
duke@1 | 128 | |
duke@1 | 129 | /** |
bpatel@766 | 130 | * Use the sorted index of all the classes and add all the classes to the |
bpatel@766 | 131 | * content list. |
duke@1 | 132 | * |
bpatel@766 | 133 | * @param content HtmlTree content to which all classes information will be added |
duke@1 | 134 | * @param wantFrames True if we want frames. |
duke@1 | 135 | */ |
bpatel@766 | 136 | protected void addAllClasses(Content content, boolean wantFrames) { |
duke@1 | 137 | for (int i = 0; i < indexbuilder.elements().length; i++) { |
duke@1 | 138 | Character unicode = (Character)((indexbuilder.elements())[i]); |
bpatel@766 | 139 | addContents(indexbuilder.getMemberList(unicode), wantFrames, content); |
duke@1 | 140 | } |
duke@1 | 141 | } |
duke@1 | 142 | |
duke@1 | 143 | /** |
duke@1 | 144 | * Given a list of classes, generate links for each class or interface. |
duke@1 | 145 | * If the class kind is interface, print it in the italics font. Also all |
duke@1 | 146 | * links should target the right-hand frame. If clicked on any class name |
duke@1 | 147 | * in this page, appropriate class page should get opened in the right-hand |
duke@1 | 148 | * frame. |
duke@1 | 149 | * |
duke@1 | 150 | * @param classlist Sorted list of classes. |
duke@1 | 151 | * @param wantFrames True if we want frames. |
bpatel@766 | 152 | * @param content HtmlTree content to which the links will be added |
duke@1 | 153 | */ |
bpatel@766 | 154 | protected void addContents(List<Doc> classlist, boolean wantFrames, |
bpatel@766 | 155 | Content content) { |
duke@1 | 156 | for (int i = 0; i < classlist.size(); i++) { |
mcimadamore@184 | 157 | ClassDoc cd = (ClassDoc)classlist.get(i); |
duke@1 | 158 | if (!Util.isCoreClass(cd)) { |
duke@1 | 159 | continue; |
duke@1 | 160 | } |
duke@1 | 161 | String label = italicsClassName(cd, false); |
bpatel@766 | 162 | Content linkContent; |
duke@1 | 163 | if(wantFrames){ |
bpatel@766 | 164 | linkContent = new RawHtml(getLink(new LinkInfoImpl( |
bpatel@766 | 165 | LinkInfoImpl.ALL_CLASSES_FRAME, cd, label, "classFrame"))); |
duke@1 | 166 | } else { |
bpatel@766 | 167 | linkContent = new RawHtml(getLink(new LinkInfoImpl(cd, label))); |
duke@1 | 168 | } |
bpatel@766 | 169 | Content li = HtmlTree.LI(linkContent); |
bpatel@766 | 170 | content.addContent(li); |
duke@1 | 171 | } |
duke@1 | 172 | } |
duke@1 | 173 | } |