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 | package com.sun.tools.doclets.formats.html; |
duke@1 | 26 | |
duke@1 | 27 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 28 | import com.sun.tools.doclets.internal.toolkit.builders.*; |
duke@1 | 29 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 30 | |
duke@1 | 31 | import com.sun.javadoc.*; |
duke@1 | 32 | import java.util.*; |
duke@1 | 33 | import java.io.*; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * The class with "start" method, calls individual Writers. |
duke@1 | 37 | * |
duke@1 | 38 | * @author Atul M Dambalkar |
duke@1 | 39 | * @author Robert Field |
duke@1 | 40 | * @author Jamie Ho |
duke@1 | 41 | * |
duke@1 | 42 | */ |
duke@1 | 43 | public class HtmlDoclet extends AbstractDoclet { |
jjg@140 | 44 | public HtmlDoclet() { |
jjg@140 | 45 | configuration = (ConfigurationImpl) configuration(); |
jjg@140 | 46 | } |
duke@1 | 47 | |
duke@1 | 48 | /** |
duke@1 | 49 | * The global configuration information for this run. |
duke@1 | 50 | */ |
jjg@140 | 51 | public ConfigurationImpl configuration; |
duke@1 | 52 | |
duke@1 | 53 | /** |
duke@1 | 54 | * The "start" method as required by Javadoc. |
duke@1 | 55 | * |
duke@1 | 56 | * @param root the root of the documentation tree. |
duke@1 | 57 | * @see com.sun.javadoc.RootDoc |
duke@1 | 58 | * @return true if the doclet ran without encountering any errors. |
duke@1 | 59 | */ |
duke@1 | 60 | public static boolean start(RootDoc root) { |
jjg@140 | 61 | try { |
jjg@140 | 62 | HtmlDoclet doclet = new HtmlDoclet(); |
jjg@140 | 63 | return doclet.start(doclet, root); |
jjg@140 | 64 | } finally { |
jjg@140 | 65 | ConfigurationImpl.reset(); |
jjg@140 | 66 | } |
duke@1 | 67 | } |
duke@1 | 68 | |
duke@1 | 69 | /** |
duke@1 | 70 | * Create the configuration instance. |
duke@1 | 71 | * Override this method to use a different |
duke@1 | 72 | * configuration. |
duke@1 | 73 | */ |
duke@1 | 74 | public Configuration configuration() { |
duke@1 | 75 | return ConfigurationImpl.getInstance(); |
duke@1 | 76 | } |
duke@1 | 77 | |
duke@1 | 78 | /** |
duke@1 | 79 | * Start the generation of files. Call generate methods in the individual |
duke@1 | 80 | * writers, which will in turn genrate the documentation files. Call the |
duke@1 | 81 | * TreeWriter generation first to ensure the Class Hierarchy is built |
duke@1 | 82 | * first and then can be used in the later generation. |
duke@1 | 83 | * |
duke@1 | 84 | * For new format. |
duke@1 | 85 | * |
duke@1 | 86 | * @see com.sun.javadoc.RootDoc |
duke@1 | 87 | */ |
duke@1 | 88 | protected void generateOtherFiles(RootDoc root, ClassTree classtree) |
duke@1 | 89 | throws Exception { |
duke@1 | 90 | super.generateOtherFiles(root, classtree); |
duke@1 | 91 | if (configuration.linksource) { |
duke@1 | 92 | if (configuration.destDirName.length() > 0) { |
duke@1 | 93 | SourceToHTMLConverter.convertRoot(configuration, |
duke@1 | 94 | root, configuration.destDirName + File.separator |
duke@1 | 95 | + DocletConstants.SOURCE_OUTPUT_DIR_NAME); |
duke@1 | 96 | } else { |
duke@1 | 97 | SourceToHTMLConverter.convertRoot(configuration, |
duke@1 | 98 | root, DocletConstants.SOURCE_OUTPUT_DIR_NAME); |
duke@1 | 99 | } |
duke@1 | 100 | } |
duke@1 | 101 | |
duke@1 | 102 | if (configuration.topFile.length() == 0) { |
duke@1 | 103 | configuration.standardmessage. |
duke@1 | 104 | error("doclet.No_Non_Deprecated_Classes_To_Document"); |
duke@1 | 105 | return; |
duke@1 | 106 | } |
duke@1 | 107 | boolean nodeprecated = configuration.nodeprecated; |
duke@1 | 108 | String configdestdir = configuration.destDirName; |
duke@1 | 109 | String confighelpfile = configuration.helpfile; |
duke@1 | 110 | String configstylefile = configuration.stylesheetfile; |
duke@1 | 111 | performCopy(configdestdir, confighelpfile); |
duke@1 | 112 | performCopy(configdestdir, configstylefile); |
duke@1 | 113 | Util.copyResourceFile(configuration, "inherit.gif", false); |
duke@1 | 114 | // do early to reduce memory footprint |
duke@1 | 115 | if (configuration.classuse) { |
duke@1 | 116 | ClassUseWriter.generate(configuration, classtree); |
duke@1 | 117 | } |
duke@1 | 118 | IndexBuilder indexbuilder = new IndexBuilder(configuration, nodeprecated); |
duke@1 | 119 | |
duke@1 | 120 | if (configuration.createtree) { |
duke@1 | 121 | TreeWriter.generate(configuration, classtree); |
duke@1 | 122 | } |
duke@1 | 123 | if (configuration.createindex) { |
duke@1 | 124 | if (configuration.splitindex) { |
duke@1 | 125 | SplitIndexWriter.generate(configuration, indexbuilder); |
duke@1 | 126 | } else { |
duke@1 | 127 | SingleIndexWriter.generate(configuration, indexbuilder); |
duke@1 | 128 | } |
duke@1 | 129 | } |
duke@1 | 130 | |
duke@1 | 131 | if (!(configuration.nodeprecatedlist || nodeprecated)) { |
duke@1 | 132 | DeprecatedListWriter.generate(configuration); |
duke@1 | 133 | } |
duke@1 | 134 | |
duke@1 | 135 | AllClassesFrameWriter.generate(configuration, |
duke@1 | 136 | new IndexBuilder(configuration, nodeprecated, true)); |
duke@1 | 137 | |
duke@1 | 138 | FrameOutputWriter.generate(configuration); |
duke@1 | 139 | |
duke@1 | 140 | if (configuration.createoverview) { |
duke@1 | 141 | PackageIndexWriter.generate(configuration); |
duke@1 | 142 | } |
duke@1 | 143 | if (configuration.helpfile.length() == 0 && |
duke@1 | 144 | !configuration.nohelp) { |
duke@1 | 145 | HelpWriter.generate(configuration); |
duke@1 | 146 | } |
bpatel@793 | 147 | // If a stylesheet file is not specified, copy the default stylesheet |
bpatel@793 | 148 | // and replace newline with platform-specific newline. |
duke@1 | 149 | if (configuration.stylesheetfile.length() == 0) { |
bpatel@766 | 150 | Util.copyFile(configuration, "stylesheet.css", Util.RESOURCESDIR, |
bpatel@766 | 151 | (configdestdir.isEmpty()) ? |
bpatel@793 | 152 | System.getProperty("user.dir") : configdestdir, false, true); |
duke@1 | 153 | } |
duke@1 | 154 | } |
duke@1 | 155 | |
duke@1 | 156 | /** |
duke@1 | 157 | * {@inheritDoc} |
duke@1 | 158 | */ |
duke@1 | 159 | protected void generateClassFiles(ClassDoc[] arr, ClassTree classtree) { |
duke@1 | 160 | Arrays.sort(arr); |
duke@1 | 161 | for(int i = 0; i < arr.length; i++) { |
duke@1 | 162 | if (!(configuration.isGeneratedDoc(arr[i]) && arr[i].isIncluded())) { |
duke@1 | 163 | continue; |
duke@1 | 164 | } |
duke@1 | 165 | ClassDoc prev = (i == 0)? |
duke@1 | 166 | null: |
duke@1 | 167 | arr[i-1]; |
duke@1 | 168 | ClassDoc curr = arr[i]; |
duke@1 | 169 | ClassDoc next = (i+1 == arr.length)? |
duke@1 | 170 | null: |
duke@1 | 171 | arr[i+1]; |
duke@1 | 172 | try { |
duke@1 | 173 | if (curr.isAnnotationType()) { |
duke@1 | 174 | AbstractBuilder annotationTypeBuilder = |
duke@1 | 175 | configuration.getBuilderFactory() |
duke@1 | 176 | .getAnnotationTypeBuilder((AnnotationTypeDoc) curr, |
duke@1 | 177 | prev, next); |
duke@1 | 178 | annotationTypeBuilder.build(); |
duke@1 | 179 | } else { |
duke@1 | 180 | AbstractBuilder classBuilder = |
duke@1 | 181 | configuration.getBuilderFactory() |
duke@1 | 182 | .getClassBuilder(curr, prev, next, classtree); |
duke@1 | 183 | classBuilder.build(); |
duke@1 | 184 | } |
duke@1 | 185 | } catch (Exception e) { |
duke@1 | 186 | e.printStackTrace(); |
duke@1 | 187 | throw new DocletAbortException(); |
duke@1 | 188 | } |
duke@1 | 189 | } |
duke@1 | 190 | } |
duke@1 | 191 | |
duke@1 | 192 | /** |
duke@1 | 193 | * {@inheritDoc} |
duke@1 | 194 | */ |
duke@1 | 195 | protected void generatePackageFiles(ClassTree classtree) throws Exception { |
duke@1 | 196 | PackageDoc[] packages = configuration.packages; |
duke@1 | 197 | if (packages.length > 1) { |
duke@1 | 198 | PackageIndexFrameWriter.generate(configuration); |
duke@1 | 199 | } |
duke@1 | 200 | PackageDoc prev = null, next; |
duke@1 | 201 | for(int i = 0; i < packages.length; i++) { |
duke@1 | 202 | PackageFrameWriter.generate(configuration, packages[i]); |
duke@1 | 203 | next = (i + 1 < packages.length && packages[i+1].name().length() > 0) ? |
duke@1 | 204 | packages[i+1] : null; |
duke@1 | 205 | //If the next package is unnamed package, skip 2 ahead if possible |
duke@1 | 206 | next = (i + 2 < packages.length && next == null) ? |
duke@1 | 207 | packages[i+2]: next; |
duke@1 | 208 | AbstractBuilder packageSummaryBuilder = configuration. |
duke@1 | 209 | getBuilderFactory().getPackageSummaryBuilder( |
duke@1 | 210 | packages[i], prev, next); |
duke@1 | 211 | packageSummaryBuilder.build(); |
duke@1 | 212 | if (configuration.createtree) { |
duke@1 | 213 | PackageTreeWriter.generate(configuration, |
duke@1 | 214 | packages[i], prev, next, |
duke@1 | 215 | configuration.nodeprecated); |
duke@1 | 216 | } |
duke@1 | 217 | prev = packages[i]; |
duke@1 | 218 | } |
duke@1 | 219 | } |
duke@1 | 220 | |
duke@1 | 221 | /** |
duke@1 | 222 | * Check for doclet added options here. |
duke@1 | 223 | * |
duke@1 | 224 | * @return number of arguments to option. Zero return means |
duke@1 | 225 | * option not known. Negative value means error occurred. |
duke@1 | 226 | */ |
duke@1 | 227 | public static int optionLength(String option) { |
duke@1 | 228 | // Construct temporary configuration for check |
duke@1 | 229 | return (ConfigurationImpl.getInstance()).optionLength(option); |
duke@1 | 230 | } |
duke@1 | 231 | |
duke@1 | 232 | /** |
duke@1 | 233 | * Check that options have the correct arguments here. |
duke@1 | 234 | * <P> |
duke@1 | 235 | * This method is not required and will default gracefully |
duke@1 | 236 | * (to true) if absent. |
duke@1 | 237 | * <P> |
duke@1 | 238 | * Printing option related error messages (using the provided |
duke@1 | 239 | * DocErrorReporter) is the responsibility of this method. |
duke@1 | 240 | * |
duke@1 | 241 | * @return true if the options are valid. |
duke@1 | 242 | */ |
duke@1 | 243 | public static boolean validOptions(String options[][], |
duke@1 | 244 | DocErrorReporter reporter) { |
duke@1 | 245 | // Construct temporary configuration for check |
duke@1 | 246 | return (ConfigurationImpl.getInstance()).validOptions(options, reporter); |
duke@1 | 247 | } |
duke@1 | 248 | |
duke@1 | 249 | private void performCopy(String configdestdir, String filename) { |
duke@1 | 250 | try { |
duke@1 | 251 | String destdir = (configdestdir.length() > 0) ? |
duke@1 | 252 | configdestdir + File.separatorChar: ""; |
duke@1 | 253 | if (filename.length() > 0) { |
duke@1 | 254 | File helpstylefile = new File(filename); |
duke@1 | 255 | String parent = helpstylefile.getParent(); |
duke@1 | 256 | String helpstylefilename = (parent == null)? |
duke@1 | 257 | filename: |
duke@1 | 258 | filename.substring(parent.length() + 1); |
duke@1 | 259 | File desthelpfile = new File(destdir + helpstylefilename); |
duke@1 | 260 | if (!desthelpfile.getCanonicalPath().equals( |
duke@1 | 261 | helpstylefile.getCanonicalPath())) { |
duke@1 | 262 | configuration.message. |
duke@1 | 263 | notice((SourcePosition) null, |
duke@1 | 264 | "doclet.Copying_File_0_To_File_1", |
duke@1 | 265 | helpstylefile.toString(), desthelpfile.toString()); |
duke@1 | 266 | Util.copyFile(desthelpfile, helpstylefile); |
duke@1 | 267 | } |
duke@1 | 268 | } |
duke@1 | 269 | } catch (IOException exc) { |
duke@1 | 270 | configuration.message. |
duke@1 | 271 | error((SourcePosition) null, |
duke@1 | 272 | "doclet.perform_copy_exception_encountered", |
duke@1 | 273 | exc.toString()); |
duke@1 | 274 | throw new DocletAbortException(); |
duke@1 | 275 | } |
duke@1 | 276 | } |
duke@1 | 277 | } |