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

Thu, 15 Nov 2012 09:18:36 -0800

author
jjg
date
Thu, 15 Nov 2012 09:18:36 -0800
changeset 1410
bfec2a1cc869
parent 1359
25e14ad23cef
child 1606
ccbe7ffdd867
permissions
-rw-r--r--

8000800: javadoc uses static non-final fields
Reviewed-by: bpatel

     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 required annotation type members.
    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 AnnotationTypeRequiredMemberBuilder extends AbstractMemberBuilder {
    48     /**
    49      * The annotation type whose members are being documented.
    50      */
    51     protected ClassDoc classDoc;
    53     /**
    54      * The visible members for the given class.
    55      */
    56     protected VisibleMemberMap visibleMemberMap;
    58     /**
    59      * The writer to output the member documentation.
    60      */
    61     protected AnnotationTypeRequiredMemberWriter writer;
    63     /**
    64      * The list of members being documented.
    65      */
    66     protected List<ProgramElementDoc> members;
    68     /**
    69      * The index of the current member that is being documented at this point
    70      * in time.
    71      */
    72     protected int currentMemberIndex;
    74     /**
    75      * Construct a new AnnotationTypeRequiredMemberBuilder.
    76      *
    77      * @param context  the build context.
    78      * @param classDoc the class whose members are being documented.
    79      * @param writer the doclet specific writer.
    80      */
    81     protected AnnotationTypeRequiredMemberBuilder(Context context,
    82             ClassDoc classDoc,
    83             AnnotationTypeRequiredMemberWriter writer,
    84             int memberType) {
    85         super(context);
    86         this.classDoc = classDoc;
    87         this.writer = writer;
    88         this.visibleMemberMap = new VisibleMemberMap(classDoc, memberType,
    89             configuration.nodeprecated);
    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 AnnotationTypeMemberBuilder.
   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 AnnotationTypeRequiredMemberBuilder getInstance(
   106             Context context, ClassDoc classDoc,
   107             AnnotationTypeRequiredMemberWriter writer) {
   108         return new AnnotationTypeRequiredMemberBuilder(context, classDoc,
   109                     writer,
   110                     VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED);
   111     }
   113     /**
   114      * {@inheritDoc}
   115      */
   116     public String getName() {
   117         return "AnnotationTypeRequiredMemberDetails";
   118     }
   120     /**
   121      * Returns a list of members that will be documented for the given class.
   122      * This information can be used for doclet specific documentation
   123      * generation.
   124      *
   125      * @param classDoc the {@link ClassDoc} we want to check.
   126      * @return a list of members that will be documented.
   127      */
   128     public List<ProgramElementDoc> members(ClassDoc classDoc) {
   129         return visibleMemberMap.getMembersFor(classDoc);
   130     }
   132     /**
   133      * Returns the visible member map for the members of this class.
   134      *
   135      * @return the visible member map for the members of this class.
   136      */
   137     public VisibleMemberMap getVisibleMemberMap() {
   138         return visibleMemberMap;
   139     }
   141     /**
   142      * summaryOrder.size()
   143      */
   144     public boolean hasMembersToDocument() {
   145         return members.size() > 0;
   146     }
   148     /**
   149      * Build the annotation type required member documentation.
   150      *
   151      * @param node the XML element that specifies which components to document
   152      * @param memberDetailsTree the content tree to which the documentation will be added
   153      */
   154     public void buildAnnotationTypeRequiredMember(XMLNode node, Content memberDetailsTree) {
   155         buildAnnotationTypeMember(node, memberDetailsTree);
   156     }
   158     /**
   159      * Build the member documentation.
   160      *
   161      * @param node the XML element that specifies which components to document
   162      * @param memberDetailsTree the content tree to which the documentation will be added
   163      */
   164     public void buildAnnotationTypeMember(XMLNode node, Content memberDetailsTree) {
   165         if (writer == null) {
   166             return;
   167         }
   168         int size = members.size();
   169         if (size > 0) {
   170             writer.addAnnotationDetailsTreeHeader(
   171                     classDoc, memberDetailsTree);
   172             for (currentMemberIndex = 0; currentMemberIndex < size;
   173             currentMemberIndex++) {
   174                 Content annotationDocTree = writer.getAnnotationDocTreeHeader(
   175                         (MemberDoc) members.get(currentMemberIndex),
   176                         memberDetailsTree);
   177                 buildChildren(node, annotationDocTree);
   178                 memberDetailsTree.addContent(writer.getAnnotationDoc(
   179                         annotationDocTree, (currentMemberIndex == size - 1)));
   180             }
   181         }
   182     }
   184     /**
   185      * Build the signature.
   186      *
   187      * @param node the XML element that specifies which components to document
   188      * @param annotationDocTree the content tree to which the documentation will be added
   189      */
   190     public void buildSignature(XMLNode node, Content annotationDocTree) {
   191         annotationDocTree.addContent(
   192                 writer.getSignature((MemberDoc) members.get(currentMemberIndex)));
   193     }
   195     /**
   196      * Build the deprecation information.
   197      *
   198      * @param node the XML element that specifies which components to document
   199      * @param annotationDocTree the content tree to which the documentation will be added
   200      */
   201     public void buildDeprecationInfo(XMLNode node, Content annotationDocTree) {
   202         writer.addDeprecated((MemberDoc) members.get(currentMemberIndex),
   203                 annotationDocTree);
   204     }
   206     /**
   207      * Build the comments for the member.  Do nothing if
   208      * {@link Configuration#nocomment} is set to true.
   209      *
   210      * @param node the XML element that specifies which components to document
   211      * @param annotationDocTree the content tree to which the documentation will be added
   212      */
   213     public void buildMemberComments(XMLNode node, Content annotationDocTree) {
   214         if(! configuration.nocomment){
   215             writer.addComments((MemberDoc) members.get(currentMemberIndex),
   216                     annotationDocTree);
   217         }
   218     }
   220     /**
   221      * Build the tag information.
   222      *
   223      * @param node the XML element that specifies which components to document
   224      * @param annotationDocTree the content tree to which the documentation will be added
   225      */
   226     public void buildTagInfo(XMLNode node, Content annotationDocTree) {
   227         writer.addTags((MemberDoc) members.get(currentMemberIndex),
   228                 annotationDocTree);
   229     }
   231     /**
   232      * Return the annotation type required member writer for this builder.
   233      *
   234      * @return the annotation type required member constant writer for this
   235      * builder.
   236      */
   237     public AnnotationTypeRequiredMemberWriter getWriter() {
   238         return writer;
   239     }
   240 }

mercurial