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

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 2071
2c24a04ebfb4
parent 0
959103a6100f
child 3446
e468915bad3a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, 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;
aoqi@0 86 } catch (DocletAbortException e) {
aoqi@0 87 Throwable cause = e.getCause();
aoqi@0 88 if (cause != null) {
aoqi@0 89 if (cause.getLocalizedMessage() != null) {
aoqi@0 90 root.printError(cause.getLocalizedMessage());
aoqi@0 91 } else {
aoqi@0 92 root.printError(cause.toString());
aoqi@0 93 }
aoqi@0 94 }
aoqi@0 95 return false;
aoqi@0 96 } catch (Exception exc) {
aoqi@0 97 exc.printStackTrace();
aoqi@0 98 return false;
aoqi@0 99 }
aoqi@0 100 return true;
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 /**
aoqi@0 104 * Indicate that this doclet supports the 1.5 language features.
aoqi@0 105 * @return JAVA_1_5, indicating that the new features are supported.
aoqi@0 106 */
aoqi@0 107 public static LanguageVersion languageVersion() {
aoqi@0 108 return LanguageVersion.JAVA_1_5;
aoqi@0 109 }
aoqi@0 110
aoqi@0 111
aoqi@0 112 /**
aoqi@0 113 * Create the configuration instance and returns it.
aoqi@0 114 * @return the configuration of the doclet.
aoqi@0 115 */
aoqi@0 116 public abstract Configuration configuration();
aoqi@0 117
aoqi@0 118 /**
aoqi@0 119 * Start the generation of files. Call generate methods in the individual
aoqi@0 120 * writers, which will in turn generate the documentation files. Call the
aoqi@0 121 * TreeWriter generation first to ensure the Class Hierarchy is built
aoqi@0 122 * first and then can be used in the later generation.
aoqi@0 123 *
aoqi@0 124 * @see com.sun.javadoc.RootDoc
aoqi@0 125 */
aoqi@0 126 private void startGeneration(RootDoc root) throws Configuration.Fault, Exception {
aoqi@0 127 if (root.classes().length == 0) {
aoqi@0 128 configuration.message.
aoqi@0 129 error("doclet.No_Public_Classes_To_Document");
aoqi@0 130 return;
aoqi@0 131 }
aoqi@0 132 configuration.setOptions();
aoqi@0 133 configuration.getDocletSpecificMsg().notice("doclet.build_version",
aoqi@0 134 configuration.getDocletSpecificBuildDate());
aoqi@0 135 ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated);
aoqi@0 136
aoqi@0 137 generateClassFiles(root, classtree);
aoqi@0 138 Util.copyDocFiles(configuration, DocPaths.DOC_FILES);
aoqi@0 139
aoqi@0 140 PackageListWriter.generate(configuration);
aoqi@0 141 generatePackageFiles(classtree);
aoqi@0 142 generateProfileFiles();
aoqi@0 143
aoqi@0 144 generateOtherFiles(root, classtree);
aoqi@0 145 configuration.tagletManager.printReport();
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 /**
aoqi@0 149 * Generate additional documentation that is added to the API documentation.
aoqi@0 150 *
aoqi@0 151 * @param root the RootDoc of source to document.
aoqi@0 152 * @param classtree the data structure representing the class tree.
aoqi@0 153 */
aoqi@0 154 protected void generateOtherFiles(RootDoc root, ClassTree classtree) throws Exception {
aoqi@0 155 BuilderFactory builderFactory = configuration.getBuilderFactory();
aoqi@0 156 AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuider();
aoqi@0 157 constantsSummaryBuilder.build();
aoqi@0 158 AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder();
aoqi@0 159 serializedFormBuilder.build();
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 /**
aoqi@0 163 * Generate the profile documentation.
aoqi@0 164 *
aoqi@0 165 */
aoqi@0 166 protected abstract void generateProfileFiles() throws Exception;
aoqi@0 167
aoqi@0 168 /**
aoqi@0 169 * Generate the package documentation.
aoqi@0 170 *
aoqi@0 171 * @param classtree the data structure representing the class tree.
aoqi@0 172 */
aoqi@0 173 protected abstract void generatePackageFiles(ClassTree classtree) throws Exception;
aoqi@0 174
aoqi@0 175 /**
aoqi@0 176 * Generate the class documentation.
aoqi@0 177 *
aoqi@0 178 * @param classtree the data structure representing the class tree.
aoqi@0 179 */
aoqi@0 180 protected abstract void generateClassFiles(ClassDoc[] arr, ClassTree classtree);
aoqi@0 181
aoqi@0 182 /**
aoqi@0 183 * Iterate through all classes and construct documentation for them.
aoqi@0 184 *
aoqi@0 185 * @param root the RootDoc of source to document.
aoqi@0 186 * @param classtree the data structure representing the class tree.
aoqi@0 187 */
aoqi@0 188 protected void generateClassFiles(RootDoc root, ClassTree classtree) {
aoqi@0 189 generateClassFiles(classtree);
aoqi@0 190 PackageDoc[] packages = root.specifiedPackages();
aoqi@0 191 for (int i = 0; i < packages.length; i++) {
aoqi@0 192 generateClassFiles(packages[i].allClasses(), classtree);
aoqi@0 193 }
aoqi@0 194 }
aoqi@0 195
aoqi@0 196 /**
aoqi@0 197 * Generate the class files for single classes specified on the command line.
aoqi@0 198 *
aoqi@0 199 * @param classtree the data structure representing the class tree.
aoqi@0 200 */
aoqi@0 201 private void generateClassFiles(ClassTree classtree) {
aoqi@0 202 String[] packageNames = configuration.classDocCatalog.packageNames();
aoqi@0 203 for (int packageNameIndex = 0; packageNameIndex < packageNames.length;
aoqi@0 204 packageNameIndex++) {
aoqi@0 205 generateClassFiles(configuration.classDocCatalog.allClasses(
aoqi@0 206 packageNames[packageNameIndex]), classtree);
aoqi@0 207 }
aoqi@0 208 }
aoqi@0 209 }

mercurial