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

Thu, 24 May 2018 18:02:46 +0800

author
aoqi
date
Thu, 24 May 2018 18:02:46 +0800
changeset 3446
e468915bad3a
parent 3315
6f0746b6de9f
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aefimov@3315 2 * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.doclets.internal.toolkit;
aoqi@0 27
aoqi@0 28 import com.sun.javadoc.*;
aoqi@0 29 import com.sun.tools.doclets.internal.toolkit.builders.*;
aoqi@0 30 import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0 31
aoqi@0 32 /**
aoqi@0 33 * An abstract implementation of a Doclet.
aoqi@0 34 *
aoqi@0 35 * <p><b>This is NOT part of any supported API.
aoqi@0 36 * If you write code that depends on this, you do so at your own risk.
aoqi@0 37 * This code and its internal interfaces are subject to change or
aoqi@0 38 * deletion without notice.</b>
aoqi@0 39 *
aoqi@0 40 * @author Jamie Ho
aoqi@0 41 */
aoqi@0 42 public abstract class AbstractDoclet {
aoqi@0 43
aoqi@0 44 /**
aoqi@0 45 * The global configuration information for this run.
aoqi@0 46 */
aoqi@0 47 public Configuration configuration;
aoqi@0 48
aoqi@0 49 /**
aoqi@0 50 * The only doclet that may use this toolkit is {@value}
aoqi@0 51 */
aoqi@0 52 private static final String TOOLKIT_DOCLET_NAME =
aoqi@0 53 com.sun.tools.doclets.formats.html.HtmlDoclet.class.getName();
aoqi@0 54
aoqi@0 55 /**
aoqi@0 56 * Verify that the only doclet that is using this toolkit is
aoqi@0 57 * {@value #TOOLKIT_DOCLET_NAME}.
aoqi@0 58 */
aoqi@0 59 private boolean isValidDoclet(AbstractDoclet doclet) {
aoqi@0 60 if (! doclet.getClass().getName().equals(TOOLKIT_DOCLET_NAME)) {
aoqi@0 61 configuration.message.error("doclet.Toolkit_Usage_Violation",
aoqi@0 62 TOOLKIT_DOCLET_NAME);
aoqi@0 63 return false;
aoqi@0 64 }
aoqi@0 65 return true;
aoqi@0 66 }
aoqi@0 67
aoqi@0 68 /**
aoqi@0 69 * The method that starts the execution of the doclet.
aoqi@0 70 *
aoqi@0 71 * @param doclet the doclet to start the execution for.
aoqi@0 72 * @param root the {@link RootDoc} that points to the source to document.
aoqi@0 73 * @return true if the doclet executed without error. False otherwise.
aoqi@0 74 */
aoqi@0 75 public boolean start(AbstractDoclet doclet, RootDoc root) {
aoqi@0 76 configuration = configuration();
aoqi@0 77 configuration.root = root;
aoqi@0 78 if (! isValidDoclet(doclet)) {
aoqi@0 79 return false;
aoqi@0 80 }
aoqi@0 81 try {
aoqi@0 82 doclet.startGeneration(root);
aoqi@0 83 } catch (Configuration.Fault f) {
aoqi@0 84 root.printError(f.getMessage());
aoqi@0 85 return false;
aefimov@3315 86 } catch (FatalError fe) {
aefimov@3315 87 return false;
aoqi@0 88 } catch (DocletAbortException e) {
aoqi@0 89 Throwable cause = e.getCause();
aoqi@0 90 if (cause != null) {
aoqi@0 91 if (cause.getLocalizedMessage() != null) {
aoqi@0 92 root.printError(cause.getLocalizedMessage());
aoqi@0 93 } else {
aoqi@0 94 root.printError(cause.toString());
aoqi@0 95 }
aoqi@0 96 }
aoqi@0 97 return false;
aoqi@0 98 } catch (Exception exc) {
aoqi@0 99 exc.printStackTrace();
aoqi@0 100 return false;
aoqi@0 101 }
aoqi@0 102 return true;
aoqi@0 103 }
aoqi@0 104
aoqi@0 105 /**
aoqi@0 106 * Indicate that this doclet supports the 1.5 language features.
aoqi@0 107 * @return JAVA_1_5, indicating that the new features are supported.
aoqi@0 108 */
aoqi@0 109 public static LanguageVersion languageVersion() {
aoqi@0 110 return LanguageVersion.JAVA_1_5;
aoqi@0 111 }
aoqi@0 112
aoqi@0 113
aoqi@0 114 /**
aoqi@0 115 * Create the configuration instance and returns it.
aoqi@0 116 * @return the configuration of the doclet.
aoqi@0 117 */
aoqi@0 118 public abstract Configuration configuration();
aoqi@0 119
aoqi@0 120 /**
aoqi@0 121 * Start the generation of files. Call generate methods in the individual
aoqi@0 122 * writers, which will in turn generate the documentation files. Call the
aoqi@0 123 * TreeWriter generation first to ensure the Class Hierarchy is built
aoqi@0 124 * first and then can be used in the later generation.
aoqi@0 125 *
aoqi@0 126 * @see com.sun.javadoc.RootDoc
aoqi@0 127 */
aoqi@0 128 private void startGeneration(RootDoc root) throws Configuration.Fault, Exception {
aoqi@0 129 if (root.classes().length == 0) {
aoqi@0 130 configuration.message.
aoqi@0 131 error("doclet.No_Public_Classes_To_Document");
aoqi@0 132 return;
aoqi@0 133 }
aoqi@0 134 configuration.setOptions();
aoqi@0 135 configuration.getDocletSpecificMsg().notice("doclet.build_version",
aoqi@0 136 configuration.getDocletSpecificBuildDate());
aoqi@0 137 ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated);
aoqi@0 138
aoqi@0 139 generateClassFiles(root, classtree);
aoqi@0 140 Util.copyDocFiles(configuration, DocPaths.DOC_FILES);
aoqi@0 141
aoqi@0 142 PackageListWriter.generate(configuration);
aoqi@0 143 generatePackageFiles(classtree);
aoqi@0 144 generateProfileFiles();
aoqi@0 145
aoqi@0 146 generateOtherFiles(root, classtree);
aoqi@0 147 configuration.tagletManager.printReport();
aoqi@0 148 }
aoqi@0 149
aoqi@0 150 /**
aoqi@0 151 * Generate additional documentation that is added to the API documentation.
aoqi@0 152 *
aoqi@0 153 * @param root the RootDoc of source to document.
aoqi@0 154 * @param classtree the data structure representing the class tree.
aoqi@0 155 */
aoqi@0 156 protected void generateOtherFiles(RootDoc root, ClassTree classtree) throws Exception {
aoqi@0 157 BuilderFactory builderFactory = configuration.getBuilderFactory();
aoqi@0 158 AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuider();
aoqi@0 159 constantsSummaryBuilder.build();
aoqi@0 160 AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder();
aoqi@0 161 serializedFormBuilder.build();
aoqi@0 162 }
aoqi@0 163
aoqi@0 164 /**
aoqi@0 165 * Generate the profile documentation.
aoqi@0 166 *
aoqi@0 167 */
aoqi@0 168 protected abstract void generateProfileFiles() throws Exception;
aoqi@0 169
aoqi@0 170 /**
aoqi@0 171 * Generate the package documentation.
aoqi@0 172 *
aoqi@0 173 * @param classtree the data structure representing the class tree.
aoqi@0 174 */
aoqi@0 175 protected abstract void generatePackageFiles(ClassTree classtree) throws Exception;
aoqi@0 176
aoqi@0 177 /**
aoqi@0 178 * Generate the class documentation.
aoqi@0 179 *
aoqi@0 180 * @param classtree the data structure representing the class tree.
aoqi@0 181 */
aoqi@0 182 protected abstract void generateClassFiles(ClassDoc[] arr, ClassTree classtree);
aoqi@0 183
aoqi@0 184 /**
aoqi@0 185 * Iterate through all classes and construct documentation for them.
aoqi@0 186 *
aoqi@0 187 * @param root the RootDoc of source to document.
aoqi@0 188 * @param classtree the data structure representing the class tree.
aoqi@0 189 */
aoqi@0 190 protected void generateClassFiles(RootDoc root, ClassTree classtree) {
aoqi@0 191 generateClassFiles(classtree);
aoqi@0 192 PackageDoc[] packages = root.specifiedPackages();
aoqi@0 193 for (int i = 0; i < packages.length; i++) {
aoqi@0 194 generateClassFiles(packages[i].allClasses(), classtree);
aoqi@0 195 }
aoqi@0 196 }
aoqi@0 197
aoqi@0 198 /**
aoqi@0 199 * Generate the class files for single classes specified on the command line.
aoqi@0 200 *
aoqi@0 201 * @param classtree the data structure representing the class tree.
aoqi@0 202 */
aoqi@0 203 private void generateClassFiles(ClassTree classtree) {
aoqi@0 204 String[] packageNames = configuration.classDocCatalog.packageNames();
aoqi@0 205 for (int packageNameIndex = 0; packageNameIndex < packageNames.length;
aoqi@0 206 packageNameIndex++) {
aoqi@0 207 generateClassFiles(configuration.classDocCatalog.allClasses(
aoqi@0 208 packageNames[packageNameIndex]), classtree);
aoqi@0 209 }
aoqi@0 210 }
aoqi@0 211 }

mercurial