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

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

     1 /*
     2  * Copyright (c) 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.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 annotation type fields.
    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 Bhavesh Patel
    43  * @since 1.8
    44  */
    45 public class AnnotationTypeFieldBuilder extends AbstractMemberBuilder {
    47     /**
    48      * The annotation type whose members are being documented.
    49      */
    50     protected ClassDoc classDoc;
    52     /**
    53      * The visible members for the given class.
    54      */
    55     protected VisibleMemberMap visibleMemberMap;
    57     /**
    58      * The writer to output the member documentation.
    59      */
    60     protected AnnotationTypeFieldWriter writer;
    62     /**
    63      * The list of members being documented.
    64      */
    65     protected List<ProgramElementDoc> members;
    67     /**
    68      * The index of the current member that is being documented at this point
    69      * in time.
    70      */
    71     protected int currentMemberIndex;
    73     /**
    74      * Construct a new AnnotationTypeFieldsBuilder.
    75      *
    76      * @param context  the build context.
    77      * @param classDoc the class whose members are being documented.
    78      * @param writer the doclet specific writer.
    79      * @param memberType the type of member that is being documented.
    80      */
    81     protected AnnotationTypeFieldBuilder(Context context,
    82             ClassDoc classDoc,
    83             AnnotationTypeFieldWriter writer,
    84             int memberType) {
    85         super(context);
    86         this.classDoc = classDoc;
    87         this.writer = writer;
    88         this.visibleMemberMap = new VisibleMemberMap(classDoc, memberType,
    89             configuration);
    90         this.members = new ArrayList<ProgramElementDoc>(
    91             this.visibleMemberMap.getMembersFor(classDoc));
    92         if (configuration.getMemberComparator() != null) {
    93             Collections.sort(this.members, configuration.getMemberComparator());
    94         }
    95     }
    98     /**
    99      * Construct a new AnnotationTypeFieldBuilder.
   100      *
   101      * @param context  the build context.
   102      * @param classDoc the class whose members are being documented.
   103      * @param writer the doclet specific writer.
   104      */
   105     public static AnnotationTypeFieldBuilder getInstance(
   106             Context context, ClassDoc classDoc,
   107             AnnotationTypeFieldWriter writer) {
   108         return new AnnotationTypeFieldBuilder(context, classDoc,
   109                     writer, VisibleMemberMap.ANNOTATION_TYPE_FIELDS);
   110     }
   112     /**
   113      * {@inheritDoc}
   114      */
   115     public String getName() {
   116         return "AnnotationTypeFieldDetails";
   117     }
   119     /**
   120      * Returns a list of members 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 members 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 members of this class.
   133      *
   134      * @return the visible member map for the members of this class.
   135      */
   136     public VisibleMemberMap getVisibleMemberMap() {
   137         return visibleMemberMap;
   138     }
   140     /**
   141      * summaryOrder.size()
   142      */
   143     public boolean hasMembersToDocument() {
   144         return members.size() > 0;
   145     }
   147     /**
   148      * Build the annotation type 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 buildAnnotationTypeField(XMLNode node, Content memberDetailsTree) {
   154         buildAnnotationTypeMember(node, memberDetailsTree);
   155     }
   157     /**
   158      * Build the member documentation.
   159      *
   160      * @param node the XML element that specifies which components to document
   161      * @param memberDetailsTree the content tree to which the documentation will be added
   162      */
   163     public void buildAnnotationTypeMember(XMLNode node, Content memberDetailsTree) {
   164         if (writer == null) {
   165             return;
   166         }
   167         int size = members.size();
   168         if (size > 0) {
   169             writer.addAnnotationFieldDetailsMarker(memberDetailsTree);
   170             for (currentMemberIndex = 0; currentMemberIndex < size;
   171                     currentMemberIndex++) {
   172                 Content detailsTree = writer.getMemberTreeHeader();
   173                 writer.addAnnotationDetailsTreeHeader(classDoc, detailsTree);
   174                 Content annotationDocTree = writer.getAnnotationDocTreeHeader(
   175                         (MemberDoc) members.get(currentMemberIndex),
   176                         detailsTree);
   177                 buildChildren(node, annotationDocTree);
   178                 detailsTree.addContent(writer.getAnnotationDoc(
   179                         annotationDocTree, (currentMemberIndex == size - 1)));
   180                 memberDetailsTree.addContent(writer.getAnnotationDetails(detailsTree));
   181             }
   182         }
   183     }
   185     /**
   186      * Build the signature.
   187      *
   188      * @param node the XML element that specifies which components to document
   189      * @param annotationDocTree the content tree to which the documentation will be added
   190      */
   191     public void buildSignature(XMLNode node, Content annotationDocTree) {
   192         annotationDocTree.addContent(
   193                 writer.getSignature((MemberDoc) members.get(currentMemberIndex)));
   194     }
   196     /**
   197      * Build the deprecation information.
   198      *
   199      * @param node the XML element that specifies which components to document
   200      * @param annotationDocTree the content tree to which the documentation will be added
   201      */
   202     public void buildDeprecationInfo(XMLNode node, Content annotationDocTree) {
   203         writer.addDeprecated((MemberDoc) members.get(currentMemberIndex),
   204                 annotationDocTree);
   205     }
   207     /**
   208      * Build the comments for the member.  Do nothing if
   209      * {@link Configuration#nocomment} is set to true.
   210      *
   211      * @param node the XML element that specifies which components to document
   212      * @param annotationDocTree the content tree to which the documentation will be added
   213      */
   214     public void buildMemberComments(XMLNode node, Content annotationDocTree) {
   215         if(! configuration.nocomment){
   216             writer.addComments((MemberDoc) members.get(currentMemberIndex),
   217                     annotationDocTree);
   218         }
   219     }
   221     /**
   222      * Build the tag information.
   223      *
   224      * @param node the XML element that specifies which components to document
   225      * @param annotationDocTree the content tree to which the documentation will be added
   226      */
   227     public void buildTagInfo(XMLNode node, Content annotationDocTree) {
   228         writer.addTags((MemberDoc) members.get(currentMemberIndex),
   229                 annotationDocTree);
   230     }
   232     /**
   233      * Return the annotation type field writer for this builder.
   234      *
   235      * @return the annotation type field writer for this builder.
   236      */
   237     public AnnotationTypeFieldWriter getWriter() {
   238         return writer;
   239     }
   240 }

mercurial