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

Tue, 23 Oct 2012 13:20:37 -0700

author
jjg
date
Tue, 23 Oct 2012 13:20:37 -0700
changeset 1372
78962d89f283
parent 1362
c46e0c9940d6
child 1383
b980e8e6aabf
permissions
-rw-r--r--

8000741: refactor javadoc to use abstraction to handle relative paths
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.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 AnnotationTypeDoc annotationTypeDoc;
    59     /**
    60      * The doclet specific writer.
    61      */
    62     private 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 configuration the current configuration of the
    73      *                      doclet.
    74      */
    75     private AnnotationTypeBuilder(Configuration configuration) {
    76         super(configuration);
    77     }
    79     /**
    80      * Construct a new ClassBuilder.
    81      *
    82      * @param configuration     the current configuration of the doclet.
    83      * @param annotationTypeDoc the class being documented.
    84      * @param writer            the doclet specific writer.
    85      */
    86     public static AnnotationTypeBuilder getInstance(Configuration configuration,
    87         AnnotationTypeDoc annotationTypeDoc, AnnotationTypeWriter writer)
    88     throws Exception {
    89         AnnotationTypeBuilder builder = new AnnotationTypeBuilder(configuration);
    90         builder.configuration = configuration;
    91         builder.annotationTypeDoc = annotationTypeDoc;
    92         builder.writer = writer;
    93         if(containingPackagesSeen == null) {
    94             containingPackagesSeen = new HashSet<String>();
    95         }
    96         return builder;
    97     }
    99     /**
   100      * {@inheritDoc}
   101      */
   102     public void build() throws IOException {
   103         build(LayoutParser.getInstance(configuration).parseXML(ROOT), contentTree);
   104     }
   106     /**
   107      * {@inheritDoc}
   108      */
   109     public String getName() {
   110         return ROOT;
   111     }
   113     /**
   114       * Build the annotation type documentation.
   115       *
   116       * @param node the XML element that specifies which components to document
   117       * @param contentTree the content tree to which the documentation will be added
   118       */
   119      public void buildAnnotationTypeDoc(XMLNode node, Content contentTree) throws Exception {
   120         contentTree = writer.getHeader(configuration.getText("doclet.AnnotationType") +
   121                 " " + annotationTypeDoc.name());
   122         Content annotationContentTree = writer.getAnnotationContentHeader();
   123          buildChildren(node, annotationContentTree);
   124          contentTree.addContent(annotationContentTree);
   125          writer.addFooter(contentTree);
   126          writer.printDocument(contentTree);
   127          writer.close();
   128          copyDocFiles();
   129      }
   131      /**
   132       * Copy the doc files for the current ClassDoc if necessary.
   133       */
   134      private void copyDocFiles() {
   135         PackageDoc containingPackage = annotationTypeDoc.containingPackage();
   136         if((configuration.packages == null ||
   137                 Arrays.binarySearch(configuration.packages,
   138                                     containingPackage) < 0) &&
   139            ! containingPackagesSeen.contains(containingPackage.name())){
   140             //Only copy doc files dir if the containing package is not
   141             //documented AND if we have not documented a class from the same
   142             //package already. Otherwise, we are making duplicate copies.
   143             Util.copyDocFiles(configuration,
   144                 new File(Util.getPackageSourcePath(configuration, containingPackage),
   145                     DocPath.forPackage(annotationTypeDoc).getPath()),
   146                 DocPaths.DOC_FILES, 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         StringBuilder modifiers = new StringBuilder(
   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