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