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

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

     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         modifiers.append(modifiers.length() == 0 ? "" : " ");
   294         if (isEnum) {
   295             modifiers.append("enum ");
   296             int index;
   297             if ((index = modifiers.indexOf("abstract")) >= 0) {
   298                 modifiers.delete(index, index + "abstract".length());
   299                 modifiers = new StringBuilder(
   300                         Util.replaceText(modifiers.toString(), "  ", " "));
   301             }
   302             if ((index = modifiers.indexOf("final")) >= 0) {
   303                 modifiers.delete(index, index + "final".length());
   304                 modifiers = new StringBuilder(
   305                         Util.replaceText(modifiers.toString(), "  ", " "));
   306             }
   307         //} else if (classDoc.isAnnotationType()) {
   308             //modifiers.append("@interface ");
   309         } else if (! isInterface) {
   310             modifiers.append("class ");
   311         }
   312         writer.addClassSignature(modifiers.toString(), classInfoTree);
   313     }
   315     /**
   316      * Build the class description.
   317      *
   318      * @param node the XML element that specifies which components to document
   319      * @param classInfoTree the content tree to which the documentation will be added
   320      */
   321     public void buildClassDescription(XMLNode node, Content classInfoTree) {
   322        writer.addClassDescription(classInfoTree);
   323     }
   325     /**
   326      * Build the tag information for the current class.
   327      *
   328      * @param node the XML element that specifies which components to document
   329      * @param classInfoTree the content tree to which the documentation will be added
   330      */
   331     public void buildClassTagInfo(XMLNode node, Content classInfoTree) {
   332        writer.addClassTagInfo(classInfoTree);
   333     }
   335     /**
   336      * Build the member summary contents of the page.
   337      *
   338      * @param node the XML element that specifies which components to document
   339      * @param classContentTree the content tree to which the documentation will be added
   340      */
   341     public void buildMemberSummary(XMLNode node, Content classContentTree) throws Exception {
   342         Content memberSummaryTree = writer.getMemberTreeHeader();
   343         configuration.getBuilderFactory().
   344                 getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree);
   345         classContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
   346     }
   348     /**
   349      * Build the member details contents of the page.
   350      *
   351      * @param node the XML element that specifies which components to document
   352      * @param classContentTree the content tree to which the documentation will be added
   353      */
   354     public void buildMemberDetails(XMLNode node, Content classContentTree) {
   355         Content memberDetailsTree = writer.getMemberTreeHeader();
   356         buildChildren(node, memberDetailsTree);
   357         classContentTree.addContent(writer.getMemberDetailsTree(memberDetailsTree));
   358     }
   360     /**
   361      * Build the enum constants documentation.
   362      *
   363      * @param node the XML element that specifies which components to document
   364      * @param memberDetailsTree the content tree to which the documentation will be added
   365      */
   366     public void buildEnumConstantsDetails(XMLNode node,
   367             Content memberDetailsTree) throws Exception {
   368         configuration.getBuilderFactory().
   369                 getEnumConstantsBuilder(writer).buildChildren(node, memberDetailsTree);
   370     }
   372     /**
   373      * Build the field documentation.
   374      *
   375      * @param node the XML element that specifies which components to document
   376      * @param memberDetailsTree the content tree to which the documentation will be added
   377      */
   378     public void buildFieldDetails(XMLNode node,
   379             Content memberDetailsTree) throws Exception {
   380         configuration.getBuilderFactory().
   381                 getFieldBuilder(writer).buildChildren(node, memberDetailsTree);
   382     }
   384     /**
   385      * Build the property documentation.
   386      *
   387      * @param elements the XML elements that specify how a field is documented.
   388      */
   389     public void buildPropertyDetails(XMLNode node,
   390             Content memberDetailsTree) throws Exception {
   391         configuration.getBuilderFactory().
   392                 getPropertyBuilder(writer).buildChildren(node, memberDetailsTree);
   393     }
   395     /**
   396      * Build the constructor documentation.
   397      *
   398      * @param node the XML element that specifies which components to document
   399      * @param memberDetailsTree the content tree to which the documentation will be added
   400      */
   401     public void buildConstructorDetails(XMLNode node,
   402             Content memberDetailsTree) throws Exception {
   403         configuration.getBuilderFactory().
   404                 getConstructorBuilder(writer).buildChildren(node, memberDetailsTree);
   405     }
   407     /**
   408      * Build the method documentation.
   409      *
   410      * @param node the XML element that specifies which components to document
   411      * @param memberDetailsTree the content tree to which the documentation will be added
   412      */
   413     public void buildMethodDetails(XMLNode node,
   414             Content memberDetailsTree) throws Exception {
   415         configuration.getBuilderFactory().
   416                 getMethodBuilder(writer).buildChildren(node, memberDetailsTree);
   417     }
   418 }

mercurial