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

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 766
90af8d87741f
child 1357
c75be5bc5283
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

     1 /*
     2  * Copyright (c) 2003, 2010, 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.util.*;
    29 import com.sun.tools.doclets.internal.toolkit.util.*;
    30 import com.sun.tools.doclets.internal.toolkit.*;
    31 import com.sun.javadoc.*;
    33 /**
    34  * Builds documentation for a field.
    35  *
    36  * This code is not part of an API.
    37  * It is implementation that is subject to change.
    38  * Do not use it as an API
    39  *
    40  * @author Jamie Ho
    41  * @author Bhavesh Patel (Modified)
    42  * @since 1.5
    43  */
    44 public class FieldBuilder extends AbstractMemberBuilder {
    46     /**
    47      * The class whose fields are being documented.
    48      */
    49     private ClassDoc classDoc;
    51     /**
    52      * The visible fields for the given class.
    53      */
    54     private VisibleMemberMap visibleMemberMap;
    56     /**
    57      * The writer to output the field documentation.
    58      */
    59     private FieldWriter writer;
    61     /**
    62      * The list of fields being documented.
    63      */
    64     private List<ProgramElementDoc> fields;
    66     /**
    67      * The index of the current field that is being documented at this point
    68      * in time.
    69      */
    70     private int currentFieldIndex;
    72     /**
    73      * Construct a new FieldBuilder.
    74      *
    75      * @param configuration the current configuration of the
    76      *                      doclet.
    77      */
    78     private FieldBuilder(Configuration configuration) {
    79         super(configuration);
    80     }
    82     /**
    83      * Construct a new FieldBuilder.
    84      *
    85      * @param configuration the current configuration of the doclet.
    86      * @param classDoc the class whoses members are being documented.
    87      * @param writer the doclet specific writer.
    88      */
    89     public static FieldBuilder getInstance(
    90             Configuration configuration,
    91             ClassDoc classDoc,
    92             FieldWriter writer) {
    93         FieldBuilder builder = new FieldBuilder(configuration);
    94         builder.classDoc = classDoc;
    95         builder.writer = writer;
    96         builder.visibleMemberMap =
    97                 new VisibleMemberMap(
    98                 classDoc,
    99                 VisibleMemberMap.FIELDS,
   100                 configuration.nodeprecated);
   101         builder.fields =
   102                 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getLeafClassMembers(
   103                 configuration));
   104         if (configuration.getMemberComparator() != null) {
   105             Collections.sort(
   106                     builder.fields,
   107                     configuration.getMemberComparator());
   108         }
   109         return builder;
   110     }
   112     /**
   113      * {@inheritDoc}
   114      */
   115     public String getName() {
   116         return "FieldDetails";
   117     }
   119     /**
   120      * Returns a list of fields that will be documented for the given class.
   121      * This information can be used for doclet specific documentation
   122      * generation.
   123      *
   124      * @param classDoc the {@link ClassDoc} we want to check.
   125      * @return a list of fields that will be documented.
   126      */
   127     public List<ProgramElementDoc> members(ClassDoc classDoc) {
   128         return visibleMemberMap.getMembersFor(classDoc);
   129     }
   131     /**
   132      * Returns the visible member map for the fields of this class.
   133      *
   134      * @return the visible member map for the fields of this class.
   135      */
   136     public VisibleMemberMap getVisibleMemberMap() {
   137         return visibleMemberMap;
   138     }
   140     /**
   141      * summaryOrder.size()
   142      */
   143     public boolean hasMembersToDocument() {
   144         return fields.size() > 0;
   145     }
   147     /**
   148      * Build the field documentation.
   149      *
   150      * @param node the XML element that specifies which components to document
   151      * @param memberDetailsTree the content tree to which the documentation will be added
   152      */
   153     public void buildFieldDoc(XMLNode node, Content memberDetailsTree) {
   154         if (writer == null) {
   155             return;
   156         }
   157         int size = fields.size();
   158         if (size > 0) {
   159             Content fieldDetailsTree = writer.getFieldDetailsTreeHeader(
   160                     classDoc, memberDetailsTree);
   161             for (currentFieldIndex = 0; currentFieldIndex < size;
   162                     currentFieldIndex++) {
   163                 Content fieldDocTree = writer.getFieldDocTreeHeader(
   164                         (FieldDoc) fields.get(currentFieldIndex),
   165                         fieldDetailsTree);
   166                 buildChildren(node, fieldDocTree);
   167                 fieldDetailsTree.addContent(writer.getFieldDoc(
   168                         fieldDocTree, (currentFieldIndex == size - 1)));
   169             }
   170             memberDetailsTree.addContent(
   171                     writer.getFieldDetails(fieldDetailsTree));
   172         }
   173     }
   175     /**
   176      * Build the signature.
   177      *
   178      * @param node the XML element that specifies which components to document
   179      * @param fieldDocTree the content tree to which the documentation will be added
   180      */
   181     public void buildSignature(XMLNode node, Content fieldDocTree) {
   182         fieldDocTree.addContent(
   183                 writer.getSignature((FieldDoc) fields.get(currentFieldIndex)));
   184     }
   186     /**
   187      * Build the deprecation information.
   188      *
   189      * @param node the XML element that specifies which components to document
   190      * @param fieldDocTree the content tree to which the documentation will be added
   191      */
   192     public void buildDeprecationInfo(XMLNode node, Content fieldDocTree) {
   193         writer.addDeprecated(
   194                 (FieldDoc) fields.get(currentFieldIndex), fieldDocTree);
   195     }
   197     /**
   198      * Build the comments for the field.  Do nothing if
   199      * {@link Configuration#nocomment} is set to true.
   200      *
   201      * @param node the XML element that specifies which components to document
   202      * @param fieldDocTree the content tree to which the documentation will be added
   203      */
   204     public void buildFieldComments(XMLNode node, Content fieldDocTree) {
   205         if (!configuration.nocomment) {
   206             writer.addComments((FieldDoc) fields.get(currentFieldIndex), fieldDocTree);
   207         }
   208     }
   210     /**
   211      * Build the tag information.
   212      *
   213      * @param node the XML element that specifies which components to document
   214      * @param fieldDocTree the content tree to which the documentation will be added
   215      */
   216     public void buildTagInfo(XMLNode node, Content fieldDocTree) {
   217         writer.addTags((FieldDoc) fields.get(currentFieldIndex), fieldDocTree);
   218     }
   220     /**
   221      * Return the field writer for this builder.
   222      *
   223      * @return the field writer for this builder.
   224      */
   225     public FieldWriter getWriter() {
   226         return writer;
   227     }
   228 }

mercurial