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

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

author
jjg
date
Sun, 24 Feb 2013 11:36:58 -0800
changeset 1606
ccbe7ffdd867
parent 1468
690c41cdab55
child 1858
27bd6a2302f6
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.*;
    29 import java.util.*;
    31 import com.sun.javadoc.*;
    32 import com.sun.tools.doclets.internal.toolkit.*;
    33 import com.sun.tools.doclets.internal.toolkit.util.*;
    35 /**
    36  * Builds the summary for a given class.
    37  *
    38  *  <p><b>This is NOT part of any supported API.
    39  *  If you write code that depends on this, you do so at your own risk.
    40  *  This code and its internal interfaces are subject to change or
    41  *  deletion without notice.</b>
    42  *
    43  * @author Jamie Ho
    44  * @author Bhavesh Patel (Modified)
    45  * @since 1.5
    46  */
    47 public class ClassBuilder extends AbstractBuilder {
    49     /**
    50      * The root element of the class XML is {@value}.
    51      */
    52     public static final String ROOT = "ClassDoc";
    54     /**
    55      * The class being documented.
    56      */
    57     private final ClassDoc classDoc;
    59     /**
    60      * The doclet specific writer.
    61      */
    62     private final ClassWriter writer;
    64     /**
    65      * Keep track of whether or not this classdoc is an interface.
    66      */
    67     private final boolean isInterface;
    69     /**
    70      * Keep track of whether or not this classdoc is an enum.
    71      */
    72     private final boolean isEnum;
    74     /**
    75      * The content tree for the class documentation.
    76      */
    77     private Content contentTree;
    79     /**
    80      * Construct a new ClassBuilder.
    81      *
    82      * @param context  the build context
    83      * @param classDoc the class being documented.
    84      * @param writer the doclet specific writer.
    85      */
    86     private ClassBuilder(Context context,
    87             ClassDoc classDoc, ClassWriter writer) {
    88         super(context);
    89         this.classDoc = classDoc;
    90         this.writer = writer;
    91         if (classDoc.isInterface()) {
    92             isInterface = true;
    93             isEnum = false;
    94         } else if (classDoc.isEnum()) {
    95             isInterface = false;
    96             isEnum = true;
    97             Util.setEnumDocumentation(configuration, classDoc);
    98         } else {
    99             isInterface = false;
   100             isEnum = false;
   101         }
   102     }
   104     /**
   105      * Construct a new ClassBuilder.
   106      *
   107      * @param context  the build context
   108      * @param classDoc the class being documented.
   109      * @param writer the doclet specific writer.
   110      */
   111     public static ClassBuilder getInstance(Context context,
   112             ClassDoc classDoc, ClassWriter writer) {
   113         return new ClassBuilder(context, classDoc, writer);
   114     }
   116     /**
   117      * {@inheritDoc}
   118      */
   119     public void build() throws IOException {
   120         build(layoutParser.parseXML(ROOT), contentTree);
   121     }
   123     /**
   124      * {@inheritDoc}
   125      */
   126     public String getName() {
   127         return ROOT;
   128     }
   130      /**
   131       * Handles the {@literal <ClassDoc>} tag.
   132       *
   133       * @param node the XML element that specifies which components to document
   134       * @param contentTree the content tree to which the documentation will be added
   135       */
   136      public void buildClassDoc(XMLNode node, Content contentTree) throws Exception {
   137          String key;
   138          if (isInterface) {
   139              key =  "doclet.Interface";
   140          } else if (isEnum) {
   141              key = "doclet.Enum";
   142          } else {
   143              key =  "doclet.Class";
   144          }
   145          contentTree = writer.getHeader(configuration.getText(key) + " " +
   146                  classDoc.name());
   147          Content classContentTree = writer.getClassContentHeader();
   148          buildChildren(node, classContentTree);
   149          contentTree.addContent(classContentTree);
   150          writer.addFooter(contentTree);
   151          writer.printDocument(contentTree);
   152          writer.close();
   153          copyDocFiles();
   154      }
   156      /**
   157       * Build the class tree documentation.
   158       *
   159       * @param node the XML element that specifies which components to document
   160       * @param classContentTree the content tree to which the documentation will be added
   161       */
   162     public void buildClassTree(XMLNode node, Content classContentTree) {
   163         writer.addClassTree(classContentTree);
   164     }
   166     /**
   167      * Build the class information tree documentation.
   168      *
   169      * @param node the XML element that specifies which components to document
   170      * @param classContentTree the content tree to which the documentation will be added
   171      */
   172     public void buildClassInfo(XMLNode node, Content classContentTree) {
   173         Content classInfoTree = writer.getClassInfoTreeHeader();
   174         buildChildren(node, classInfoTree);
   175         classContentTree.addContent(writer.getClassInfo(classInfoTree));
   176     }
   178     /**
   179      * Build the typeparameters of this class.
   180      *
   181      * @param node the XML element that specifies which components to document
   182      * @param classInfoTree the content tree to which the documentation will be added
   183      */
   184     public void buildTypeParamInfo(XMLNode node, Content classInfoTree) {
   185         writer.addTypeParamInfo(classInfoTree);
   186     }
   188     /**
   189      * If this is an interface, list all super interfaces.
   190      *
   191      * @param node the XML element that specifies which components to document
   192      * @param classInfoTree the content tree to which the documentation will be added
   193      */
   194     public void buildSuperInterfacesInfo(XMLNode node, Content classInfoTree) {
   195         writer.addSuperInterfacesInfo(classInfoTree);
   196     }
   198     /**
   199      * If this is a class, list all interfaces implemented by this class.
   200      *
   201      * @param node the XML element that specifies which components to document
   202      * @param classInfoTree the content tree to which the documentation will be added
   203      */
   204     public void buildImplementedInterfacesInfo(XMLNode node, Content classInfoTree) {
   205         writer.addImplementedInterfacesInfo(classInfoTree);
   206     }
   208     /**
   209      * List all the classes extend this one.
   210      *
   211      * @param node the XML element that specifies which components to document
   212      * @param classInfoTree the content tree to which the documentation will be added
   213      */
   214     public void buildSubClassInfo(XMLNode node, Content classInfoTree) {
   215         writer.addSubClassInfo(classInfoTree);
   216     }
   218     /**
   219      * List all the interfaces that extend this one.
   220      *
   221      * @param node the XML element that specifies which components to document
   222      * @param classInfoTree the content tree to which the documentation will be added
   223      */
   224     public void buildSubInterfacesInfo(XMLNode node, Content classInfoTree) {
   225         writer.addSubInterfacesInfo(classInfoTree);
   226     }
   228     /**
   229      * If this is an interface, list all classes that implement this interface.
   230      *
   231      * @param node the XML element that specifies which components to document
   232      * @param classInfoTree the content tree to which the documentation will be added
   233      */
   234     public void buildInterfaceUsageInfo(XMLNode node, Content classInfoTree) {
   235         writer.addInterfaceUsageInfo(classInfoTree);
   236     }
   238     /**
   239      * If this is an functional interface, display appropriate message.
   240      *
   241      * @param node the XML element that specifies which components to document
   242      * @param classInfoTree the content tree to which the documentation will be added
   243      */
   244     public void buildFunctionalInterfaceInfo(XMLNode node, Content classInfoTree) {
   245         writer.addFunctionalInterfaceInfo(classInfoTree);
   246     }
   248     /**
   249      * If this class is deprecated, build the appropriate information.
   250      *
   251      * @param node the XML element that specifies which components to document
   252      * @param classInfoTree the content tree to which the documentation will be added
   253      */
   254     public void buildDeprecationInfo (XMLNode node, Content classInfoTree) {
   255         writer.addClassDeprecationInfo(classInfoTree);
   256     }
   258     /**
   259      * If this is an inner class or interface, list the enclosing class or interface.
   260      *
   261      * @param node the XML element that specifies which components to document
   262      * @param classInfoTree the content tree to which the documentation will be added
   263      */
   264     public void buildNestedClassInfo (XMLNode node, Content classInfoTree) {
   265         writer.addNestedClassInfo(classInfoTree);
   266     }
   268     /**
   269      * Copy the doc files for the current ClassDoc if necessary.
   270      */
   271      private void copyDocFiles() {
   272         PackageDoc containingPackage = classDoc.containingPackage();
   273         if((configuration.packages == null ||
   274                 Arrays.binarySearch(configuration.packages,
   275                 containingPackage) < 0) &&
   276                 ! containingPackagesSeen.contains(containingPackage.name())){
   277             //Only copy doc files dir if the containing package is not
   278             //documented AND if we have not documented a class from the same
   279             //package already. Otherwise, we are making duplicate copies.
   280             Util.copyDocFiles(configuration, containingPackage);
   281             containingPackagesSeen.add(containingPackage.name());
   282         }
   283      }
   285     /**
   286      * Build the signature of the current class.
   287      *
   288      * @param node the XML element that specifies which components to document
   289      * @param classInfoTree the content tree to which the documentation will be added
   290      */
   291     public void buildClassSignature(XMLNode node, Content classInfoTree) {
   292         StringBuilder modifiers = new StringBuilder(classDoc.modifiers() + " ");
   293         if (isEnum) {
   294             modifiers.append("enum ");
   295             int index;
   296             if ((index = modifiers.indexOf("abstract")) >= 0) {
   297                 modifiers.delete(index, index + "abstract".length());
   298                 modifiers = new StringBuilder(
   299                         Util.replaceText(modifiers.toString(), "  ", " "));
   300             }
   301             if ((index = modifiers.indexOf("final")) >= 0) {
   302                 modifiers.delete(index, index + "final".length());
   303                 modifiers = new StringBuilder(
   304                         Util.replaceText(modifiers.toString(), "  ", " "));
   305             }
   306         //} else if (classDoc.isAnnotationType()) {
   307             //modifiers.append("@interface ");
   308         } else if (! isInterface) {
   309             modifiers.append("class ");
   310         }
   311         writer.addClassSignature(modifiers.toString(), classInfoTree);
   312     }
   314     /**
   315      * Build the class description.
   316      *
   317      * @param node the XML element that specifies which components to document
   318      * @param classInfoTree the content tree to which the documentation will be added
   319      */
   320     public void buildClassDescription(XMLNode node, Content classInfoTree) {
   321        writer.addClassDescription(classInfoTree);
   322     }
   324     /**
   325      * Build the tag information for the current class.
   326      *
   327      * @param node the XML element that specifies which components to document
   328      * @param classInfoTree the content tree to which the documentation will be added
   329      */
   330     public void buildClassTagInfo(XMLNode node, Content classInfoTree) {
   331        writer.addClassTagInfo(classInfoTree);
   332     }
   334     /**
   335      * Build the member summary contents of the page.
   336      *
   337      * @param node the XML element that specifies which components to document
   338      * @param classContentTree the content tree to which the documentation will be added
   339      */
   340     public void buildMemberSummary(XMLNode node, Content classContentTree) throws Exception {
   341         Content memberSummaryTree = writer.getMemberTreeHeader();
   342         configuration.getBuilderFactory().
   343                 getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree);
   344         classContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
   345     }
   347     /**
   348      * Build the member details contents of the page.
   349      *
   350      * @param node the XML element that specifies which components to document
   351      * @param classContentTree the content tree to which the documentation will be added
   352      */
   353     public void buildMemberDetails(XMLNode node, Content classContentTree) {
   354         Content memberDetailsTree = writer.getMemberTreeHeader();
   355         buildChildren(node, memberDetailsTree);
   356         classContentTree.addContent(writer.getMemberDetailsTree(memberDetailsTree));
   357     }
   359     /**
   360      * Build the enum constants documentation.
   361      *
   362      * @param node the XML element that specifies which components to document
   363      * @param memberDetailsTree the content tree to which the documentation will be added
   364      */
   365     public void buildEnumConstantsDetails(XMLNode node,
   366             Content memberDetailsTree) throws Exception {
   367         configuration.getBuilderFactory().
   368                 getEnumConstantsBuilder(writer).buildChildren(node, memberDetailsTree);
   369     }
   371     /**
   372      * Build the field documentation.
   373      *
   374      * @param node the XML element that specifies which components to document
   375      * @param memberDetailsTree the content tree to which the documentation will be added
   376      */
   377     public void buildFieldDetails(XMLNode node,
   378             Content memberDetailsTree) throws Exception {
   379         configuration.getBuilderFactory().
   380                 getFieldBuilder(writer).buildChildren(node, memberDetailsTree);
   381     }
   383     /**
   384      * Build the property documentation.
   385      *
   386      * @param elements the XML elements that specify how a field is documented.
   387      */
   388     public void buildPropertyDetails(XMLNode node,
   389             Content memberDetailsTree) throws Exception {
   390         configuration.getBuilderFactory().
   391                 getPropertyBuilder(writer).buildChildren(node, memberDetailsTree);
   392     }
   394     /**
   395      * Build the constructor documentation.
   396      *
   397      * @param node the XML element that specifies which components to document
   398      * @param memberDetailsTree the content tree to which the documentation will be added
   399      */
   400     public void buildConstructorDetails(XMLNode node,
   401             Content memberDetailsTree) throws Exception {
   402         configuration.getBuilderFactory().
   403                 getConstructorBuilder(writer).buildChildren(node, memberDetailsTree);
   404     }
   406     /**
   407      * Build the method documentation.
   408      *
   409      * @param node the XML element that specifies which components to document
   410      * @param memberDetailsTree the content tree to which the documentation will be added
   411      */
   412     public void buildMethodDetails(XMLNode node,
   413             Content memberDetailsTree) throws Exception {
   414         configuration.getBuilderFactory().
   415                 getMethodBuilder(writer).buildChildren(node, memberDetailsTree);
   416     }
   417 }

mercurial