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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 554
9d9f26857129
child 1359
25e14ad23cef
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

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

mercurial