001/*
002 * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package org.jdrupes.mdoclet.internal.doclets.toolkit;
027
028import javax.lang.model.element.ExecutableElement;
029import javax.lang.model.element.PackageElement;
030import javax.lang.model.element.TypeElement;
031import javax.lang.model.element.VariableElement;
032import javax.lang.model.type.TypeMirror;
033
034import org.jdrupes.mdoclet.internal.doclets.toolkit.util.DocFileIOException;
035
036import com.sun.source.doctree.SerialFieldTree;
037
038/**
039 * The interface for writing serialized form output.
040 */
041public interface SerializedFormWriter {
042
043    /**
044     * Get the header.
045     *
046     * @param header the header to write.
047     * @return the header content
048     */
049    Content getHeader(String header);
050
051    /**
052     * Get the serialized form summaries header.
053     *
054     * @return the serialized form summary header
055     */
056    Content getSerializedSummariesHeader();
057
058    /**
059     * Get the package serialized form header.
060     *
061     * @return the package serialized form header
062     */
063    Content getPackageSerializedHeader();
064
065    /**
066     * Add the serialized package to the serialized summaries.
067     *
068     * @param serializedSummaries the serialized content to which the package serialized content will be added
069     * @param packageSerialized the serialized content per package that needs to be added
070     */
071    void addPackageSerialized(Content serializedSummaries,
072            Content packageSerialized);
073
074    /**
075     * {@return a header for the given package}
076     *
077     * @param packageElement the package element to write
078     */
079    Content getPackageHeader(PackageElement packageElement);
080
081    /**
082     * {@return the serialized class header}
083     */
084    Content getClassSerializedHeader();
085
086    /**
087     * {@return the heading for the serializable class}
088     *
089     * @param typeElement the class being processed
090     */
091    Content getClassHeader(TypeElement typeElement);
092
093    /**
094     * {@return the serial UID info header}
095     */
096    Content getSerialUIDInfoHeader();
097
098    /**
099     * Adds the serial UID info.
100     *
101     * @param header the header that will show up before the UID.
102     * @param serialUID the serial UID to print.
103     * @param target the serial UID to which the content will be added.
104     */
105    void addSerialUIDInfo(String header, String serialUID, Content target);
106
107    /**
108     * {@return the serialized class header}
109     */
110    Content getClassContentHeader();
111
112    /**
113     * Return an instance of a SerialFieldWriter for a class.
114     *
115     * @param typeElement the class
116     * @return an instance of a SerialFieldWriter.
117     */
118    SerialFieldWriter getSerialFieldWriter(TypeElement typeElement);
119
120    /**
121     * Return an instance of a SerialMethodWriter for a class.
122     *
123     * @param typeElement the class
124     * @return an instance of a SerialMethodWriter.
125     */
126    SerialMethodWriter getSerialMethodWriter(TypeElement typeElement);
127
128    /**
129     * Add the serialized content to the body content.
130     *
131     * @param source content for serialized data
132     */
133    void addSerializedContent(Content source);
134
135    /**
136     * Add the footer.
137     */
138    void addFooter();
139
140    /**
141     * Print the serialized form document.
142     *
143     * @param source the content that will be printed
144     * @throws DocFileIOException if there is a problem while writing the document
145     */
146    void printDocument(Content source) throws DocFileIOException;
147
148    /**
149     * Gets the member.
150     *
151     * @param content the content used to generate the complete member
152     * @return the member
153     */
154    Content getMember(Content content);
155
156    /**
157     * A writer for the serialized form for a given field.
158     */
159    interface SerialFieldWriter {
160
161        /**
162         * {@return the serializable field header}
163         */
164        Content getSerializableFieldsHeader();
165
166        /**
167         * {@return the field content header}
168         *
169         * @param isLastContent true if this is the last content to be documented
170         */
171        Content getFieldsContentHeader(boolean isLastContent);
172
173        /**
174         * {@return the fields}
175         *
176         * @param heading the heading to write.
177         * @param content the content to be added
178         * @return serializable fields content
179         */
180        Content getSerializableFields(String heading, Content content);
181
182        /**
183         * Adds the deprecated information for this member.
184         *
185         * @param field the field to document.
186         * @param content the content to which the deprecated information will be added
187         */
188        void addMemberDeprecatedInfo(VariableElement field, Content content);
189
190        /**
191         * Adds the description text for this member.
192         *
193         * @param field the field to document
194         * @param content the content to which the member description will be added
195         */
196        void addMemberDescription(VariableElement field, Content content);
197
198        /**
199         * Adds the description text for this member represented by the tag.
200         *
201         * @param field the field to document
202         * @param serialFieldTag the field to document (represented by tag)
203         * @param content the content to which the member description will be added
204         */
205        void addMemberDescription(VariableElement field,
206                SerialFieldTree serialFieldTag, Content content);
207
208        /**
209         * Adds the tag information for this member.
210         *
211         * @param field the field to document
212         * @param content the content to which the member tags will be added
213         */
214        void addMemberTags(VariableElement field, Content content);
215
216        /**
217         * Adds the member header.
218         *
219         * @param fieldType the type of the field
220         * @param fieldName the name of the field
221         * @param content the content to which the member header will be added
222         */
223        void addMemberHeader(TypeMirror fieldType, String fieldName,
224                Content content);
225
226        /**
227         * Check to see if overview details should be printed. If
228         * nocomment option set or if there is no text to be printed
229         * for deprecation info, inline comment or tags,
230         * do not print overview details.
231         *
232         * @param field the field to check overview details for
233         * @return true if overview details need to be printed
234         */
235        boolean shouldPrintOverview(VariableElement field);
236    }
237
238    /**
239     * Write the serialized form for a given field.
240     */
241    interface SerialMethodWriter {
242
243        /**
244         * {@return the header for serializable methods section}
245         */
246        Content getSerializableMethodsHeader();
247
248        /**
249         * {@return the header for serializable methods content section}
250         *
251         * @param isLastContent true if the content being documented is the last content
252         */
253        Content getMethodsContentHeader(boolean isLastContent);
254
255        /**
256         * Gets the given heading.
257         *
258         * @param heading the heading to write
259         * @param source the content which will be added
260         * @return a serializable methods content
261         */
262        Content getSerializableMethods(String heading, Content source);
263
264        /**
265         * Gets a warning that no serializable methods exist.
266         *
267         * @param msg the warning to print
268         * @return a no customization message
269         */
270        Content getNoCustomizationMsg(String msg);
271
272        /**
273         * Adds the header.
274         *
275         * @param member the member to write the header for
276         * @param methodsContent the content to which the header will be added
277         */
278        void addMemberHeader(ExecutableElement member, Content methodsContent);
279
280        /**
281         * Adds the deprecated information for this member.
282         *
283         * @param member the member to write the deprecated information for
284         * @param methodsContent the content to which the deprecated
285         * information will be added
286         */
287        void addDeprecatedMemberInfo(ExecutableElement member,
288                Content methodsContent);
289
290        /**
291         * Adds the description for this member.
292         *
293         * @param member the member to write the information for
294         * @param methodsContent the content to which the member
295         * information will be added
296         */
297        void addMemberDescription(ExecutableElement member,
298                Content methodsContent);
299
300        /**
301         * Adds the tag information for this member.
302         *
303         * @param member the member to write the tags information for
304         * @param methodsContent the content to which the tags
305         * information will be added
306         */
307        void addMemberTags(ExecutableElement member, Content methodsContent);
308    }
309}