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

Sun, 24 Feb 2013 11:36:58 -0800

author
jjg
date
Sun, 24 Feb 2013 11:36:58 -0800
changeset 1606
ccbe7ffdd867
parent 1410
bfec2a1cc869
child 1736
74cd21f2c2fe
permissions
-rw-r--r--

7112427: The doclet needs to be able to generate JavaFX documentation.
Reviewed-by: jjg
Contributed-by: jan.valenta@oracle.com

     1 /*
     2  * Copyright (c) 2003, 2013, 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.builders;
    28 import java.io.*;
    30 import com.sun.javadoc.*;
    31 import com.sun.tools.doclets.internal.toolkit.*;
    32 import com.sun.tools.doclets.internal.toolkit.util.*;
    34 /**
    35  * Builds the summary for a given package.
    36  *
    37  *  <p><b>This is NOT part of any supported API.
    38  *  If you write code that depends on this, you do so at your own risk.
    39  *  This code and its internal interfaces are subject to change or
    40  *  deletion without notice.</b>
    41  *
    42  * @author Jamie Ho
    43  * @author Bhavesh Patel (Modified)
    44  * @since 1.5
    45  */
    46 public class PackageSummaryBuilder extends AbstractBuilder {
    47     /**
    48      * The root element of the package summary XML is {@value}.
    49      */
    50     public static final String ROOT = "PackageDoc";
    52     /**
    53      * The package being documented.
    54      */
    55     private final PackageDoc packageDoc;
    57     /**
    58      * The doclet specific writer that will output the result.
    59      */
    60     private final PackageSummaryWriter packageWriter;
    62     /**
    63      * The content that will be added to the package summary documentation tree.
    64      */
    65     private Content contentTree;
    67     /**
    68      * Construct a new PackageSummaryBuilder.
    69      *
    70      * @param context  the build context.
    71      * @param pkg the package being documented.
    72      * @param packageWriter the doclet specific writer that will output the
    73      *        result.
    74      */
    75     private PackageSummaryBuilder(Context context,
    76             PackageDoc pkg,
    77             PackageSummaryWriter packageWriter) {
    78         super(context);
    79         this.packageDoc = pkg;
    80         this.packageWriter = packageWriter;
    81     }
    83     /**
    84      * Construct a new PackageSummaryBuilder.
    85      *
    86      * @param context  the build context.
    87      * @param pkg the package being documented.
    88      * @param packageWriter the doclet specific writer that will output the
    89      *        result.
    90      *
    91      * @return an instance of a PackageSummaryBuilder.
    92      */
    93     public static PackageSummaryBuilder getInstance(Context context,
    94             PackageDoc pkg, PackageSummaryWriter packageWriter) {
    95         return new PackageSummaryBuilder(context, pkg, packageWriter);
    96     }
    98     /**
    99      * Build the package summary.
   100      */
   101     public void build() throws IOException {
   102         if (packageWriter == null) {
   103             //Doclet does not support this output.
   104             return;
   105         }
   106         build(layoutParser.parseXML(ROOT), contentTree);
   107     }
   109     /**
   110      * {@inheritDoc}
   111      */
   112     public String getName() {
   113         return ROOT;
   114     }
   116     /**
   117      * Build the package documentation.
   118      *
   119      * @param node the XML element that specifies which components to document
   120      * @param contentTree the content tree to which the documentation will be added
   121      */
   122     public void buildPackageDoc(XMLNode node, Content contentTree) throws Exception {
   123         contentTree = packageWriter.getPackageHeader(
   124                 Util.getPackageName(packageDoc));
   125         buildChildren(node, contentTree);
   126         packageWriter.addPackageFooter(contentTree);
   127         packageWriter.printDocument(contentTree);
   128         packageWriter.close();
   129         Util.copyDocFiles(configuration, packageDoc);
   130     }
   132     /**
   133      * Build the content for the package doc.
   134      *
   135      * @param node the XML element that specifies which components to document
   136      * @param contentTree the content tree to which the package contents
   137      *                    will be added
   138      */
   139     public void buildContent(XMLNode node, Content contentTree) {
   140         Content packageContentTree = packageWriter.getContentHeader();
   141         buildChildren(node, packageContentTree);
   142         contentTree.addContent(packageContentTree);
   143     }
   145     /**
   146      * Build the package summary.
   147      *
   148      * @param node the XML element that specifies which components to document
   149      * @param packageContentTree the package content tree to which the summaries will
   150      *                           be added
   151      */
   152     public void buildSummary(XMLNode node, Content packageContentTree) {
   153         Content summaryContentTree = packageWriter.getSummaryHeader();
   154         buildChildren(node, summaryContentTree);
   155         packageContentTree.addContent(summaryContentTree);
   156     }
   158     /**
   159      * Build the summary for the interfaces in this package.
   160      *
   161      * @param node the XML element that specifies which components to document
   162      * @param summaryContentTree the summary tree to which the interface summary
   163      *                           will be added
   164      */
   165     public void buildInterfaceSummary(XMLNode node, Content summaryContentTree) {
   166         String interfaceTableSummary =
   167                 configuration.getText("doclet.Member_Table_Summary",
   168                 configuration.getText("doclet.Interface_Summary"),
   169                 configuration.getText("doclet.interfaces"));
   170         String[] interfaceTableHeader = new String[] {
   171             configuration.getText("doclet.Interface"),
   172             configuration.getText("doclet.Description")
   173         };
   174         ClassDoc[] interfaces =
   175                 packageDoc.isIncluded()
   176                         ? packageDoc.interfaces()
   177                         : configuration.classDocCatalog.interfaces(
   178                                 Util.getPackageName(packageDoc));
   179         interfaces = Util.filterOutPrivateClasses(interfaces, configuration.javafx);
   180         if (interfaces.length > 0) {
   181             packageWriter.addClassesSummary(
   182                     interfaces,
   183                     configuration.getText("doclet.Interface_Summary"),
   184                     interfaceTableSummary, interfaceTableHeader, summaryContentTree);
   185         }
   186     }
   188     /**
   189      * Build the summary for the classes in this package.
   190      *
   191      * @param node the XML element that specifies which components to document
   192      * @param summaryContentTree the summary tree to which the class summary will
   193      *                           be added
   194      */
   195     public void buildClassSummary(XMLNode node, Content summaryContentTree) {
   196         String classTableSummary =
   197                 configuration.getText("doclet.Member_Table_Summary",
   198                 configuration.getText("doclet.Class_Summary"),
   199                 configuration.getText("doclet.classes"));
   200         String[] classTableHeader = new String[] {
   201             configuration.getText("doclet.Class"),
   202             configuration.getText("doclet.Description")
   203         };
   204         ClassDoc[] classes =
   205                 packageDoc.isIncluded()
   206                         ? packageDoc.ordinaryClasses()
   207                         : configuration.classDocCatalog.ordinaryClasses(
   208                                 Util.getPackageName(packageDoc));
   209         classes = Util.filterOutPrivateClasses(classes, configuration.javafx);
   210         if (classes.length > 0) {
   211             packageWriter.addClassesSummary(
   212                     classes,
   213                     configuration.getText("doclet.Class_Summary"),
   214                     classTableSummary, classTableHeader, summaryContentTree);
   215         }
   216     }
   218     /**
   219      * Build the summary for the enums in this package.
   220      *
   221      * @param node the XML element that specifies which components to document
   222      * @param summaryContentTree the summary tree to which the enum summary will
   223      *                           be added
   224      */
   225     public void buildEnumSummary(XMLNode node, Content summaryContentTree) {
   226         String enumTableSummary =
   227                 configuration.getText("doclet.Member_Table_Summary",
   228                 configuration.getText("doclet.Enum_Summary"),
   229                 configuration.getText("doclet.enums"));
   230         String[] enumTableHeader = new String[] {
   231             configuration.getText("doclet.Enum"),
   232             configuration.getText("doclet.Description")
   233         };
   234         ClassDoc[] enums =
   235                 packageDoc.isIncluded()
   236                         ? packageDoc.enums()
   237                         : configuration.classDocCatalog.enums(
   238                                 Util.getPackageName(packageDoc));
   239         enums = Util.filterOutPrivateClasses(enums, configuration.javafx);
   240         if (enums.length > 0) {
   241             packageWriter.addClassesSummary(
   242                     enums,
   243                     configuration.getText("doclet.Enum_Summary"),
   244                     enumTableSummary, enumTableHeader, summaryContentTree);
   245         }
   246     }
   248     /**
   249      * Build the summary for the exceptions in this package.
   250      *
   251      * @param node the XML element that specifies which components to document
   252      * @param summaryContentTree the summary tree to which the exception summary will
   253      *                           be added
   254      */
   255     public void buildExceptionSummary(XMLNode node, Content summaryContentTree) {
   256         String exceptionTableSummary =
   257                 configuration.getText("doclet.Member_Table_Summary",
   258                 configuration.getText("doclet.Exception_Summary"),
   259                 configuration.getText("doclet.exceptions"));
   260         String[] exceptionTableHeader = new String[] {
   261             configuration.getText("doclet.Exception"),
   262             configuration.getText("doclet.Description")
   263         };
   264         ClassDoc[] exceptions =
   265                 packageDoc.isIncluded()
   266                         ? packageDoc.exceptions()
   267                         : configuration.classDocCatalog.exceptions(
   268                                 Util.getPackageName(packageDoc));
   269         exceptions = Util.filterOutPrivateClasses(exceptions, configuration.javafx);
   270         if (exceptions.length > 0) {
   271             packageWriter.addClassesSummary(
   272                     exceptions,
   273                     configuration.getText("doclet.Exception_Summary"),
   274                     exceptionTableSummary, exceptionTableHeader, summaryContentTree);
   275         }
   276     }
   278     /**
   279      * Build the summary for the errors in this package.
   280      *
   281      * @param node the XML element that specifies which components to document
   282      * @param summaryContentTree the summary tree to which the error summary will
   283      *                           be added
   284      */
   285     public void buildErrorSummary(XMLNode node, Content summaryContentTree) {
   286         String errorTableSummary =
   287                 configuration.getText("doclet.Member_Table_Summary",
   288                 configuration.getText("doclet.Error_Summary"),
   289                 configuration.getText("doclet.errors"));
   290         String[] errorTableHeader = new String[] {
   291             configuration.getText("doclet.Error"),
   292             configuration.getText("doclet.Description")
   293         };
   294         ClassDoc[] errors =
   295                 packageDoc.isIncluded()
   296                         ? packageDoc.errors()
   297                         : configuration.classDocCatalog.errors(
   298                                 Util.getPackageName(packageDoc));
   299         errors = Util.filterOutPrivateClasses(errors, configuration.javafx);
   300         if (errors.length > 0) {
   301             packageWriter.addClassesSummary(
   302                     errors,
   303                     configuration.getText("doclet.Error_Summary"),
   304                     errorTableSummary, errorTableHeader, summaryContentTree);
   305         }
   306     }
   308     /**
   309      * Build the summary for the annotation type in this package.
   310      *
   311      * @param node the XML element that specifies which components to document
   312      * @param summaryContentTree the summary tree to which the annotation type
   313      *                           summary will be added
   314      */
   315     public void buildAnnotationTypeSummary(XMLNode node, Content summaryContentTree) {
   316         String annotationtypeTableSummary =
   317                 configuration.getText("doclet.Member_Table_Summary",
   318                 configuration.getText("doclet.Annotation_Types_Summary"),
   319                 configuration.getText("doclet.annotationtypes"));
   320         String[] annotationtypeTableHeader = new String[] {
   321             configuration.getText("doclet.AnnotationType"),
   322             configuration.getText("doclet.Description")
   323         };
   324         ClassDoc[] annotationTypes =
   325                 packageDoc.isIncluded()
   326                         ? packageDoc.annotationTypes()
   327                         : configuration.classDocCatalog.annotationTypes(
   328                                 Util.getPackageName(packageDoc));
   329         annotationTypes = Util.filterOutPrivateClasses(annotationTypes, configuration.javafx);
   330         if (annotationTypes.length > 0) {
   331             packageWriter.addClassesSummary(
   332                     annotationTypes,
   333                     configuration.getText("doclet.Annotation_Types_Summary"),
   334                     annotationtypeTableSummary, annotationtypeTableHeader,
   335                     summaryContentTree);
   336         }
   337     }
   339     /**
   340      * Build the description of the summary.
   341      *
   342      * @param node the XML element that specifies which components to document
   343      * @param packageContentTree the tree to which the package description will
   344      *                           be added
   345      */
   346     public void buildPackageDescription(XMLNode node, Content packageContentTree) {
   347         if (configuration.nocomment) {
   348             return;
   349         }
   350         packageWriter.addPackageDescription(packageContentTree);
   351     }
   353     /**
   354      * Build the tags of the summary.
   355      *
   356      * @param node the XML element that specifies which components to document
   357      * @param packageContentTree the tree to which the package tags will be added
   358      */
   359     public void buildPackageTags(XMLNode node, Content packageContentTree) {
   360         if (configuration.nocomment) {
   361             return;
   362         }
   363         packageWriter.addPackageTags(packageContentTree);
   364     }
   365 }

mercurial