35 import javax.lang.model.element.VariableElement; |
34 import javax.lang.model.element.VariableElement; |
36 |
35 |
37 import com.sun.source.doctree.DocTree; |
36 import com.sun.source.doctree.DocTree; |
38 import com.sun.source.doctree.SerialFieldTree; |
37 import com.sun.source.doctree.SerialFieldTree; |
39 import jdk.javadoc.internal.doclets.toolkit.Content; |
38 import jdk.javadoc.internal.doclets.toolkit.Content; |
|
39 import jdk.javadoc.internal.doclets.toolkit.DocletException; |
40 import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter; |
40 import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter; |
41 import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; |
41 import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; |
42 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException; |
|
43 import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
42 import jdk.javadoc.internal.doclets.toolkit.util.Utils; |
44 |
43 |
45 /** |
44 /** |
46 * Builds the serialized form. |
45 * Builds the serialized form. |
47 * |
46 * |
112 super(context); |
111 super(context); |
113 } |
112 } |
114 |
113 |
115 /** |
114 /** |
116 * Construct a new SerializedFormBuilder. |
115 * Construct a new SerializedFormBuilder. |
|
116 * |
117 * @param context the build context. |
117 * @param context the build context. |
|
118 * @return the new SerializedFormBuilder |
118 */ |
119 */ |
119 public static SerializedFormBuilder getInstance(Context context) { |
120 public static SerializedFormBuilder getInstance(Context context) { |
120 return new SerializedFormBuilder(context); |
121 return new SerializedFormBuilder(context); |
121 } |
122 } |
122 |
123 |
123 /** |
124 /** |
124 * Build the serialized form. |
125 * Build the serialized form. |
125 */ |
126 * |
126 public void build() throws IOException { |
127 * @throws DocletException if there is a problem while building the documentation |
|
128 */ |
|
129 @Override |
|
130 public void build() throws DocletException { |
127 SortedSet<TypeElement> rootclasses = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
131 SortedSet<TypeElement> rootclasses = new TreeSet<>(utils.makeGeneralPurposeComparator()); |
128 rootclasses.addAll(configuration.docEnv.getIncludedTypeElements()); |
132 rootclasses.addAll(configuration.docEnv.getIncludedTypeElements()); |
129 if (!serialClassFoundToDocument(rootclasses)) { |
133 if (!serialClassFoundToDocument(rootclasses)) { |
130 //Nothing to document. |
134 //Nothing to document. |
131 return; |
135 return; |
132 } |
136 } |
133 try { |
137 writer = configuration.getWriterFactory().getSerializedFormWriter(); |
134 writer = configuration.getWriterFactory().getSerializedFormWriter(); |
138 if (writer == null) { |
135 if (writer == null) { |
139 //Doclet does not support this output. |
136 //Doclet does not support this output. |
140 return; |
137 return; |
|
138 } |
|
139 } catch (Exception e) { |
|
140 throw new DocletAbortException(e); |
|
141 } |
141 } |
142 build(layoutParser.parseXML(NAME), contentTree); |
142 build(layoutParser.parseXML(NAME), contentTree); |
143 } |
143 } |
144 |
144 |
145 /** |
145 /** |
146 * {@inheritDoc} |
146 * {@inheritDoc} |
147 */ |
147 */ |
|
148 @Override |
148 public String getName() { |
149 public String getName() { |
149 return NAME; |
150 return NAME; |
150 } |
151 } |
151 |
152 |
152 /** |
153 /** |
153 * Build the serialized form. |
154 * Build the serialized form. |
154 * |
155 * |
155 * @param node the XML element that specifies which components to document |
156 * @param node the XML element that specifies which components to document |
156 * @param serializedTree content tree to which the documentation will be added |
157 * @param serializedTree content tree to which the documentation will be added |
157 */ |
158 * @throws DocletException if there is a problem while building the documentation |
158 public void buildSerializedForm(XMLNode node, Content serializedTree) throws Exception { |
159 */ |
|
160 public void buildSerializedForm(XMLNode node, Content serializedTree) throws DocletException { |
159 serializedTree = writer.getHeader(configuration.getText( |
161 serializedTree = writer.getHeader(configuration.getText( |
160 "doclet.Serialized_Form")); |
162 "doclet.Serialized_Form")); |
161 buildChildren(node, serializedTree); |
163 buildChildren(node, serializedTree); |
162 writer.addFooter(serializedTree); |
164 writer.addFooter(serializedTree); |
163 writer.printDocument(serializedTree); |
165 writer.printDocument(serializedTree); |
166 /** |
168 /** |
167 * Build the serialized form summaries. |
169 * Build the serialized form summaries. |
168 * |
170 * |
169 * @param node the XML element that specifies which components to document |
171 * @param node the XML element that specifies which components to document |
170 * @param serializedTree content tree to which the documentation will be added |
172 * @param serializedTree content tree to which the documentation will be added |
171 */ |
173 * @throws DocletException if there is a problem while building the documentation |
172 public void buildSerializedFormSummaries(XMLNode node, Content serializedTree) { |
174 */ |
|
175 public void buildSerializedFormSummaries(XMLNode node, Content serializedTree) |
|
176 throws DocletException { |
173 Content serializedSummariesTree = writer.getSerializedSummariesHeader(); |
177 Content serializedSummariesTree = writer.getSerializedSummariesHeader(); |
174 for (PackageElement pkg : configuration.packages) { |
178 for (PackageElement pkg : configuration.packages) { |
175 currentPackage = pkg; |
179 currentPackage = pkg; |
176 buildChildren(node, serializedSummariesTree); |
180 buildChildren(node, serializedSummariesTree); |
177 } |
181 } |
182 /** |
186 /** |
183 * Build the package serialized form for the current package being processed. |
187 * Build the package serialized form for the current package being processed. |
184 * |
188 * |
185 * @param node the XML element that specifies which components to document |
189 * @param node the XML element that specifies which components to document |
186 * @param serializedSummariesTree content tree to which the documentation will be added |
190 * @param serializedSummariesTree content tree to which the documentation will be added |
187 */ |
191 * @throws DocletException if there is a problem while building the documentation |
188 public void buildPackageSerializedForm(XMLNode node, Content serializedSummariesTree) { |
192 */ |
|
193 public void buildPackageSerializedForm(XMLNode node, Content serializedSummariesTree) throws DocletException { |
189 Content packageSerializedTree = writer.getPackageSerializedHeader(); |
194 Content packageSerializedTree = writer.getPackageSerializedHeader(); |
190 SortedSet<TypeElement> classes = utils.getAllClassesUnfiltered(currentPackage); |
195 SortedSet<TypeElement> classes = utils.getAllClassesUnfiltered(currentPackage); |
191 if (classes.isEmpty()) { |
196 if (classes.isEmpty()) { |
192 return; |
197 return; |
193 } |
198 } |
215 /** |
220 /** |
216 * Build the class serialized form. |
221 * Build the class serialized form. |
217 * |
222 * |
218 * @param node the XML element that specifies which components to document |
223 * @param node the XML element that specifies which components to document |
219 * @param packageSerializedTree content tree to which the documentation will be added |
224 * @param packageSerializedTree content tree to which the documentation will be added |
220 */ |
225 * @throws DocletException if there is a problem while building the documentation |
221 public void buildClassSerializedForm(XMLNode node, Content packageSerializedTree) { |
226 */ |
|
227 public void buildClassSerializedForm(XMLNode node, Content packageSerializedTree) |
|
228 throws DocletException { |
222 Content classSerializedTree = writer.getClassSerializedHeader(); |
229 Content classSerializedTree = writer.getClassSerializedHeader(); |
223 SortedSet<TypeElement> typeElements = utils.getAllClassesUnfiltered(currentPackage); |
230 SortedSet<TypeElement> typeElements = utils.getAllClassesUnfiltered(currentPackage); |
224 for (TypeElement typeElement : typeElements) { |
231 for (TypeElement typeElement : typeElements) { |
225 currentTypeElement = typeElement; |
232 currentTypeElement = typeElement; |
226 fieldWriter = writer.getSerialFieldWriter(currentTypeElement); |
233 fieldWriter = writer.getSerialFieldWriter(currentTypeElement); |
260 /** |
267 /** |
261 * Build the summaries for the methods and fields. |
268 * Build the summaries for the methods and fields. |
262 * |
269 * |
263 * @param node the XML element that specifies which components to document |
270 * @param node the XML element that specifies which components to document |
264 * @param classTree content tree to which the documentation will be added |
271 * @param classTree content tree to which the documentation will be added |
265 */ |
272 * @throws DocletException if there is a problem while building the documentation |
266 public void buildClassContent(XMLNode node, Content classTree) { |
273 */ |
|
274 public void buildClassContent(XMLNode node, Content classTree) throws DocletException { |
267 Content classContentTree = writer.getClassContentHeader(); |
275 Content classContentTree = writer.getClassContentHeader(); |
268 buildChildren(node, classContentTree); |
276 buildChildren(node, classContentTree); |
269 classTree.addContent(classContentTree); |
277 classTree.addContent(classContentTree); |
270 } |
278 } |
271 |
279 |
273 * Build the summaries for the methods that belong to the given |
281 * Build the summaries for the methods that belong to the given |
274 * class. |
282 * class. |
275 * |
283 * |
276 * @param node the XML element that specifies which components to document |
284 * @param node the XML element that specifies which components to document |
277 * @param classContentTree content tree to which the documentation will be added |
285 * @param classContentTree content tree to which the documentation will be added |
278 */ |
286 * @throws DocletException if there is a problem while building the documentation |
279 public void buildSerializableMethods(XMLNode node, Content classContentTree) { |
287 */ |
|
288 public void buildSerializableMethods(XMLNode node, Content classContentTree) throws DocletException { |
280 Content serializableMethodTree = methodWriter.getSerializableMethodsHeader(); |
289 Content serializableMethodTree = methodWriter.getSerializableMethodsHeader(); |
281 SortedSet<ExecutableElement> members = utils.serializationMethods(currentTypeElement); |
290 SortedSet<ExecutableElement> members = utils.serializationMethods(currentTypeElement); |
282 if (!members.isEmpty()) { |
291 if (!members.isEmpty()) { |
283 for (ExecutableElement member : members) { |
292 for (ExecutableElement member : members) { |
284 currentMember = member; |
293 currentMember = member; |
327 /** |
336 /** |
328 * Build the information for the method. |
337 * Build the information for the method. |
329 * |
338 * |
330 * @param node the XML element that specifies which components to document |
339 * @param node the XML element that specifies which components to document |
331 * @param methodsContentTree content tree to which the documentation will be added |
340 * @param methodsContentTree content tree to which the documentation will be added |
332 */ |
341 * @throws DocletException if there is a problem while building the documentation |
333 public void buildMethodInfo(XMLNode node, Content methodsContentTree) { |
342 */ |
|
343 public void buildMethodInfo(XMLNode node, Content methodsContentTree) throws DocletException { |
334 if(configuration.nocomment){ |
344 if(configuration.nocomment){ |
335 return; |
345 return; |
336 } |
346 } |
337 buildChildren(node, methodsContentTree); |
347 buildChildren(node, methodsContentTree); |
338 } |
348 } |
409 /** |
419 /** |
410 * Build the summaries for the fields that belong to the given class. |
420 * Build the summaries for the fields that belong to the given class. |
411 * |
421 * |
412 * @param node the XML element that specifies which components to document |
422 * @param node the XML element that specifies which components to document |
413 * @param classContentTree content tree to which the documentation will be added |
423 * @param classContentTree content tree to which the documentation will be added |
414 */ |
424 * @throws DocletException if there is a problem while building the documentation |
415 public void buildSerializableFields(XMLNode node, Content classContentTree) { |
425 */ |
|
426 public void buildSerializableFields(XMLNode node, Content classContentTree) |
|
427 throws DocletException { |
416 SortedSet<VariableElement> members = utils.serializableFields(currentTypeElement); |
428 SortedSet<VariableElement> members = utils.serializableFields(currentTypeElement); |
417 if (!members.isEmpty()) { |
429 if (!members.isEmpty()) { |
418 Content serializableFieldsTree = fieldWriter.getSerializableFieldsHeader(); |
430 Content serializableFieldsTree = fieldWriter.getSerializableFieldsHeader(); |
419 for (VariableElement ve : members) { |
431 for (VariableElement ve : members) { |
420 currentMember = ve; |
432 currentMember = ve; |
531 fieldWriter.addMemberDescription(field, fieldsContentTree); |
543 fieldWriter.addMemberDescription(field, fieldsContentTree); |
532 fieldWriter.addMemberTags(field, fieldsContentTree); |
544 fieldWriter.addMemberTags(field, fieldsContentTree); |
533 } |
545 } |
534 |
546 |
535 /** |
547 /** |
536 * Return true if the given Element should be included |
548 * Returns true if the given Element should be included |
537 * in the serialized form. |
549 * in the serialized form. |
538 * |
550 * |
539 * @param element the Element object to check for serializability. |
551 * @param utils the utils object |
|
552 * @param element the Element object to check for serializability |
|
553 * @return true if the element should be included in the serial form |
540 */ |
554 */ |
541 public static boolean serialInclude(Utils utils, Element element) { |
555 public static boolean serialInclude(Utils utils, Element element) { |
542 if (element == null) { |
556 if (element == null) { |
543 return false; |
557 return false; |
544 } |
558 } |
546 ? serialClassInclude(utils, (TypeElement)element) |
560 ? serialClassInclude(utils, (TypeElement)element) |
547 : serialDocInclude(utils, element); |
561 : serialDocInclude(utils, element); |
548 } |
562 } |
549 |
563 |
550 /** |
564 /** |
551 * Return true if the given TypeElement should be included |
565 * Returns true if the given TypeElement should be included |
552 * in the serialized form. |
566 * in the serialized form. |
553 * |
567 * |
554 * @param te the TypeElement object to check for serializability. |
568 * @param te the TypeElement object to check for serializability. |
555 */ |
569 */ |
556 private static boolean serialClassInclude(Utils utils, TypeElement te) { |
570 private static boolean serialClassInclude(Utils utils, TypeElement te) { |