Thu, 02 Oct 2008 19:58:40 -0700
6754988: Update copyright year
Summary: Update for files that have been modified starting July 2008
Reviewed-by: ohair, tbell
1 /*
2 * Copyright 2003-2008 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
26 package com.sun.tools.doclets.internal.toolkit.builders;
29 import com.sun.tools.doclets.internal.toolkit.util.*;
30 import com.sun.tools.doclets.internal.toolkit.*;
31 import com.sun.javadoc.*;
32 import java.util.*;
33 import java.lang.reflect.*;
35 /**
36 * Builds documentation for required annotation type members.
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 * @since 1.5
44 */
45 public class AnnotationTypeRequiredMemberBuilder extends AbstractMemberBuilder {
47 /**
48 * The annotation type whose members are being documented.
49 */
50 protected ClassDoc classDoc;
52 /**
53 * The visible members for the given class.
54 */
55 protected VisibleMemberMap visibleMemberMap;
57 /**
58 * The writer to output the member documentation.
59 */
60 protected AnnotationTypeRequiredMemberWriter writer;
62 /**
63 * The list of members being documented.
64 */
65 protected List<ProgramElementDoc> members;
67 /**
68 * The index of the current member that is being documented at this point
69 * in time.
70 */
71 protected int currentMemberIndex;
73 /**
74 * Construct a new AnnotationTypeRequiredMemberBuilder.
75 *
76 * @param configuration the current configuration of the
77 * doclet.
78 */
79 protected AnnotationTypeRequiredMemberBuilder(Configuration configuration) {
80 super(configuration);
81 }
84 /**
85 * Construct a new AnnotationTypeMemberBuilder.
86 *
87 * @param configuration the current configuration of the doclet.
88 * @param classDoc the class whoses members are being documented.
89 * @param writer the doclet specific writer.
90 */
91 public static AnnotationTypeRequiredMemberBuilder getInstance(
92 Configuration configuration, ClassDoc classDoc,
93 AnnotationTypeRequiredMemberWriter writer) {
94 AnnotationTypeRequiredMemberBuilder builder =
95 new AnnotationTypeRequiredMemberBuilder(configuration);
96 builder.classDoc = classDoc;
97 builder.writer = writer;
98 builder.visibleMemberMap = new VisibleMemberMap(classDoc,
99 VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED, configuration.nodeprecated);
100 builder.members = new ArrayList<ProgramElementDoc>(
101 builder.visibleMemberMap.getMembersFor(classDoc));
102 if (configuration.getMemberComparator() != null) {
103 Collections.sort(builder.members,
104 configuration.getMemberComparator());
105 }
106 return builder;
107 }
109 /**
110 * {@inheritDoc}
111 */
112 public String getName() {
113 return "AnnotationTypeRequiredMemberDetails";
114 }
116 /**
117 * {@inheritDoc}
118 */
119 public void invokeMethod(String methodName, Class[] paramClasses,
120 Object[] params)
121 throws Exception {
122 if (DEBUG) {
123 configuration.root.printError("DEBUG: " + this.getClass().getName()
124 + "." + methodName);
125 }
126 Method method = this.getClass().getMethod(methodName, paramClasses);
127 method.invoke(this, params);
128 }
130 /**
131 * Returns a list of members that will be documented for the given class.
132 * This information can be used for doclet specific documentation
133 * generation.
134 *
135 * @param classDoc the {@link ClassDoc} we want to check.
136 * @return a list of members that will be documented.
137 */
138 public List members(ClassDoc classDoc) {
139 return visibleMemberMap.getMembersFor(classDoc);
140 }
142 /**
143 * Returns the visible member map for the members of this class.
144 *
145 * @return the visible member map for the members of this class.
146 */
147 public VisibleMemberMap getVisibleMemberMap() {
148 return visibleMemberMap;
149 }
151 /**
152 * summaryOrder.size()
153 */
154 public boolean hasMembersToDocument() {
155 return members.size() > 0;
156 }
158 /**
159 * Build the member documentation.
160 *
161 * @param elements the XML elements that specify how to construct this
162 * documentation.
163 */
164 public void buildAnnotationTypeRequiredMember(List elements) {
165 if (writer == null) {
166 return;
167 }
168 for (currentMemberIndex = 0; currentMemberIndex < members.size();
169 currentMemberIndex++) {
170 build(elements);
171 }
172 }
174 /**
175 * Build the overall header.
176 */
177 public void buildHeader() {
178 writer.writeHeader(classDoc,
179 configuration.getText("doclet.Annotation_Type_Member_Detail"));
180 }
182 /**
183 * Build the header for the individual members.
184 */
185 public void buildMemberHeader() {
186 writer.writeMemberHeader((MemberDoc) members.get(
187 currentMemberIndex),
188 currentMemberIndex == 0);
189 }
191 /**
192 * Build the signature.
193 */
194 public void buildSignature() {
195 writer.writeSignature((MemberDoc) members.get(currentMemberIndex));
196 }
198 /**
199 * Build the deprecation information.
200 */
201 public void buildDeprecationInfo() {
202 writer.writeDeprecated((MemberDoc) members.get(currentMemberIndex));
203 }
205 /**
206 * Build the comments for the member. Do nothing if
207 * {@link Configuration#nocomment} is set to true.
208 */
209 public void buildMemberComments() {
210 if(! configuration.nocomment){
211 writer.writeComments((MemberDoc) members.get(currentMemberIndex));
212 }
213 }
215 /**
216 * Build the tag information.
217 */
218 public void buildTagInfo() {
219 writer.writeTags((MemberDoc) members.get(currentMemberIndex));
220 }
222 /**
223 * Build the footer for the individual member.
224 */
225 public void buildMemberFooter() {
226 writer.writeMemberFooter();
227 }
229 /**
230 * Build the overall footer.
231 */
232 public void buildFooter() {
233 writer.writeFooter(classDoc);
234 }
236 /**
237 * Return the annotation type required member writer for this builder.
238 *
239 * @return the annotation type required member constant writer for this
240 * builder.
241 */
242 public AnnotationTypeRequiredMemberWriter getWriter() {
243 return writer;
244 }
245 }