Wed, 31 Oct 2012 13:48:15 -0700
8001664: refactor javadoc to use abstraction to handle files
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, containingPackage);
144 containingPackagesSeen.add(containingPackage.name());
145 }
146 }
148 /**
149 * Build the annotation information tree documentation.
150 *
151 * @param node the XML element that specifies which components to document
152 * @param annotationContentTree the content tree to which the documentation will be added
153 */
154 public void buildAnnotationTypeInfo(XMLNode node, Content annotationContentTree) {
155 Content annotationInfoTree = writer.getAnnotationInfoTreeHeader();
156 buildChildren(node, annotationInfoTree);
157 annotationContentTree.addContent(writer.getAnnotationInfo(annotationInfoTree));
158 }
160 /**
161 * If this annotation is deprecated, build the appropriate information.
162 *
163 * @param node the XML element that specifies which components to document
164 * @param annotationInfoTree the content tree to which the documentation will be added
165 */
166 public void buildDeprecationInfo (XMLNode node, Content annotationInfoTree) {
167 writer.addAnnotationTypeDeprecationInfo(annotationInfoTree);
168 }
170 /**
171 * Build the signature of the current annotation type.
172 *
173 * @param node the XML element that specifies which components to document
174 * @param annotationInfoTree the content tree to which the documentation will be added
175 */
176 public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) {
177 StringBuilder modifiers = new StringBuilder(
178 annotationTypeDoc.modifiers() + " ");
179 writer.addAnnotationTypeSignature(Util.replaceText(
180 modifiers.toString(), "interface", "@interface"), annotationInfoTree);
181 }
183 /**
184 * Build the annotation type description.
185 *
186 * @param node the XML element that specifies which components to document
187 * @param annotationInfoTree the content tree to which the documentation will be added
188 */
189 public void buildAnnotationTypeDescription(XMLNode node, Content annotationInfoTree) {
190 writer.addAnnotationTypeDescription(annotationInfoTree);
191 }
193 /**
194 * Build the tag information for the current annotation type.
195 *
196 * @param node the XML element that specifies which components to document
197 * @param annotationInfoTree the content tree to which the documentation will be added
198 */
199 public void buildAnnotationTypeTagInfo(XMLNode node, Content annotationInfoTree) {
200 writer.addAnnotationTypeTagInfo(annotationInfoTree);
201 }
203 /**
204 * Build the member summary contents of the page.
205 *
206 * @param node the XML element that specifies which components to document
207 * @param annotationContentTree the content tree to which the documentation will be added
208 */
209 public void buildMemberSummary(XMLNode node, Content annotationContentTree)
210 throws Exception {
211 Content memberSummaryTree = writer.getMemberTreeHeader();
212 configuration.getBuilderFactory().
213 getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree);
214 annotationContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
215 }
217 /**
218 * Build the member details contents of the page.
219 *
220 * @param node the XML element that specifies which components to document
221 * @param annotationContentTree the content tree to which the documentation will be added
222 */
223 public void buildAnnotationTypeMemberDetails(XMLNode node, Content annotationContentTree) {
224 Content memberDetailsTree = writer.getMemberTreeHeader();
225 buildChildren(node, memberDetailsTree);
226 if (memberDetailsTree.isValid()) {
227 Content memberDetails = writer.getMemberTreeHeader();
228 writer.addAnnotationDetailsMarker(memberDetails);
229 memberDetails.addContent(writer.getMemberTree(memberDetailsTree));
230 annotationContentTree.addContent(writer.getMemberDetailsTree(memberDetails));
231 }
232 }
234 /**
235 * Build the annotation type optional member documentation.
236 *
237 * @param node the XML element that specifies which components to document
238 * @param memberDetailsTree the content tree to which the documentation will be added
239 */
240 public void buildAnnotationTypeOptionalMemberDetails(XMLNode node, Content memberDetailsTree)
241 throws Exception {
242 configuration.getBuilderFactory().
243 getAnnotationTypeOptionalMemberBuilder(writer).buildChildren(node, memberDetailsTree);
244 }
246 /**
247 * Build the annotation type required member documentation.
248 *
249 * @param node the XML element that specifies which components to document
250 * @param memberDetailsTree the content tree to which the documentation will be added
251 */
252 public void buildAnnotationTypeRequiredMemberDetails(XMLNode node, Content memberDetailsTree)
253 throws Exception {
254 configuration.getBuilderFactory().
255 getAnnotationTypeRequiredMemberBuilder(writer).buildChildren(node, memberDetailsTree);
256 }
257 }