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

Tue, 18 Jun 2013 20:56:04 -0700

author
mfang
date
Tue, 18 Jun 2013 20:56:04 -0700
changeset 1841
792c40d5185a
parent 1611
6f988040a1c8
child 2071
2c24a04ebfb4
permissions
-rw-r--r--

8015657: jdk8 l10n resource file translation update 3
Reviewed-by: yhuang

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

mercurial