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

Wed, 18 Sep 2013 17:13:26 -0700

author
bpatel
date
Wed, 18 Sep 2013 17:13:26 -0700
changeset 2035
a2a5ad0853ed
parent 1648
a03c4a86ea2b
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8015249: javadoc fails to document static final fields in annotation types
Reviewed-by: jjg

     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 annotation type.
    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 AnnotationTypeBuilder extends AbstractBuilder {
    49     /**
    50      * The root element of the annotation type XML is {@value}.
    51      */
    52     public static final String ROOT = "AnnotationTypeDoc";
    54     /**
    55      * The annotation type being documented.
    56      */
    57     private final AnnotationTypeDoc annotationTypeDoc;
    59     /**
    60      * The doclet specific writer.
    61      */
    62     private final AnnotationTypeWriter writer;
    64     /**
    65      * The content tree for the annotation documentation.
    66      */
    67     private Content contentTree;
    69     /**
    70      * Construct a new ClassBuilder.
    71      *
    72      * @param context           the build context.
    73      * @param annotationTypeDoc the class being documented.
    74      * @param writer            the doclet specific writer.
    75      */
    76     private AnnotationTypeBuilder(Context context,
    77             AnnotationTypeDoc annotationTypeDoc,
    78             AnnotationTypeWriter writer) {
    79         super(context);
    80         this.annotationTypeDoc = annotationTypeDoc;
    81         this.writer = writer;
    82     }
    84     /**
    85      * Construct a new ClassBuilder.
    86      *
    87      * @param context           the build context.
    88      * @param annotationTypeDoc the class being documented.
    89      * @param writer            the doclet specific writer.
    90      */
    91     public static AnnotationTypeBuilder getInstance(Context context,
    92             AnnotationTypeDoc annotationTypeDoc,
    93             AnnotationTypeWriter writer)
    94             throws Exception {
    95         return new AnnotationTypeBuilder(context, annotationTypeDoc, writer);
    96     }
    98     /**
    99      * {@inheritDoc}
   100      */
   101     public void build() throws IOException {
   102         build(layoutParser.parseXML(ROOT), contentTree);
   103     }
   105     /**
   106      * {@inheritDoc}
   107      */
   108     public String getName() {
   109         return ROOT;
   110     }
   112     /**
   113       * Build the annotation type documentation.
   114       *
   115       * @param node the XML element that specifies which components to document
   116       * @param contentTree the content tree to which the documentation will be added
   117       */
   118      public void buildAnnotationTypeDoc(XMLNode node, Content contentTree) throws Exception {
   119          contentTree = writer.getHeader(configuration.getText("doclet.AnnotationType") +
   120                 " " + annotationTypeDoc.name());
   121          Content annotationContentTree = writer.getAnnotationContentHeader();
   122          buildChildren(node, annotationContentTree);
   123          contentTree.addContent(annotationContentTree);
   124          writer.addFooter(contentTree);
   125          writer.printDocument(contentTree);
   126          writer.close();
   127          copyDocFiles();
   128      }
   130      /**
   131       * Copy the doc files for the current ClassDoc if necessary.
   132       */
   133      private void copyDocFiles() {
   134         PackageDoc containingPackage = annotationTypeDoc.containingPackage();
   135         if((configuration.packages == null ||
   136                 Arrays.binarySearch(configuration.packages,
   137                                     containingPackage) < 0) &&
   138            ! containingPackagesSeen.contains(containingPackage.name())){
   139             //Only copy doc files dir if the containing package is not
   140             //documented AND if we have not documented a class from the same
   141             //package already. Otherwise, we are making duplicate copies.
   142             Util.copyDocFiles(configuration, containingPackage);
   143             containingPackagesSeen.add(containingPackage.name());
   144         }
   145      }
   147     /**
   148      * Build the annotation information tree documentation.
   149      *
   150      * @param node the XML element that specifies which components to document
   151      * @param annotationContentTree the content tree to which the documentation will be added
   152      */
   153     public void buildAnnotationTypeInfo(XMLNode node, Content annotationContentTree) {
   154         Content annotationInfoTree = writer.getAnnotationInfoTreeHeader();
   155         buildChildren(node, annotationInfoTree);
   156         annotationContentTree.addContent(writer.getAnnotationInfo(annotationInfoTree));
   157     }
   159     /**
   160      * If this annotation is deprecated, build the appropriate information.
   161      *
   162      * @param node the XML element that specifies which components to document
   163      * @param annotationInfoTree the content tree to which the documentation will be added
   164      */
   165     public void buildDeprecationInfo (XMLNode node, Content annotationInfoTree) {
   166         writer.addAnnotationTypeDeprecationInfo(annotationInfoTree);
   167     }
   169     /**
   170      * Build the signature of the current annotation type.
   171      *
   172      * @param node the XML element that specifies which components to document
   173      * @param annotationInfoTree the content tree to which the documentation will be added
   174      */
   175     public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) {
   176         StringBuilder modifiers = new StringBuilder(
   177                 annotationTypeDoc.modifiers() + " ");
   178         writer.addAnnotationTypeSignature(Util.replaceText(
   179                 modifiers.toString(), "interface", "@interface"), annotationInfoTree);
   180     }
   182     /**
   183      * Build the annotation type description.
   184      *
   185      * @param node the XML element that specifies which components to document
   186      * @param annotationInfoTree the content tree to which the documentation will be added
   187      */
   188     public void buildAnnotationTypeDescription(XMLNode node, Content annotationInfoTree) {
   189         writer.addAnnotationTypeDescription(annotationInfoTree);
   190     }
   192     /**
   193      * Build the tag information for the current annotation type.
   194      *
   195      * @param node the XML element that specifies which components to document
   196      * @param annotationInfoTree the content tree to which the documentation will be added
   197      */
   198     public void buildAnnotationTypeTagInfo(XMLNode node, Content annotationInfoTree) {
   199         writer.addAnnotationTypeTagInfo(annotationInfoTree);
   200     }
   202     /**
   203      * Build the member summary contents of the page.
   204      *
   205      * @param node the XML element that specifies which components to document
   206      * @param annotationContentTree the content tree to which the documentation will be added
   207      */
   208     public void buildMemberSummary(XMLNode node, Content annotationContentTree)
   209             throws Exception {
   210         Content memberSummaryTree = writer.getMemberTreeHeader();
   211         configuration.getBuilderFactory().
   212                 getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree);
   213         annotationContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
   214     }
   216     /**
   217      * Build the member details contents of the page.
   218      *
   219      * @param node the XML element that specifies which components to document
   220      * @param annotationContentTree the content tree to which the documentation will be added
   221      */
   222     public void buildAnnotationTypeMemberDetails(XMLNode node, Content annotationContentTree) {
   223         Content memberDetailsTree = writer.getMemberTreeHeader();
   224         buildChildren(node, memberDetailsTree);
   225         if (memberDetailsTree.isValid()) {
   226             annotationContentTree.addContent(writer.getMemberDetailsTree(memberDetailsTree));
   227         }
   228     }
   230     /**
   231      * Build the annotation type field documentation.
   232      *
   233      * @param node the XML element that specifies which components to document
   234      * @param memberDetailsTree the content tree to which the documentation will be added
   235      */
   236     public void buildAnnotationTypeFieldDetails(XMLNode node, Content memberDetailsTree)
   237             throws Exception {
   238         configuration.getBuilderFactory().
   239                 getAnnotationTypeFieldsBuilder(writer).buildChildren(node, memberDetailsTree);
   240     }
   242     /**
   243      * Build the annotation type optional member documentation.
   244      *
   245      * @param node the XML element that specifies which components to document
   246      * @param memberDetailsTree the content tree to which the documentation will be added
   247      */
   248     public void buildAnnotationTypeOptionalMemberDetails(XMLNode node, Content memberDetailsTree)
   249             throws Exception {
   250         configuration.getBuilderFactory().
   251                 getAnnotationTypeOptionalMemberBuilder(writer).buildChildren(node, memberDetailsTree);
   252     }
   254     /**
   255      * Build the annotation type required member documentation.
   256      *
   257      * @param node the XML element that specifies which components to document
   258      * @param memberDetailsTree the content tree to which the documentation will be added
   259      */
   260     public void buildAnnotationTypeRequiredMemberDetails(XMLNode node, Content memberDetailsTree)
   261             throws Exception {
   262         configuration.getBuilderFactory().
   263                 getAnnotationTypeRequiredMemberBuilder(writer).buildChildren(node, memberDetailsTree);
   264     }
   265 }

mercurial