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

Wed, 10 Oct 2012 16:48:21 -0700

author
jjg
date
Wed, 10 Oct 2012 16:48:21 -0700
changeset 1359
25e14ad23cef
parent 1357
c75be5bc5283
child 1410
bfec2a1cc869
permissions
-rw-r--r--

8000665: fix "internal API" comments on javadoc files
Reviewed-by: darcy

     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.util.*;
    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 documentation for a field.
    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 FieldBuilder extends AbstractMemberBuilder {
    48     /**
    49      * The class whose fields are being documented.
    50      */
    51     private ClassDoc classDoc;
    53     /**
    54      * The visible fields for the given class.
    55      */
    56     private VisibleMemberMap visibleMemberMap;
    58     /**
    59      * The writer to output the field documentation.
    60      */
    61     private FieldWriter writer;
    63     /**
    64      * The list of fields being documented.
    65      */
    66     private List<ProgramElementDoc> fields;
    68     /**
    69      * The index of the current field that is being documented at this point
    70      * in time.
    71      */
    72     private int currentFieldIndex;
    74     /**
    75      * Construct a new FieldBuilder.
    76      *
    77      * @param configuration the current configuration of the
    78      *                      doclet.
    79      */
    80     private FieldBuilder(Configuration configuration) {
    81         super(configuration);
    82     }
    84     /**
    85      * Construct a new FieldBuilder.
    86      *
    87      * @param configuration the current configuration of the doclet.
    88      * @param classDoc the class whoses members are being documented.
    89      * @param writer the doclet specific writer.
    90      */
    91     public static FieldBuilder getInstance(
    92             Configuration configuration,
    93             ClassDoc classDoc,
    94             FieldWriter writer) {
    95         FieldBuilder builder = new FieldBuilder(configuration);
    96         builder.classDoc = classDoc;
    97         builder.writer = writer;
    98         builder.visibleMemberMap =
    99                 new VisibleMemberMap(
   100                 classDoc,
   101                 VisibleMemberMap.FIELDS,
   102                 configuration.nodeprecated);
   103         builder.fields =
   104                 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getLeafClassMembers(
   105                 configuration));
   106         if (configuration.getMemberComparator() != null) {
   107             Collections.sort(
   108                     builder.fields,
   109                     configuration.getMemberComparator());
   110         }
   111         return builder;
   112     }
   114     /**
   115      * {@inheritDoc}
   116      */
   117     public String getName() {
   118         return "FieldDetails";
   119     }
   121     /**
   122      * Returns a list of fields that will be documented for the given class.
   123      * This information can be used for doclet specific documentation
   124      * generation.
   125      *
   126      * @param classDoc the {@link ClassDoc} we want to check.
   127      * @return a list of fields that will be documented.
   128      */
   129     public List<ProgramElementDoc> members(ClassDoc classDoc) {
   130         return visibleMemberMap.getMembersFor(classDoc);
   131     }
   133     /**
   134      * Returns the visible member map for the fields of this class.
   135      *
   136      * @return the visible member map for the fields of this class.
   137      */
   138     public VisibleMemberMap getVisibleMemberMap() {
   139         return visibleMemberMap;
   140     }
   142     /**
   143      * summaryOrder.size()
   144      */
   145     public boolean hasMembersToDocument() {
   146         return fields.size() > 0;
   147     }
   149     /**
   150      * Build the field documentation.
   151      *
   152      * @param node the XML element that specifies which components to document
   153      * @param memberDetailsTree the content tree to which the documentation will be added
   154      */
   155     public void buildFieldDoc(XMLNode node, Content memberDetailsTree) {
   156         if (writer == null) {
   157             return;
   158         }
   159         int size = fields.size();
   160         if (size > 0) {
   161             Content fieldDetailsTree = writer.getFieldDetailsTreeHeader(
   162                     classDoc, memberDetailsTree);
   163             for (currentFieldIndex = 0; currentFieldIndex < size;
   164                     currentFieldIndex++) {
   165                 Content fieldDocTree = writer.getFieldDocTreeHeader(
   166                         (FieldDoc) fields.get(currentFieldIndex),
   167                         fieldDetailsTree);
   168                 buildChildren(node, fieldDocTree);
   169                 fieldDetailsTree.addContent(writer.getFieldDoc(
   170                         fieldDocTree, (currentFieldIndex == size - 1)));
   171             }
   172             memberDetailsTree.addContent(
   173                     writer.getFieldDetails(fieldDetailsTree));
   174         }
   175     }
   177     /**
   178      * Build the signature.
   179      *
   180      * @param node the XML element that specifies which components to document
   181      * @param fieldDocTree the content tree to which the documentation will be added
   182      */
   183     public void buildSignature(XMLNode node, Content fieldDocTree) {
   184         fieldDocTree.addContent(
   185                 writer.getSignature((FieldDoc) fields.get(currentFieldIndex)));
   186     }
   188     /**
   189      * Build the deprecation information.
   190      *
   191      * @param node the XML element that specifies which components to document
   192      * @param fieldDocTree the content tree to which the documentation will be added
   193      */
   194     public void buildDeprecationInfo(XMLNode node, Content fieldDocTree) {
   195         writer.addDeprecated(
   196                 (FieldDoc) fields.get(currentFieldIndex), fieldDocTree);
   197     }
   199     /**
   200      * Build the comments for the field.  Do nothing if
   201      * {@link Configuration#nocomment} is set to true.
   202      *
   203      * @param node the XML element that specifies which components to document
   204      * @param fieldDocTree the content tree to which the documentation will be added
   205      */
   206     public void buildFieldComments(XMLNode node, Content fieldDocTree) {
   207         if (!configuration.nocomment) {
   208             writer.addComments((FieldDoc) fields.get(currentFieldIndex), fieldDocTree);
   209         }
   210     }
   212     /**
   213      * Build the tag information.
   214      *
   215      * @param node the XML element that specifies which components to document
   216      * @param fieldDocTree the content tree to which the documentation will be added
   217      */
   218     public void buildTagInfo(XMLNode node, Content fieldDocTree) {
   219         writer.addTags((FieldDoc) fields.get(currentFieldIndex), fieldDocTree);
   220     }
   222     /**
   223      * Return the field writer for this builder.
   224      *
   225      * @return the field writer for this builder.
   226      */
   227     public FieldWriter getWriter() {
   228         return writer;
   229     }
   230 }

mercurial