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;
28 import com.sun.tools.doclets.internal.toolkit.util.*;
29 import com.sun.tools.doclets.internal.toolkit.*;
30 import com.sun.javadoc.*;
31 import java.util.*;
33 /**
34 * Builds documentation for a field.
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 * @since 1.5
42 */
43 public class FieldBuilder extends AbstractMemberBuilder {
45 /**
46 * The class whose fields are being documented.
47 */
48 private ClassDoc classDoc;
50 /**
51 * The visible fields for the given class.
52 */
53 private VisibleMemberMap visibleMemberMap;
55 /**
56 * The writer to output the field documentation.
57 */
58 private FieldWriter writer;
60 /**
61 * The list of fields being documented.
62 */
63 private List<ProgramElementDoc> fields;
65 /**
66 * The index of the current field that is being documented at this point
67 * in time.
68 */
69 private int currentFieldIndex;
71 /**
72 * Construct a new FieldBuilder.
73 *
74 * @param configuration the current configuration of the
75 * doclet.
76 */
77 private FieldBuilder(Configuration configuration) {
78 super(configuration);
79 }
81 /**
82 * Construct a new FieldBuilder.
83 *
84 * @param configuration the current configuration of the doclet.
85 * @param classDoc the class whoses members are being documented.
86 * @param writer the doclet specific writer.
87 */
88 public static FieldBuilder getInstance(
89 Configuration configuration,
90 ClassDoc classDoc,
91 FieldWriter writer) {
92 FieldBuilder builder = new FieldBuilder(configuration);
93 builder.classDoc = classDoc;
94 builder.writer = writer;
95 builder.visibleMemberMap =
96 new VisibleMemberMap(
97 classDoc,
98 VisibleMemberMap.FIELDS,
99 configuration.nodeprecated);
100 builder.fields =
101 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getLeafClassMembers(
102 configuration));
103 if (configuration.getMemberComparator() != null) {
104 Collections.sort(
105 builder.fields,
106 configuration.getMemberComparator());
107 }
108 return builder;
109 }
111 /**
112 * {@inheritDoc}
113 */
114 public String getName() {
115 return "FieldDetails";
116 }
118 /**
119 * Returns a list of fields that will be documented for the given class.
120 * This information can be used for doclet specific documentation
121 * generation.
122 *
123 * @param classDoc the {@link ClassDoc} we want to check.
124 * @return a list of fields that will be documented.
125 */
126 public List<ProgramElementDoc> members(ClassDoc classDoc) {
127 return visibleMemberMap.getMembersFor(classDoc);
128 }
130 /**
131 * Returns the visible member map for the fields of this class.
132 *
133 * @return the visible member map for the fields of this class.
134 */
135 public VisibleMemberMap getVisibleMemberMap() {
136 return visibleMemberMap;
137 }
139 /**
140 * summaryOrder.size()
141 */
142 public boolean hasMembersToDocument() {
143 return fields.size() > 0;
144 }
146 /**
147 * Build the field documentation.
148 *
149 * @param elements the XML elements that specify how to construct this
150 * documentation.
151 */
152 public void buildFieldDoc(XMLNode node) {
153 if (writer == null) {
154 return;
155 }
156 for (currentFieldIndex = 0;
157 currentFieldIndex < fields.size();
158 currentFieldIndex++) {
159 buildChildren(node);
160 }
161 }
163 /**
164 * Build the overall header.
165 */
166 public void buildHeader(XMLNode node) {
167 writer.writeHeader(
168 classDoc,
169 configuration.getText("doclet.Field_Detail"));
170 }
172 /**
173 * Build the header for the individual field.
174 */
175 public void buildFieldHeader(XMLNode node) {
176 writer.writeFieldHeader(
177 (FieldDoc) fields.get(currentFieldIndex),
178 currentFieldIndex == 0);
179 }
181 /**
182 * Build the signature.
183 */
184 public void buildSignature(XMLNode node) {
185 writer.writeSignature((FieldDoc) fields.get(currentFieldIndex));
186 }
188 /**
189 * Build the deprecation information.
190 */
191 public void buildDeprecationInfo(XMLNode node) {
192 writer.writeDeprecated((FieldDoc) fields.get(currentFieldIndex));
193 }
195 /**
196 * Build the comments for the field. Do nothing if
197 * {@link Configuration#nocomment} is set to true.
198 */
199 public void buildFieldComments(XMLNode node) {
200 if (!configuration.nocomment) {
201 writer.writeComments((FieldDoc) fields.get(currentFieldIndex));
202 }
203 }
205 /**
206 * Build the tag information.
207 */
208 public void buildTagInfo(XMLNode node) {
209 writer.writeTags((FieldDoc) fields.get(currentFieldIndex));
210 }
212 /**
213 * Build the footer for the individual field.
214 */
215 public void buildFieldFooter(XMLNode node) {
216 writer.writeFieldFooter();
217 }
219 /**
220 * Build the overall footer.
221 */
222 public void buildFooter(XMLNode node) {
223 writer.writeFooter(classDoc);
224 }
226 /**
227 * Return the field writer for this builder.
228 *
229 * @return the field writer for this builder.
230 */
231 public FieldWriter getWriter() {
232 return writer;
233 }
234 }