src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/AnnotationTypeBuilder.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.io.*;
    29 import java.util.*;
    30 import com.sun.tools.doclets.internal.toolkit.util.*;
    31 import com.sun.tools.doclets.internal.toolkit.*;
    32 import com.sun.javadoc.*;
    34 /**
    35  * Builds the summary for a given annotation type.
    36  *
    37  * This code is not part of an API.
    38  * It is implementation that is subject to change.
    39  * Do not use it as an API
    40  *
    41  * @author Jamie Ho
    42  * @author Bhavesh Patel (Modified)
    43  * @since 1.5
    44  */
    45 public class AnnotationTypeBuilder extends AbstractBuilder {
    47     /**
    48      * The root element of the annotation type XML is {@value}.
    49      */
    50     public static final String ROOT = "AnnotationTypeDoc";
    52     /**
    53      * The annotation type being documented.
    54      */
    55     private AnnotationTypeDoc annotationTypeDoc;
    57     /**
    58      * The doclet specific writer.
    59      */
    60     private AnnotationTypeWriter writer;
    62     /**
    63      * The content tree for the annotation documentation.
    64      */
    65     private Content contentTree;
    67     /**
    68      * Construct a new ClassBuilder.
    69      *
    70      * @param configuration the current configuration of the
    71      *                      doclet.
    72      */
    73     private AnnotationTypeBuilder(Configuration configuration) {
    74         super(configuration);
    75     }
    77     /**
    78      * Construct a new ClassBuilder.
    79      *
    80      * @param configuration     the current configuration of the doclet.
    81      * @param annotationTypeDoc the class being documented.
    82      * @param writer            the doclet specific writer.
    83      */
    84     public static AnnotationTypeBuilder getInstance(Configuration configuration,
    85         AnnotationTypeDoc annotationTypeDoc, AnnotationTypeWriter writer)
    86     throws Exception {
    87         AnnotationTypeBuilder builder = new AnnotationTypeBuilder(configuration);
    88         builder.configuration = configuration;
    89         builder.annotationTypeDoc = annotationTypeDoc;
    90         builder.writer = writer;
    91         if(containingPackagesSeen == null) {
    92             containingPackagesSeen = new HashSet<String>();
    93         }
    94         return builder;
    95     }
    97     /**
    98      * {@inheritDoc}
    99      */
   100     public void build() throws IOException {
   101         build(LayoutParser.getInstance(configuration).parseXML(ROOT), contentTree);
   102     }
   104     /**
   105      * {@inheritDoc}
   106      */
   107     public String getName() {
   108         return ROOT;
   109     }
   111     /**
   112       * Build the annotation type documentation.
   113       *
   114       * @param node the XML element that specifies which components to document
   115       * @param contentTree the content tree to which the documentation will be added
   116       */
   117      public void buildAnnotationTypeDoc(XMLNode node, Content contentTree) throws Exception {
   118         contentTree = writer.getHeader(configuration.getText("doclet.AnnotationType") +
   119                 " " + annotationTypeDoc.name());
   120         Content annotationContentTree = writer.getAnnotationContentHeader();
   121          buildChildren(node, annotationContentTree);
   122          contentTree.addContent(annotationContentTree);
   123          writer.addFooter(contentTree);
   124          writer.printDocument(contentTree);
   125          writer.close();
   126          copyDocFiles();
   127      }
   129      /**
   130       * Copy the doc files for the current ClassDoc if necessary.
   131       */
   132      private void copyDocFiles() {
   133         PackageDoc containingPackage = annotationTypeDoc.containingPackage();
   134         if((configuration.packages == null ||
   135                 Arrays.binarySearch(configuration.packages,
   136                                     containingPackage) < 0) &&
   137            ! containingPackagesSeen.contains(containingPackage.name())){
   138             //Only copy doc files dir if the containing package is not
   139             //documented AND if we have not documented a class from the same
   140             //package already. Otherwise, we are making duplicate copies.
   141             Util.copyDocFiles(configuration,
   142                 Util.getPackageSourcePath(configuration,
   143                     annotationTypeDoc.containingPackage()) +
   144                 DirectoryManager.getDirectoryPath(
   145                     annotationTypeDoc.containingPackage())
   146                     + File.separator, DocletConstants.DOC_FILES_DIR_NAME, true);
   147             containingPackagesSeen.add(containingPackage.name());
   148         }
   149      }
   151     /**
   152      * Build the annotation information tree documentation.
   153      *
   154      * @param node the XML element that specifies which components to document
   155      * @param annotationContentTree the content tree to which the documentation will be added
   156      */
   157     public void buildAnnotationTypeInfo(XMLNode node, Content annotationContentTree) {
   158         Content annotationInfoTree = writer.getAnnotationInfoTreeHeader();
   159         buildChildren(node, annotationInfoTree);
   160         annotationContentTree.addContent(writer.getAnnotationInfo(annotationInfoTree));
   161     }
   163     /**
   164      * If this annotation is deprecated, build the appropriate information.
   165      *
   166      * @param node the XML element that specifies which components to document
   167      * @param annotationInfoTree the content tree to which the documentation will be added
   168      */
   169     public void buildDeprecationInfo (XMLNode node, Content annotationInfoTree) {
   170         writer.addAnnotationTypeDeprecationInfo(annotationInfoTree);
   171     }
   173     /**
   174      * Build the signature of the current annotation type.
   175      *
   176      * @param node the XML element that specifies which components to document
   177      * @param annotationInfoTree the content tree to which the documentation will be added
   178      */
   179     public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) {
   180         StringBuffer modifiers = new StringBuffer(
   181                 annotationTypeDoc.modifiers() + " ");
   182         writer.addAnnotationTypeSignature(Util.replaceText(
   183                 modifiers.toString(), "interface", "@interface"), annotationInfoTree);
   184     }
   186     /**
   187      * Build the annotation type description.
   188      *
   189      * @param node the XML element that specifies which components to document
   190      * @param annotationInfoTree the content tree to which the documentation will be added
   191      */
   192     public void buildAnnotationTypeDescription(XMLNode node, Content annotationInfoTree) {
   193         writer.addAnnotationTypeDescription(annotationInfoTree);
   194     }
   196     /**
   197      * Build the tag information for the current annotation type.
   198      *
   199      * @param node the XML element that specifies which components to document
   200      * @param annotationInfoTree the content tree to which the documentation will be added
   201      */
   202     public void buildAnnotationTypeTagInfo(XMLNode node, Content annotationInfoTree) {
   203         writer.addAnnotationTypeTagInfo(annotationInfoTree);
   204     }
   206     /**
   207      * Build the member summary contents of the page.
   208      *
   209      * @param node the XML element that specifies which components to document
   210      * @param annotationContentTree the content tree to which the documentation will be added
   211      */
   212     public void buildMemberSummary(XMLNode node, Content annotationContentTree)
   213             throws Exception {
   214         Content memberSummaryTree = writer.getMemberTreeHeader();
   215         configuration.getBuilderFactory().
   216                 getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree);
   217         annotationContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
   218     }
   220     /**
   221      * Build the member details contents of the page.
   222      *
   223      * @param node the XML element that specifies which components to document
   224      * @param annotationContentTree the content tree to which the documentation will be added
   225      */
   226     public void buildAnnotationTypeMemberDetails(XMLNode node, Content annotationContentTree) {
   227         Content memberDetailsTree = writer.getMemberTreeHeader();
   228         buildChildren(node, memberDetailsTree);
   229         if (memberDetailsTree.isValid()) {
   230             Content memberDetails = writer.getMemberTreeHeader();
   231             writer.addAnnotationDetailsMarker(memberDetails);
   232             memberDetails.addContent(writer.getMemberTree(memberDetailsTree));
   233             annotationContentTree.addContent(writer.getMemberDetailsTree(memberDetails));
   234         }
   235     }
   237     /**
   238      * Build the annotation type optional member documentation.
   239      *
   240      * @param node the XML element that specifies which components to document
   241      * @param memberDetailsTree the content tree to which the documentation will be added
   242      */
   243     public void buildAnnotationTypeOptionalMemberDetails(XMLNode node, Content memberDetailsTree)
   244             throws Exception {
   245         configuration.getBuilderFactory().
   246                 getAnnotationTypeOptionalMemberBuilder(writer).buildChildren(node, memberDetailsTree);
   247     }
   249     /**
   250      * Build the annotation type required member documentation.
   251      *
   252      * @param node the XML element that specifies which components to document
   253      * @param memberDetailsTree the content tree to which the documentation will be added
   254      */
   255     public void buildAnnotationTypeRequiredMemberDetails(XMLNode node, Content memberDetailsTree)
   256             throws Exception {
   257         configuration.getBuilderFactory().
   258                 getAnnotationTypeRequiredMemberBuilder(writer).buildChildren(node, memberDetailsTree);
   259     }
   260 }

mercurial