Fri, 18 Jun 2010 21:13:56 -0700
6961178: Allow doclet.xml to contain XML attributes
Reviewed-by: bpatel
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;
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.*;
34 /**
35 * Builds documentation for required annotation type members.
36 *
37 * This code is not part of an API.
38 * It is implementation that is subject to change.
39 * Do not use it as an API
40 *
41 * @author Jamie Ho
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 member documentation.
145 *
146 * @param elements the XML elements that specify how to construct this
147 * documentation.
148 */
149 public void buildAnnotationTypeRequiredMember(XMLNode node) {
150 if (writer == null) {
151 return;
152 }
153 for (currentMemberIndex = 0; currentMemberIndex < members.size();
154 currentMemberIndex++) {
155 buildChildren(node);
156 }
157 }
159 /**
160 * Build the overall header.
161 */
162 public void buildHeader(XMLNode node) {
163 writer.writeHeader(classDoc,
164 configuration.getText("doclet.Annotation_Type_Member_Detail"));
165 }
167 /**
168 * Build the header for the individual members.
169 */
170 public void buildMemberHeader(XMLNode node) {
171 writer.writeMemberHeader((MemberDoc) members.get(
172 currentMemberIndex),
173 currentMemberIndex == 0);
174 }
176 /**
177 * Build the signature.
178 */
179 public void buildSignature(XMLNode node) {
180 writer.writeSignature((MemberDoc) members.get(currentMemberIndex));
181 }
183 /**
184 * Build the deprecation information.
185 */
186 public void buildDeprecationInfo(XMLNode node) {
187 writer.writeDeprecated((MemberDoc) members.get(currentMemberIndex));
188 }
190 /**
191 * Build the comments for the member. Do nothing if
192 * {@link Configuration#nocomment} is set to true.
193 */
194 public void buildMemberComments(XMLNode node) {
195 if(! configuration.nocomment){
196 writer.writeComments((MemberDoc) members.get(currentMemberIndex));
197 }
198 }
200 /**
201 * Build the tag information.
202 */
203 public void buildTagInfo(XMLNode node) {
204 writer.writeTags((MemberDoc) members.get(currentMemberIndex));
205 }
207 /**
208 * Build the footer for the individual member.
209 */
210 public void buildMemberFooter(XMLNode node) {
211 writer.writeMemberFooter();
212 }
214 /**
215 * Build the overall footer.
216 */
217 public void buildFooter(XMLNode node) {
218 writer.writeFooter(classDoc);
219 }
221 /**
222 * Return the annotation type required member writer for this builder.
223 *
224 * @return the annotation type required member constant writer for this
225 * builder.
226 */
227 public AnnotationTypeRequiredMemberWriter getWriter() {
228 return writer;
229 }
230 }