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.util.*;
30 import com.sun.javadoc.*;
31 import com.sun.tools.doclets.internal.toolkit.*;
32 import com.sun.tools.doclets.internal.toolkit.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 * @author Bhavesh Patel (Modified)
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 * Returns a list of members that will be documented for the given class.
118 * This information can be used for doclet specific documentation
119 * generation.
120 *
121 * @param classDoc the {@link ClassDoc} we want to check.
122 * @return a list of members that will be documented.
123 */
124 public List<ProgramElementDoc> members(ClassDoc classDoc) {
125 return visibleMemberMap.getMembersFor(classDoc);
126 }
128 /**
129 * Returns the visible member map for the members of this class.
130 *
131 * @return the visible member map for the members of this class.
132 */
133 public VisibleMemberMap getVisibleMemberMap() {
134 return visibleMemberMap;
135 }
137 /**
138 * summaryOrder.size()
139 */
140 public boolean hasMembersToDocument() {
141 return members.size() > 0;
142 }
144 /**
145 * Build the annotation type required member documentation.
146 *
147 * @param node the XML element that specifies which components to document
148 * @param memberDetailsTree the content tree to which the documentation will be added
149 */
150 public void buildAnnotationTypeRequiredMember(XMLNode node, Content memberDetailsTree) {
151 buildAnnotationTypeMember(node, memberDetailsTree);
152 }
154 /**
155 * Build the member documentation.
156 *
157 * @param node the XML element that specifies which components to document
158 * @param memberDetailsTree the content tree to which the documentation will be added
159 */
160 public void buildAnnotationTypeMember(XMLNode node, Content memberDetailsTree) {
161 if (writer == null) {
162 return;
163 }
164 int size = members.size();
165 if (size > 0) {
166 writer.addAnnotationDetailsTreeHeader(
167 classDoc, memberDetailsTree);
168 for (currentMemberIndex = 0; currentMemberIndex < size;
169 currentMemberIndex++) {
170 Content annotationDocTree = writer.getAnnotationDocTreeHeader(
171 (MemberDoc) members.get(currentMemberIndex),
172 memberDetailsTree);
173 buildChildren(node, annotationDocTree);
174 memberDetailsTree.addContent(writer.getAnnotationDoc(
175 annotationDocTree, (currentMemberIndex == size - 1)));
176 }
177 }
178 }
180 /**
181 * Build the signature.
182 *
183 * @param node the XML element that specifies which components to document
184 * @param annotationDocTree the content tree to which the documentation will be added
185 */
186 public void buildSignature(XMLNode node, Content annotationDocTree) {
187 annotationDocTree.addContent(
188 writer.getSignature((MemberDoc) members.get(currentMemberIndex)));
189 }
191 /**
192 * Build the deprecation information.
193 *
194 * @param node the XML element that specifies which components to document
195 * @param annotationDocTree the content tree to which the documentation will be added
196 */
197 public void buildDeprecationInfo(XMLNode node, Content annotationDocTree) {
198 writer.addDeprecated((MemberDoc) members.get(currentMemberIndex),
199 annotationDocTree);
200 }
202 /**
203 * Build the comments for the member. Do nothing if
204 * {@link Configuration#nocomment} is set to true.
205 *
206 * @param node the XML element that specifies which components to document
207 * @param annotationDocTree the content tree to which the documentation will be added
208 */
209 public void buildMemberComments(XMLNode node, Content annotationDocTree) {
210 if(! configuration.nocomment){
211 writer.addComments((MemberDoc) members.get(currentMemberIndex),
212 annotationDocTree);
213 }
214 }
216 /**
217 * Build the tag information.
218 *
219 * @param node the XML element that specifies which components to document
220 * @param annotationDocTree the content tree to which the documentation will be added
221 */
222 public void buildTagInfo(XMLNode node, Content annotationDocTree) {
223 writer.addTags((MemberDoc) members.get(currentMemberIndex),
224 annotationDocTree);
225 }
227 /**
228 * Return the annotation type required member writer for this builder.
229 *
230 * @return the annotation type required member constant writer for this
231 * builder.
232 */
233 public AnnotationTypeRequiredMemberWriter getWriter() {
234 return writer;
235 }
236 }