Wed, 01 Dec 2010 11:02:38 -0800
6851834: Javadoc doclet needs a structured approach to generate the output HTML.
Reviewed-by: jjg
1 /*
2 * Copyright (c) 2003, 2008, 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.util.*;
29 import com.sun.tools.doclets.internal.toolkit.util.*;
30 import com.sun.tools.doclets.internal.toolkit.*;
31 import com.sun.javadoc.*;
33 /**
34 * Builds documentation for required annotation type members.
35 *
36 * This code is not part of an API.
37 * It is implementation that is subject to change.
38 * Do not use it as an API
39 *
40 * @author Jamie Ho
41 * @author Bhavesh Patel (Modified)
42 * @since 1.5
43 */
44 public class AnnotationTypeRequiredMemberBuilder extends AbstractMemberBuilder {
46 /**
47 * The annotation type whose members are being documented.
48 */
49 protected ClassDoc classDoc;
51 /**
52 * The visible members for the given class.
53 */
54 protected VisibleMemberMap visibleMemberMap;
56 /**
57 * The writer to output the member documentation.
58 */
59 protected AnnotationTypeRequiredMemberWriter writer;
61 /**
62 * The list of members being documented.
63 */
64 protected List<ProgramElementDoc> members;
66 /**
67 * The index of the current member that is being documented at this point
68 * in time.
69 */
70 protected int currentMemberIndex;
72 /**
73 * Construct a new AnnotationTypeRequiredMemberBuilder.
74 *
75 * @param configuration the current configuration of the
76 * doclet.
77 */
78 protected AnnotationTypeRequiredMemberBuilder(Configuration configuration) {
79 super(configuration);
80 }
83 /**
84 * Construct a new AnnotationTypeMemberBuilder.
85 *
86 * @param configuration the current configuration of the doclet.
87 * @param classDoc the class whoses members are being documented.
88 * @param writer the doclet specific writer.
89 */
90 public static AnnotationTypeRequiredMemberBuilder getInstance(
91 Configuration configuration, ClassDoc classDoc,
92 AnnotationTypeRequiredMemberWriter writer) {
93 AnnotationTypeRequiredMemberBuilder builder =
94 new AnnotationTypeRequiredMemberBuilder(configuration);
95 builder.classDoc = classDoc;
96 builder.writer = writer;
97 builder.visibleMemberMap = new VisibleMemberMap(classDoc,
98 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED, configuration.nodeprecated);
99 builder.members = new ArrayList<ProgramElementDoc>(
100 builder.visibleMemberMap.getMembersFor(classDoc));
101 if (configuration.getMemberComparator() != null) {
102 Collections.sort(builder.members,
103 configuration.getMemberComparator());
104 }
105 return builder;
106 }
108 /**
109 * {@inheritDoc}
110 */
111 public String getName() {
112 return "AnnotationTypeRequiredMemberDetails";
113 }
115 /**
116 * Returns a list of members that will be documented for the given class.
117 * This information can be used for doclet specific documentation
118 * generation.
119 *
120 * @param classDoc the {@link ClassDoc} we want to check.
121 * @return a list of members that will be documented.
122 */
123 public List<ProgramElementDoc> members(ClassDoc classDoc) {
124 return visibleMemberMap.getMembersFor(classDoc);
125 }
127 /**
128 * Returns the visible member map for the members of this class.
129 *
130 * @return the visible member map for the members of this class.
131 */
132 public VisibleMemberMap getVisibleMemberMap() {
133 return visibleMemberMap;
134 }
136 /**
137 * summaryOrder.size()
138 */
139 public boolean hasMembersToDocument() {
140 return members.size() > 0;
141 }
143 /**
144 * Build the annotation type required member documentation.
145 *
146 * @param node the XML element that specifies which components to document
147 * @param memberDetailsTree the content tree to which the documentation will be added
148 */
149 public void buildAnnotationTypeRequiredMember(XMLNode node, Content memberDetailsTree) {
150 buildAnnotationTypeMember(node, memberDetailsTree);
151 }
153 /**
154 * Build the member documentation.
155 *
156 * @param node the XML element that specifies which components to document
157 * @param memberDetailsTree the content tree to which the documentation will be added
158 */
159 public void buildAnnotationTypeMember(XMLNode node, Content memberDetailsTree) {
160 if (writer == null) {
161 return;
162 }
163 int size = members.size();
164 if (size > 0) {
165 writer.addAnnotationDetailsTreeHeader(
166 classDoc, memberDetailsTree);
167 for (currentMemberIndex = 0; currentMemberIndex < size;
168 currentMemberIndex++) {
169 Content annotationDocTree = writer.getAnnotationDocTreeHeader(
170 (MemberDoc) members.get(currentMemberIndex),
171 memberDetailsTree);
172 buildChildren(node, annotationDocTree);
173 memberDetailsTree.addContent(writer.getAnnotationDoc(
174 annotationDocTree, (currentMemberIndex == size - 1)));
175 }
176 }
177 }
179 /**
180 * Build the signature.
181 *
182 * @param node the XML element that specifies which components to document
183 * @param annotationDocTree the content tree to which the documentation will be added
184 */
185 public void buildSignature(XMLNode node, Content annotationDocTree) {
186 annotationDocTree.addContent(
187 writer.getSignature((MemberDoc) members.get(currentMemberIndex)));
188 }
190 /**
191 * Build the deprecation information.
192 *
193 * @param node the XML element that specifies which components to document
194 * @param annotationDocTree the content tree to which the documentation will be added
195 */
196 public void buildDeprecationInfo(XMLNode node, Content annotationDocTree) {
197 writer.addDeprecated((MemberDoc) members.get(currentMemberIndex),
198 annotationDocTree);
199 }
201 /**
202 * Build the comments for the member. Do nothing if
203 * {@link Configuration#nocomment} is set to true.
204 *
205 * @param node the XML element that specifies which components to document
206 * @param annotationDocTree the content tree to which the documentation will be added
207 */
208 public void buildMemberComments(XMLNode node, Content annotationDocTree) {
209 if(! configuration.nocomment){
210 writer.addComments((MemberDoc) members.get(currentMemberIndex),
211 annotationDocTree);
212 }
213 }
215 /**
216 * Build the tag information.
217 *
218 * @param node the XML element that specifies which components to document
219 * @param annotationDocTree the content tree to which the documentation will be added
220 */
221 public void buildTagInfo(XMLNode node, Content annotationDocTree) {
222 writer.addTags((MemberDoc) members.get(currentMemberIndex),
223 annotationDocTree);
224 }
226 /**
227 * Return the annotation type required member writer for this builder.
228 *
229 * @return the annotation type required member constant writer for this
230 * builder.
231 */
232 public AnnotationTypeRequiredMemberWriter getWriter() {
233 return writer;
234 }
235 }