Tue, 09 Oct 2012 19:10:00 -0700
8000663: clean up langtools imports
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 * This code is not part of an API.
39 * It is implementation that is subject to change.
40 * Do not use it as an API
41 *
42 * @author Jamie Ho
43 * @author Bhavesh Patel (Modified)
44 * @since 1.5
45 */
46 public class AnnotationTypeBuilder extends AbstractBuilder {
48 /**
49 * The root element of the annotation type XML is {@value}.
50 */
51 public static final String ROOT = "AnnotationTypeDoc";
53 /**
54 * The annotation type being documented.
55 */
56 private AnnotationTypeDoc annotationTypeDoc;
58 /**
59 * The doclet specific writer.
60 */
61 private AnnotationTypeWriter writer;
63 /**
64 * The content tree for the annotation documentation.
65 */
66 private Content contentTree;
68 /**
69 * Construct a new ClassBuilder.
70 *
71 * @param configuration the current configuration of the
72 * doclet.
73 */
74 private AnnotationTypeBuilder(Configuration configuration) {
75 super(configuration);
76 }
78 /**
79 * Construct a new ClassBuilder.
80 *
81 * @param configuration the current configuration of the doclet.
82 * @param annotationTypeDoc the class being documented.
83 * @param writer the doclet specific writer.
84 */
85 public static AnnotationTypeBuilder getInstance(Configuration configuration,
86 AnnotationTypeDoc annotationTypeDoc, AnnotationTypeWriter writer)
87 throws Exception {
88 AnnotationTypeBuilder builder = new AnnotationTypeBuilder(configuration);
89 builder.configuration = configuration;
90 builder.annotationTypeDoc = annotationTypeDoc;
91 builder.writer = writer;
92 if(containingPackagesSeen == null) {
93 containingPackagesSeen = new HashSet<String>();
94 }
95 return builder;
96 }
98 /**
99 * {@inheritDoc}
100 */
101 public void build() throws IOException {
102 build(LayoutParser.getInstance(configuration).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,
143 Util.getPackageSourcePath(configuration,
144 annotationTypeDoc.containingPackage()) +
145 DirectoryManager.getDirectoryPath(
146 annotationTypeDoc.containingPackage())
147 + File.separator, DocletConstants.DOC_FILES_DIR_NAME, true);
148 containingPackagesSeen.add(containingPackage.name());
149 }
150 }
152 /**
153 * Build the annotation information tree documentation.
154 *
155 * @param node the XML element that specifies which components to document
156 * @param annotationContentTree the content tree to which the documentation will be added
157 */
158 public void buildAnnotationTypeInfo(XMLNode node, Content annotationContentTree) {
159 Content annotationInfoTree = writer.getAnnotationInfoTreeHeader();
160 buildChildren(node, annotationInfoTree);
161 annotationContentTree.addContent(writer.getAnnotationInfo(annotationInfoTree));
162 }
164 /**
165 * If this annotation is deprecated, build the appropriate information.
166 *
167 * @param node the XML element that specifies which components to document
168 * @param annotationInfoTree the content tree to which the documentation will be added
169 */
170 public void buildDeprecationInfo (XMLNode node, Content annotationInfoTree) {
171 writer.addAnnotationTypeDeprecationInfo(annotationInfoTree);
172 }
174 /**
175 * Build the signature of the current annotation type.
176 *
177 * @param node the XML element that specifies which components to document
178 * @param annotationInfoTree the content tree to which the documentation will be added
179 */
180 public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) {
181 StringBuffer modifiers = new StringBuffer(
182 annotationTypeDoc.modifiers() + " ");
183 writer.addAnnotationTypeSignature(Util.replaceText(
184 modifiers.toString(), "interface", "@interface"), annotationInfoTree);
185 }
187 /**
188 * Build the annotation type description.
189 *
190 * @param node the XML element that specifies which components to document
191 * @param annotationInfoTree the content tree to which the documentation will be added
192 */
193 public void buildAnnotationTypeDescription(XMLNode node, Content annotationInfoTree) {
194 writer.addAnnotationTypeDescription(annotationInfoTree);
195 }
197 /**
198 * Build the tag information for the current annotation type.
199 *
200 * @param node the XML element that specifies which components to document
201 * @param annotationInfoTree the content tree to which the documentation will be added
202 */
203 public void buildAnnotationTypeTagInfo(XMLNode node, Content annotationInfoTree) {
204 writer.addAnnotationTypeTagInfo(annotationInfoTree);
205 }
207 /**
208 * Build the member summary contents of the page.
209 *
210 * @param node the XML element that specifies which components to document
211 * @param annotationContentTree the content tree to which the documentation will be added
212 */
213 public void buildMemberSummary(XMLNode node, Content annotationContentTree)
214 throws Exception {
215 Content memberSummaryTree = writer.getMemberTreeHeader();
216 configuration.getBuilderFactory().
217 getMemberSummaryBuilder(writer).buildChildren(node, memberSummaryTree);
218 annotationContentTree.addContent(writer.getMemberSummaryTree(memberSummaryTree));
219 }
221 /**
222 * Build the member details contents of the page.
223 *
224 * @param node the XML element that specifies which components to document
225 * @param annotationContentTree the content tree to which the documentation will be added
226 */
227 public void buildAnnotationTypeMemberDetails(XMLNode node, Content annotationContentTree) {
228 Content memberDetailsTree = writer.getMemberTreeHeader();
229 buildChildren(node, memberDetailsTree);
230 if (memberDetailsTree.isValid()) {
231 Content memberDetails = writer.getMemberTreeHeader();
232 writer.addAnnotationDetailsMarker(memberDetails);
233 memberDetails.addContent(writer.getMemberTree(memberDetailsTree));
234 annotationContentTree.addContent(writer.getMemberDetailsTree(memberDetails));
235 }
236 }
238 /**
239 * Build the annotation type optional member documentation.
240 *
241 * @param node the XML element that specifies which components to document
242 * @param memberDetailsTree the content tree to which the documentation will be added
243 */
244 public void buildAnnotationTypeOptionalMemberDetails(XMLNode node, Content memberDetailsTree)
245 throws Exception {
246 configuration.getBuilderFactory().
247 getAnnotationTypeOptionalMemberBuilder(writer).buildChildren(node, memberDetailsTree);
248 }
250 /**
251 * Build the annotation type required member documentation.
252 *
253 * @param node the XML element that specifies which components to document
254 * @param memberDetailsTree the content tree to which the documentation will be added
255 */
256 public void buildAnnotationTypeRequiredMemberDetails(XMLNode node, Content memberDetailsTree)
257 throws Exception {
258 configuration.getBuilderFactory().
259 getAnnotationTypeRequiredMemberBuilder(writer).buildChildren(node, memberDetailsTree);
260 }
261 }