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

Mon, 19 Nov 2012 16:10:34 -0800

author
bpatel
date
Mon, 19 Nov 2012 16:10:34 -0800
changeset 1417
522a1ee72340
parent 1410
bfec2a1cc869
child 1468
690c41cdab55
permissions
-rw-r--r--

8002304: Group methods by types in methods summary section
Reviewed-by: jjg

     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.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 class is deprecated, build the appropriate information.
   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 buildDeprecationInfo (XMLNode node, Content classInfoTree) {
   245         writer.addClassDeprecationInfo(classInfoTree);
   246     }
   248     /**
   249      * If this is an inner class or interface, list the enclosing class or interface.
   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 buildNestedClassInfo (XMLNode node, Content classInfoTree) {
   255         writer.addNestedClassInfo(classInfoTree);
   256     }
   258     /**
   259      * Copy the doc files for the current ClassDoc if necessary.
   260      */
   261      private void copyDocFiles() {
   262         PackageDoc containingPackage = classDoc.containingPackage();
   263         if((configuration.packages == null ||
   264                 Arrays.binarySearch(configuration.packages,
   265                 containingPackage) < 0) &&
   266                 ! containingPackagesSeen.contains(containingPackage.name())){
   267             //Only copy doc files dir if the containing package is not
   268             //documented AND if we have not documented a class from the same
   269             //package already. Otherwise, we are making duplicate copies.
   270             Util.copyDocFiles(configuration, containingPackage);
   271             containingPackagesSeen.add(containingPackage.name());
   272         }
   273      }
   275     /**
   276      * Build the signature of the current class.
   277      *
   278      * @param node the XML element that specifies which components to document
   279      * @param classInfoTree the content tree to which the documentation will be added
   280      */
   281     public void buildClassSignature(XMLNode node, Content classInfoTree) {
   282         StringBuilder modifiers = new StringBuilder(classDoc.modifiers() + " ");
   283         if (isEnum) {
   284             modifiers.append("enum ");
   285             int index;
   286             if ((index = modifiers.indexOf("abstract")) >= 0) {
   287                 modifiers.delete(index, index + "abstract".length());
   288                 modifiers = new StringBuilder(
   289                         Util.replaceText(modifiers.toString(), "  ", " "));
   290             }
   291             if ((index = modifiers.indexOf("final")) >= 0) {
   292                 modifiers.delete(index, index + "final".length());
   293                 modifiers = new StringBuilder(
   294                         Util.replaceText(modifiers.toString(), "  ", " "));
   295             }
   296         //} else if (classDoc.isAnnotationType()) {
   297             //modifiers.append("@interface ");
   298         } else if (! isInterface) {
   299             modifiers.append("class ");
   300         }
   301         writer.addClassSignature(modifiers.toString(), classInfoTree);
   302     }
   304     /**
   305      * Build the class description.
   306      *
   307      * @param node the XML element that specifies which components to document
   308      * @param classInfoTree the content tree to which the documentation will be added
   309      */
   310     public void buildClassDescription(XMLNode node, Content classInfoTree) {
   311        writer.addClassDescription(classInfoTree);
   312     }
   314     /**
   315      * Build the tag information for the current class.
   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 buildClassTagInfo(XMLNode node, Content classInfoTree) {
   321        writer.addClassTagInfo(classInfoTree);
   322     }
   324     /**
   325      * Build the member summary contents of the page.
   326      *
   327      * @param node the XML element that specifies which components to document
   328      * @param classContentTree the content tree to which the documentation will be added
   329      */
   330     public void buildMemberSummary(XMLNode node, Content classContentTree) throws Exception {
   331         Content memberSummaryTree = writer.getMemberTreeHeader();
   332         configuration.getBuilderFactory().
   333                 getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree);
   334         classContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
   335     }
   337     /**
   338      * Build the member details contents of the page.
   339      *
   340      * @param node the XML element that specifies which components to document
   341      * @param classContentTree the content tree to which the documentation will be added
   342      */
   343     public void buildMemberDetails(XMLNode node, Content classContentTree) {
   344         Content memberDetailsTree = writer.getMemberTreeHeader();
   345         buildChildren(node, memberDetailsTree);
   346         classContentTree.addContent(writer.getMemberDetailsTree(memberDetailsTree));
   347     }
   349     /**
   350      * Build the enum constants documentation.
   351      *
   352      * @param node the XML element that specifies which components to document
   353      * @param memberDetailsTree the content tree to which the documentation will be added
   354      */
   355     public void buildEnumConstantsDetails(XMLNode node,
   356             Content memberDetailsTree) throws Exception {
   357         configuration.getBuilderFactory().
   358                 getEnumConstantsBuilder(writer).buildChildren(node, memberDetailsTree);
   359     }
   361     /**
   362      * Build the field documentation.
   363      *
   364      * @param node the XML element that specifies which components to document
   365      * @param memberDetailsTree the content tree to which the documentation will be added
   366      */
   367     public void buildFieldDetails(XMLNode node,
   368             Content memberDetailsTree) throws Exception {
   369         configuration.getBuilderFactory().
   370                 getFieldBuilder(writer).buildChildren(node, memberDetailsTree);
   371     }
   373     /**
   374      * Build the constructor documentation.
   375      *
   376      * @param node the XML element that specifies which components to document
   377      * @param memberDetailsTree the content tree to which the documentation will be added
   378      */
   379     public void buildConstructorDetails(XMLNode node,
   380             Content memberDetailsTree) throws Exception {
   381         configuration.getBuilderFactory().
   382                 getConstructorBuilder(writer).buildChildren(node, memberDetailsTree);
   383     }
   385     /**
   386      * Build the method documentation.
   387      *
   388      * @param node the XML element that specifies which components to document
   389      * @param memberDetailsTree the content tree to which the documentation will be added
   390      */
   391     public void buildMethodDetails(XMLNode node,
   392             Content memberDetailsTree) throws Exception {
   393         configuration.getBuilderFactory().
   394                 getMethodBuilder(writer).buildChildren(node, memberDetailsTree);
   395     }
   396 }

mercurial