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

Mon, 18 Jul 2016 23:53:12 +0300

author
aefimov
date
Mon, 18 Jul 2016 23:53:12 +0300
changeset 3315
6f0746b6de9f
parent 2071
2c24a04ebfb4
child 3446
e468915bad3a
permissions
-rw-r--r--

8138725: Add options for Javadoc generation
Reviewed-by: jjg

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

mercurial