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