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 a field.
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 FieldBuilder extends AbstractMemberBuilder {
47 /**
48 * The class whose fields are being documented.
49 */
50 private ClassDoc classDoc;
52 /**
53 * The visible fields for the given class.
54 */
55 private VisibleMemberMap visibleMemberMap;
57 /**
58 * The writer to output the field documentation.
59 */
60 private FieldWriter writer;
62 /**
63 * The list of fields being documented.
64 */
65 private List<ProgramElementDoc> fields;
67 /**
68 * The index of the current field that is being documented at this point
69 * in time.
70 */
71 private int currentFieldIndex;
73 /**
74 * Construct a new FieldBuilder.
75 *
76 * @param configuration the current configuration of the
77 * doclet.
78 */
79 private FieldBuilder(Configuration configuration) {
80 super(configuration);
81 }
83 /**
84 * Construct a new FieldBuilder.
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 FieldBuilder getInstance(
91 Configuration configuration,
92 ClassDoc classDoc,
93 FieldWriter writer) {
94 FieldBuilder builder = new FieldBuilder(configuration);
95 builder.classDoc = classDoc;
96 builder.writer = writer;
97 builder.visibleMemberMap =
98 new VisibleMemberMap(
99 classDoc,
100 VisibleMemberMap.FIELDS,
101 configuration.nodeprecated);
102 builder.fields =
103 new ArrayList<ProgramElementDoc>(builder.visibleMemberMap.getLeafClassMembers(
104 configuration));
105 if (configuration.getMemberComparator() != null) {
106 Collections.sort(
107 builder.fields,
108 configuration.getMemberComparator());
109 }
110 return builder;
111 }
113 /**
114 * {@inheritDoc}
115 */
116 public String getName() {
117 return "FieldDetails";
118 }
120 /**
121 * Returns a list of fields that will be documented for the given class.
122 * This information can be used for doclet specific documentation
123 * generation.
124 *
125 * @param classDoc the {@link ClassDoc} we want to check.
126 * @return a list of fields that will be documented.
127 */
128 public List<ProgramElementDoc> members(ClassDoc classDoc) {
129 return visibleMemberMap.getMembersFor(classDoc);
130 }
132 /**
133 * Returns the visible member map for the fields of this class.
134 *
135 * @return the visible member map for the fields of this class.
136 */
137 public VisibleMemberMap getVisibleMemberMap() {
138 return visibleMemberMap;
139 }
141 /**
142 * summaryOrder.size()
143 */
144 public boolean hasMembersToDocument() {
145 return fields.size() > 0;
146 }
148 /**
149 * Build the field documentation.
150 *
151 * @param node the XML element that specifies which components to document
152 * @param memberDetailsTree the content tree to which the documentation will be added
153 */
154 public void buildFieldDoc(XMLNode node, Content memberDetailsTree) {
155 if (writer == null) {
156 return;
157 }
158 int size = fields.size();
159 if (size > 0) {
160 Content fieldDetailsTree = writer.getFieldDetailsTreeHeader(
161 classDoc, memberDetailsTree);
162 for (currentFieldIndex = 0; currentFieldIndex < size;
163 currentFieldIndex++) {
164 Content fieldDocTree = writer.getFieldDocTreeHeader(
165 (FieldDoc) fields.get(currentFieldIndex),
166 fieldDetailsTree);
167 buildChildren(node, fieldDocTree);
168 fieldDetailsTree.addContent(writer.getFieldDoc(
169 fieldDocTree, (currentFieldIndex == size - 1)));
170 }
171 memberDetailsTree.addContent(
172 writer.getFieldDetails(fieldDetailsTree));
173 }
174 }
176 /**
177 * Build the signature.
178 *
179 * @param node the XML element that specifies which components to document
180 * @param fieldDocTree the content tree to which the documentation will be added
181 */
182 public void buildSignature(XMLNode node, Content fieldDocTree) {
183 fieldDocTree.addContent(
184 writer.getSignature((FieldDoc) fields.get(currentFieldIndex)));
185 }
187 /**
188 * Build the deprecation information.
189 *
190 * @param node the XML element that specifies which components to document
191 * @param fieldDocTree the content tree to which the documentation will be added
192 */
193 public void buildDeprecationInfo(XMLNode node, Content fieldDocTree) {
194 writer.addDeprecated(
195 (FieldDoc) fields.get(currentFieldIndex), fieldDocTree);
196 }
198 /**
199 * Build the comments for the field. Do nothing if
200 * {@link Configuration#nocomment} is set to true.
201 *
202 * @param node the XML element that specifies which components to document
203 * @param fieldDocTree the content tree to which the documentation will be added
204 */
205 public void buildFieldComments(XMLNode node, Content fieldDocTree) {
206 if (!configuration.nocomment) {
207 writer.addComments((FieldDoc) fields.get(currentFieldIndex), fieldDocTree);
208 }
209 }
211 /**
212 * Build the tag information.
213 *
214 * @param node the XML element that specifies which components to document
215 * @param fieldDocTree the content tree to which the documentation will be added
216 */
217 public void buildTagInfo(XMLNode node, Content fieldDocTree) {
218 writer.addTags((FieldDoc) fields.get(currentFieldIndex), fieldDocTree);
219 }
221 /**
222 * Return the field writer for this builder.
223 *
224 * @return the field writer for this builder.
225 */
226 public FieldWriter getWriter() {
227 return writer;
228 }
229 }