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

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

mercurial