src/share/classes/com/sun/tools/doclets/internal/toolkit/AbstractDoclet.java

Fri, 27 Sep 2013 21:20:01 +0400

author
kizune
date
Fri, 27 Sep 2013 21:20:01 +0400
changeset 2071
2c24a04ebfb4
parent 1611
6f988040a1c8
child 2525
2eb010b6cb22
child 3315
6f0746b6de9f
permissions
-rw-r--r--

6978886: javadoc shows stacktrace after print error resulting from disk full
Reviewed-by: jjg

duke@1 1 /*
bpatel@1568 2 * Copyright (c) 2003, 2013, 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.internal.toolkit;
duke@1 27
jjg@1357 28 import com.sun.javadoc.*;
duke@1 29 import com.sun.tools.doclets.internal.toolkit.builders.*;
duke@1 30 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 31
duke@1 32 /**
duke@1 33 * An abstract implementation of a Doclet.
duke@1 34 *
jjg@1359 35 * <p><b>This is NOT part of any supported API.
jjg@1359 36 * If you write code that depends on this, you do so at your own risk.
jjg@1359 37 * This code and its internal interfaces are subject to change or
jjg@1359 38 * deletion without notice.</b>
duke@1 39 *
duke@1 40 * @author Jamie Ho
duke@1 41 */
duke@1 42 public abstract class AbstractDoclet {
duke@1 43
duke@1 44 /**
duke@1 45 * The global configuration information for this run.
duke@1 46 */
jjg@140 47 public Configuration configuration;
duke@1 48
duke@1 49 /**
duke@1 50 * The only doclet that may use this toolkit is {@value}
duke@1 51 */
jjg@1410 52 private static final String TOOLKIT_DOCLET_NAME =
jjg@1410 53 com.sun.tools.doclets.formats.html.HtmlDoclet.class.getName();
duke@1 54
duke@1 55 /**
duke@1 56 * Verify that the only doclet that is using this toolkit is
duke@1 57 * {@value #TOOLKIT_DOCLET_NAME}.
duke@1 58 */
duke@1 59 private boolean isValidDoclet(AbstractDoclet doclet) {
duke@1 60 if (! doclet.getClass().getName().equals(TOOLKIT_DOCLET_NAME)) {
duke@1 61 configuration.message.error("doclet.Toolkit_Usage_Violation",
duke@1 62 TOOLKIT_DOCLET_NAME);
duke@1 63 return false;
duke@1 64 }
duke@1 65 return true;
duke@1 66 }
duke@1 67
duke@1 68 /**
duke@1 69 * The method that starts the execution of the doclet.
duke@1 70 *
duke@1 71 * @param doclet the doclet to start the execution for.
duke@1 72 * @param root the {@link RootDoc} that points to the source to document.
duke@1 73 * @return true if the doclet executed without error. False otherwise.
duke@1 74 */
duke@1 75 public boolean start(AbstractDoclet doclet, RootDoc root) {
jjg@140 76 configuration = configuration();
duke@1 77 configuration.root = root;
duke@1 78 if (! isValidDoclet(doclet)) {
duke@1 79 return false;
duke@1 80 }
duke@1 81 try {
duke@1 82 doclet.startGeneration(root);
jjg@1611 83 } catch (Configuration.Fault f) {
jjg@1611 84 root.printError(f.getMessage());
jjg@1611 85 return false;
kizune@2071 86 } catch (DocletAbortException e) {
kizune@2071 87 Throwable cause = e.getCause();
kizune@2071 88 if (cause != null) {
kizune@2071 89 if (cause.getLocalizedMessage() != null) {
kizune@2071 90 root.printError(cause.getLocalizedMessage());
kizune@2071 91 } else {
kizune@2071 92 root.printError(cause.toString());
kizune@2071 93 }
kizune@2071 94 }
kizune@2071 95 return false;
duke@1 96 } catch (Exception exc) {
duke@1 97 exc.printStackTrace();
duke@1 98 return false;
duke@1 99 }
duke@1 100 return true;
duke@1 101 }
duke@1 102
duke@1 103 /**
duke@1 104 * Indicate that this doclet supports the 1.5 language features.
duke@1 105 * @return JAVA_1_5, indicating that the new features are supported.
duke@1 106 */
duke@1 107 public static LanguageVersion languageVersion() {
duke@1 108 return LanguageVersion.JAVA_1_5;
duke@1 109 }
duke@1 110
duke@1 111
duke@1 112 /**
duke@1 113 * Create the configuration instance and returns it.
duke@1 114 * @return the configuration of the doclet.
duke@1 115 */
duke@1 116 public abstract Configuration configuration();
duke@1 117
duke@1 118 /**
duke@1 119 * Start the generation of files. Call generate methods in the individual
jjg@1383 120 * writers, which will in turn generate the documentation files. Call the
duke@1 121 * TreeWriter generation first to ensure the Class Hierarchy is built
duke@1 122 * first and then can be used in the later generation.
duke@1 123 *
duke@1 124 * @see com.sun.javadoc.RootDoc
duke@1 125 */
jjg@1611 126 private void startGeneration(RootDoc root) throws Configuration.Fault, Exception {
duke@1 127 if (root.classes().length == 0) {
duke@1 128 configuration.message.
duke@1 129 error("doclet.No_Public_Classes_To_Document");
duke@1 130 return;
duke@1 131 }
duke@1 132 configuration.setOptions();
duke@1 133 configuration.getDocletSpecificMsg().notice("doclet.build_version",
duke@1 134 configuration.getDocletSpecificBuildDate());
duke@1 135 ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated);
duke@1 136
duke@1 137 generateClassFiles(root, classtree);
jjg@1383 138 Util.copyDocFiles(configuration, DocPaths.DOC_FILES);
duke@1 139
duke@1 140 PackageListWriter.generate(configuration);
duke@1 141 generatePackageFiles(classtree);
bpatel@1568 142 generateProfileFiles();
duke@1 143
duke@1 144 generateOtherFiles(root, classtree);
duke@1 145 configuration.tagletManager.printReport();
duke@1 146 }
duke@1 147
duke@1 148 /**
duke@1 149 * Generate additional documentation that is added to the API documentation.
duke@1 150 *
duke@1 151 * @param root the RootDoc of source to document.
duke@1 152 * @param classtree the data structure representing the class tree.
duke@1 153 */
duke@1 154 protected void generateOtherFiles(RootDoc root, ClassTree classtree) throws Exception {
duke@1 155 BuilderFactory builderFactory = configuration.getBuilderFactory();
duke@1 156 AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuider();
duke@1 157 constantsSummaryBuilder.build();
duke@1 158 AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder();
duke@1 159 serializedFormBuilder.build();
duke@1 160 }
duke@1 161
duke@1 162 /**
bpatel@1568 163 * Generate the profile documentation.
bpatel@1568 164 *
bpatel@1568 165 */
bpatel@1568 166 protected abstract void generateProfileFiles() throws Exception;
bpatel@1568 167
bpatel@1568 168 /**
duke@1 169 * Generate the package documentation.
duke@1 170 *
duke@1 171 * @param classtree the data structure representing the class tree.
duke@1 172 */
duke@1 173 protected abstract void generatePackageFiles(ClassTree classtree) throws Exception;
duke@1 174
duke@1 175 /**
duke@1 176 * Generate the class documentation.
duke@1 177 *
duke@1 178 * @param classtree the data structure representing the class tree.
duke@1 179 */
duke@1 180 protected abstract void generateClassFiles(ClassDoc[] arr, ClassTree classtree);
duke@1 181
duke@1 182 /**
duke@1 183 * Iterate through all classes and construct documentation for them.
duke@1 184 *
duke@1 185 * @param root the RootDoc of source to document.
duke@1 186 * @param classtree the data structure representing the class tree.
duke@1 187 */
duke@1 188 protected void generateClassFiles(RootDoc root, ClassTree classtree) {
duke@1 189 generateClassFiles(classtree);
duke@1 190 PackageDoc[] packages = root.specifiedPackages();
duke@1 191 for (int i = 0; i < packages.length; i++) {
duke@1 192 generateClassFiles(packages[i].allClasses(), classtree);
duke@1 193 }
duke@1 194 }
duke@1 195
duke@1 196 /**
duke@1 197 * Generate the class files for single classes specified on the command line.
duke@1 198 *
duke@1 199 * @param classtree the data structure representing the class tree.
duke@1 200 */
duke@1 201 private void generateClassFiles(ClassTree classtree) {
duke@1 202 String[] packageNames = configuration.classDocCatalog.packageNames();
duke@1 203 for (int packageNameIndex = 0; packageNameIndex < packageNames.length;
duke@1 204 packageNameIndex++) {
duke@1 205 generateClassFiles(configuration.classDocCatalog.allClasses(
duke@1 206 packageNames[packageNameIndex]), classtree);
duke@1 207 }
duke@1 208 }
duke@1 209 }

mercurial