aoqi@0: /* aefimov@3315: * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.doclets.internal.toolkit; aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.builders.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*; aoqi@0: aoqi@0: /** aoqi@0: * An abstract implementation of a Doclet. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: * aoqi@0: * @author Jamie Ho aoqi@0: */ aoqi@0: public abstract class AbstractDoclet { aoqi@0: aoqi@0: /** aoqi@0: * The global configuration information for this run. aoqi@0: */ aoqi@0: public Configuration configuration; aoqi@0: aoqi@0: /** aoqi@0: * The only doclet that may use this toolkit is {@value} aoqi@0: */ aoqi@0: private static final String TOOLKIT_DOCLET_NAME = aoqi@0: com.sun.tools.doclets.formats.html.HtmlDoclet.class.getName(); aoqi@0: aoqi@0: /** aoqi@0: * Verify that the only doclet that is using this toolkit is aoqi@0: * {@value #TOOLKIT_DOCLET_NAME}. aoqi@0: */ aoqi@0: private boolean isValidDoclet(AbstractDoclet doclet) { aoqi@0: if (! doclet.getClass().getName().equals(TOOLKIT_DOCLET_NAME)) { aoqi@0: configuration.message.error("doclet.Toolkit_Usage_Violation", aoqi@0: TOOLKIT_DOCLET_NAME); aoqi@0: return false; aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * The method that starts the execution of the doclet. aoqi@0: * aoqi@0: * @param doclet the doclet to start the execution for. aoqi@0: * @param root the {@link RootDoc} that points to the source to document. aoqi@0: * @return true if the doclet executed without error. False otherwise. aoqi@0: */ aoqi@0: public boolean start(AbstractDoclet doclet, RootDoc root) { aoqi@0: configuration = configuration(); aoqi@0: configuration.root = root; aoqi@0: if (! isValidDoclet(doclet)) { aoqi@0: return false; aoqi@0: } aoqi@0: try { aoqi@0: doclet.startGeneration(root); aoqi@0: } catch (Configuration.Fault f) { aoqi@0: root.printError(f.getMessage()); aoqi@0: return false; aefimov@3315: } catch (FatalError fe) { aefimov@3315: return false; aoqi@0: } catch (DocletAbortException e) { aoqi@0: Throwable cause = e.getCause(); aoqi@0: if (cause != null) { aoqi@0: if (cause.getLocalizedMessage() != null) { aoqi@0: root.printError(cause.getLocalizedMessage()); aoqi@0: } else { aoqi@0: root.printError(cause.toString()); aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } catch (Exception exc) { aoqi@0: exc.printStackTrace(); aoqi@0: return false; aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Indicate that this doclet supports the 1.5 language features. aoqi@0: * @return JAVA_1_5, indicating that the new features are supported. aoqi@0: */ aoqi@0: public static LanguageVersion languageVersion() { aoqi@0: return LanguageVersion.JAVA_1_5; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Create the configuration instance and returns it. aoqi@0: * @return the configuration of the doclet. aoqi@0: */ aoqi@0: public abstract Configuration configuration(); aoqi@0: aoqi@0: /** aoqi@0: * Start the generation of files. Call generate methods in the individual aoqi@0: * writers, which will in turn generate the documentation files. Call the aoqi@0: * TreeWriter generation first to ensure the Class Hierarchy is built aoqi@0: * first and then can be used in the later generation. aoqi@0: * aoqi@0: * @see com.sun.javadoc.RootDoc aoqi@0: */ aoqi@0: private void startGeneration(RootDoc root) throws Configuration.Fault, Exception { aoqi@0: if (root.classes().length == 0) { aoqi@0: configuration.message. aoqi@0: error("doclet.No_Public_Classes_To_Document"); aoqi@0: return; aoqi@0: } aoqi@0: configuration.setOptions(); aoqi@0: configuration.getDocletSpecificMsg().notice("doclet.build_version", aoqi@0: configuration.getDocletSpecificBuildDate()); aoqi@0: ClassTree classtree = new ClassTree(configuration, configuration.nodeprecated); aoqi@0: aoqi@0: generateClassFiles(root, classtree); aoqi@0: Util.copyDocFiles(configuration, DocPaths.DOC_FILES); aoqi@0: aoqi@0: PackageListWriter.generate(configuration); aoqi@0: generatePackageFiles(classtree); aoqi@0: generateProfileFiles(); aoqi@0: aoqi@0: generateOtherFiles(root, classtree); aoqi@0: configuration.tagletManager.printReport(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Generate additional documentation that is added to the API documentation. aoqi@0: * aoqi@0: * @param root the RootDoc of source to document. aoqi@0: * @param classtree the data structure representing the class tree. aoqi@0: */ aoqi@0: protected void generateOtherFiles(RootDoc root, ClassTree classtree) throws Exception { aoqi@0: BuilderFactory builderFactory = configuration.getBuilderFactory(); aoqi@0: AbstractBuilder constantsSummaryBuilder = builderFactory.getConstantsSummaryBuider(); aoqi@0: constantsSummaryBuilder.build(); aoqi@0: AbstractBuilder serializedFormBuilder = builderFactory.getSerializedFormBuilder(); aoqi@0: serializedFormBuilder.build(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Generate the profile documentation. aoqi@0: * aoqi@0: */ aoqi@0: protected abstract void generateProfileFiles() throws Exception; aoqi@0: aoqi@0: /** aoqi@0: * Generate the package documentation. aoqi@0: * aoqi@0: * @param classtree the data structure representing the class tree. aoqi@0: */ aoqi@0: protected abstract void generatePackageFiles(ClassTree classtree) throws Exception; aoqi@0: aoqi@0: /** aoqi@0: * Generate the class documentation. aoqi@0: * aoqi@0: * @param classtree the data structure representing the class tree. aoqi@0: */ aoqi@0: protected abstract void generateClassFiles(ClassDoc[] arr, ClassTree classtree); aoqi@0: aoqi@0: /** aoqi@0: * Iterate through all classes and construct documentation for them. aoqi@0: * aoqi@0: * @param root the RootDoc of source to document. aoqi@0: * @param classtree the data structure representing the class tree. aoqi@0: */ aoqi@0: protected void generateClassFiles(RootDoc root, ClassTree classtree) { aoqi@0: generateClassFiles(classtree); aoqi@0: PackageDoc[] packages = root.specifiedPackages(); aoqi@0: for (int i = 0; i < packages.length; i++) { aoqi@0: generateClassFiles(packages[i].allClasses(), classtree); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Generate the class files for single classes specified on the command line. aoqi@0: * aoqi@0: * @param classtree the data structure representing the class tree. aoqi@0: */ aoqi@0: private void generateClassFiles(ClassTree classtree) { aoqi@0: String[] packageNames = configuration.classDocCatalog.packageNames(); aoqi@0: for (int packageNameIndex = 0; packageNameIndex < packageNames.length; aoqi@0: packageNameIndex++) { aoqi@0: generateClassFiles(configuration.classDocCatalog.allClasses( aoqi@0: packageNames[packageNameIndex]), classtree); aoqi@0: } aoqi@0: } aoqi@0: }