001/*
002 * Copyright (c) 1998, 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.formats.html;
027
028import javax.lang.model.element.ExecutableElement;
029import javax.lang.model.element.TypeElement;
030
031import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlStyle;
032import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.HtmlTree;
033import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.TagName;
034import org.jdrupes.mdoclet.internal.doclets.formats.html.markup.Text;
035import org.jdrupes.mdoclet.internal.doclets.toolkit.Content;
036import org.jdrupes.mdoclet.internal.doclets.toolkit.SerializedFormWriter;
037import org.jdrupes.mdoclet.internal.doclets.toolkit.taglets.TagletManager;
038
039/**
040 * Generate serialized form for Serializable/Externalizable methods.
041 * Documentation denoted by the <code>serialData</code> tag is processed.
042 */
043public class HtmlSerialMethodWriter extends MethodWriterImpl implements
044        SerializedFormWriter.SerialMethodWriter {
045
046    public HtmlSerialMethodWriter(SubWriterHolderWriter writer,
047            TypeElement typeElement) {
048        super(writer, typeElement);
049    }
050
051    @Override
052    public Content getSerializableMethodsHeader() {
053        return HtmlTree.UL(HtmlStyle.blockList);
054    }
055
056    @Override
057    public Content getMethodsContentHeader(boolean isLastContent) {
058        return new HtmlTree(TagName.LI);
059    }
060
061    /**
062     * Add serializable methods.
063     *
064     * @param heading the heading for the section
065     * @param source the content to be added to the serializable methods
066     *        content
067     * @return a content for the serializable methods content
068     */
069    @Override
070    public Content getSerializableMethods(String heading, Content source) {
071        Content headingContent = Text.of(heading);
072        var serialHeading = HtmlTree
073            .HEADING(Headings.SerializedForm.CLASS_SUBHEADING, headingContent);
074        var section = HtmlTree.SECTION(HtmlStyle.detail, serialHeading);
075        section.add(source);
076        return HtmlTree.LI(section);
077    }
078
079    /**
080     * Return the no customization message.
081     *
082     * @param msg the message to be displayed
083     * @return no customization message content
084     */
085    @Override
086    public Content getNoCustomizationMsg(String msg) {
087        return Text.of(msg);
088    }
089
090    /**
091     * Add the member header.
092     *
093     * @param member the method document to be listed
094     * @param methodsContent the content to which the member header will be added
095     */
096    @Override
097    public void addMemberHeader(ExecutableElement member,
098            Content methodsContent) {
099        Content memberContent = Text.of(name(member));
100        var heading = HtmlTree.HEADING(Headings.SerializedForm.MEMBER_HEADING,
101            memberContent);
102        methodsContent.add(heading);
103        methodsContent.add(getSignature(member));
104    }
105
106    /**
107     * Add the deprecated information for this member.
108     *
109     * @param member the method to document.
110     * @param methodsContent the content to which the deprecated info will be added
111     */
112    @Override
113    public void addDeprecatedMemberInfo(ExecutableElement member,
114            Content methodsContent) {
115        addDeprecatedInfo(member, methodsContent);
116    }
117
118    /**
119     * Add the description text for this member.
120     *
121     * @param member the method to document.
122     * @param methodsContent the content to which the deprecated info will be added
123     */
124    @Override
125    public void addMemberDescription(ExecutableElement member,
126            Content methodsContent) {
127        addComment(member, methodsContent);
128    }
129
130    /**
131     * Add the tag information for this member.
132     *
133     * @param member the method to document.
134     * @param methodsContent the content to which the member tags info will be added
135     */
136    @Override
137    public void addMemberTags(ExecutableElement member,
138            Content methodsContent) {
139        TagletManager tagletManager = configuration.tagletManager;
140        Content tagContent = writer.getBlockTagOutput(member,
141            tagletManager.getSerializedFormTaglets());
142        var dl = HtmlTree.DL(HtmlStyle.notes);
143        dl.add(tagContent);
144        methodsContent.add(dl);
145        if (name(member).equals("writeExternal")
146            && utils.getSerialDataTrees(member).isEmpty()) {
147            serialWarning(member, "doclet.MissingSerialDataTag",
148                utils.getFullyQualifiedName(member.getEnclosingElement()),
149                name(member));
150        }
151    }
152}