HtmlSerialMethodWriter.java revision 3233:b5d08bc0d224
1/*
2 * Copyright (c) 1998, 2016, 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 */
25
26package jdk.javadoc.internal.doclets.formats.html;
27
28import javax.lang.model.element.ExecutableElement;
29import javax.lang.model.element.TypeElement;
30
31import jdk.javadoc.internal.doclets.formats.html.markup.ContentBuilder;
32import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
33import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
34import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
35import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
36import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
37import jdk.javadoc.internal.doclets.toolkit.Content;
38import jdk.javadoc.internal.doclets.toolkit.SerializedFormWriter;
39import jdk.javadoc.internal.doclets.toolkit.taglets.TagletManager;
40import jdk.javadoc.internal.doclets.toolkit.taglets.TagletWriter;
41
42
43/**
44 * Generate serialized form for Serializable/Externalizable methods.
45 * Documentation denoted by the <code>serialData</code> tag is processed.
46 *
47 *  <p><b>This is NOT part of any supported API.
48 *  If you write code that depends on this, you do so at your own risk.
49 *  This code and its internal interfaces are subject to change or
50 *  deletion without notice.</b>
51 *
52 * @author Joe Fialli
53 * @author Bhavesh Patel (Modified)
54 */
55public class HtmlSerialMethodWriter extends MethodWriterImpl implements
56        SerializedFormWriter.SerialMethodWriter{
57
58    public HtmlSerialMethodWriter(SubWriterHolderWriter writer, TypeElement  typeElement) {
59        super(writer, typeElement);
60    }
61
62    /**
63     * Return the header for serializable methods section.
64     *
65     * @return a content tree for the header
66     */
67    public Content getSerializableMethodsHeader() {
68        HtmlTree ul = new HtmlTree(HtmlTag.UL);
69        ul.addStyle(HtmlStyle.blockList);
70        return ul;
71    }
72
73    /**
74     * Return the header for serializable methods content section.
75     *
76     * @param isLastContent true if the cotent being documented is the last content.
77     * @return a content tree for the header
78     */
79    public Content getMethodsContentHeader(boolean isLastContent) {
80        HtmlTree li = new HtmlTree(HtmlTag.LI);
81        if (isLastContent)
82            li.addStyle(HtmlStyle.blockListLast);
83        else
84            li.addStyle(HtmlStyle.blockList);
85        return li;
86    }
87
88    /**
89     * Add serializable methods.
90     *
91     * @param heading the heading for the section
92     * @param serializableMethodContent the tree to be added to the serializable methods
93     *        content tree
94     * @return a content tree for the serializable methods content
95     */
96    public Content getSerializableMethods(String heading, Content serializableMethodContent) {
97        Content headingContent = new StringContent(heading);
98        Content serialHeading = HtmlTree.HEADING(HtmlConstants.SERIALIZED_MEMBER_HEADING,
99                headingContent);
100        Content li = HtmlTree.LI(HtmlStyle.blockList, serialHeading);
101        li.addContent(serializableMethodContent);
102        return li;
103    }
104
105    /**
106     * Return the no customization message.
107     *
108     * @param msg the message to be displayed
109     * @return no customization message content
110     */
111    public Content getNoCustomizationMsg(String msg) {
112        Content noCustomizationMsg = new StringContent(msg);
113        return noCustomizationMsg;
114    }
115
116    /**
117     * Add the member header.
118     *
119     * @param member the method document to be listed
120     * @param methodsContentTree the content tree to which the member header will be added
121     */
122    public void addMemberHeader(ExecutableElement member, Content methodsContentTree) {
123        methodsContentTree.addContent(getHead(member));
124        methodsContentTree.addContent(getSignature(member));
125    }
126
127    /**
128     * Add the deprecated information for this member.
129     *
130     * @param member the method to document.
131     * @param methodsContentTree the tree to which the deprecated info will be added
132     */
133    public void addDeprecatedMemberInfo(ExecutableElement member, Content methodsContentTree) {
134        addDeprecatedInfo(member, methodsContentTree);
135    }
136
137    /**
138     * Add the description text for this member.
139     *
140     * @param member the method to document.
141     * @param methodsContentTree the tree to which the deprecated info will be added
142     */
143    public void addMemberDescription(ExecutableElement member, Content methodsContentTree) {
144        addComment(member, methodsContentTree);
145    }
146
147    /**
148     * Add the tag information for this member.
149     *
150     * @param member the method to document.
151     * @param methodsContentTree the tree to which the member tags info will be added
152     */
153    public void addMemberTags(ExecutableElement member, Content methodsContentTree) {
154        Content tagContent = new ContentBuilder();
155        TagletManager tagletManager =
156            configuration.tagletManager;
157        TagletWriter.genTagOutput(tagletManager, member,
158            tagletManager.getSerializedFormTaglets(),
159            writer.getTagletWriterInstance(false), tagContent);
160        Content dlTags = new HtmlTree(HtmlTag.DL);
161        dlTags.addContent(tagContent);
162        methodsContentTree.addContent(dlTags);
163        if (name(member).compareTo("writeExternal") == 0
164                && utils.getSerialDataTrees(member).isEmpty()) {
165            serialWarning(member, "doclet.MissingSerialDataTag",
166                utils.getFullyQualifiedName(member.getEnclosingElement()), name(member));
167        }
168    }
169}
170