src/share/classes/com/sun/tools/doclets/formats/html/HtmlSerialFieldWriter.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 2101
933ba3f81a87
parent 0
959103a6100f
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.doclets.formats.html;
aoqi@0 27
aoqi@0 28 import java.util.*;
aoqi@0 29
aoqi@0 30 import com.sun.javadoc.*;
aoqi@0 31 import com.sun.tools.doclets.formats.html.markup.*;
aoqi@0 32 import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0 33 import com.sun.tools.doclets.internal.toolkit.taglets.*;
aoqi@0 34
aoqi@0 35 /**
aoqi@0 36 * Generate serialized form for serializable fields.
aoqi@0 37 * Documentation denoted by the tags <code>serial</code> and
aoqi@0 38 * <code>serialField</code> is processed.
aoqi@0 39 *
aoqi@0 40 * <p><b>This is NOT part of any supported API.
aoqi@0 41 * If you write code that depends on this, you do so at your own risk.
aoqi@0 42 * This code and its internal interfaces are subject to change or
aoqi@0 43 * deletion without notice.</b>
aoqi@0 44 *
aoqi@0 45 * @author Joe Fialli
aoqi@0 46 * @author Bhavesh Patel (Modified)
aoqi@0 47 */
aoqi@0 48 public class HtmlSerialFieldWriter extends FieldWriterImpl
aoqi@0 49 implements SerializedFormWriter.SerialFieldWriter {
aoqi@0 50 ProgramElementDoc[] members = null;
aoqi@0 51
aoqi@0 52 public HtmlSerialFieldWriter(SubWriterHolderWriter writer,
aoqi@0 53 ClassDoc classdoc) {
aoqi@0 54 super(writer, classdoc);
aoqi@0 55 }
aoqi@0 56
aoqi@0 57 public List<FieldDoc> members(ClassDoc cd) {
aoqi@0 58 return Arrays.asList(cd.serializableFields());
aoqi@0 59 }
aoqi@0 60
aoqi@0 61 /**
aoqi@0 62 * Return the header for serializable fields section.
aoqi@0 63 *
aoqi@0 64 * @return a content tree for the header
aoqi@0 65 */
aoqi@0 66 public Content getSerializableFieldsHeader() {
aoqi@0 67 HtmlTree ul = new HtmlTree(HtmlTag.UL);
aoqi@0 68 ul.addStyle(HtmlStyle.blockList);
aoqi@0 69 return ul;
aoqi@0 70 }
aoqi@0 71
aoqi@0 72 /**
aoqi@0 73 * Return the header for serializable fields content section.
aoqi@0 74 *
aoqi@0 75 * @param isLastContent true if the cotent being documented is the last content.
aoqi@0 76 * @return a content tree for the header
aoqi@0 77 */
aoqi@0 78 public Content getFieldsContentHeader(boolean isLastContent) {
aoqi@0 79 HtmlTree li = new HtmlTree(HtmlTag.LI);
aoqi@0 80 if (isLastContent)
aoqi@0 81 li.addStyle(HtmlStyle.blockListLast);
aoqi@0 82 else
aoqi@0 83 li.addStyle(HtmlStyle.blockList);
aoqi@0 84 return li;
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 /**
aoqi@0 88 * Add serializable fields.
aoqi@0 89 *
aoqi@0 90 * @param heading the heading for the section
aoqi@0 91 * @param serializableFieldsTree the tree to be added to the serializable fileds
aoqi@0 92 * content tree
aoqi@0 93 * @return a content tree for the serializable fields content
aoqi@0 94 */
aoqi@0 95 public Content getSerializableFields(String heading, Content serializableFieldsTree) {
aoqi@0 96 HtmlTree li = new HtmlTree(HtmlTag.LI);
aoqi@0 97 li.addStyle(HtmlStyle.blockList);
aoqi@0 98 if (serializableFieldsTree.isValid()) {
aoqi@0 99 Content headingContent = new StringContent(heading);
aoqi@0 100 Content serialHeading = HtmlTree.HEADING(HtmlConstants.SERIALIZED_MEMBER_HEADING,
aoqi@0 101 headingContent);
aoqi@0 102 li.addContent(serialHeading);
aoqi@0 103 li.addContent(serializableFieldsTree);
aoqi@0 104 }
aoqi@0 105 return li;
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 /**
aoqi@0 109 * Add the member header.
aoqi@0 110 *
aoqi@0 111 * @param fieldType the class document to be listed
aoqi@0 112 * @param fieldTypeStr the string for the field type to be documented
aoqi@0 113 * @param fieldDimensions the dimensions of the field string to be added
aoqi@0 114 * @param fieldName name of the field to be added
aoqi@0 115 * @param contentTree the content tree to which the member header will be added
aoqi@0 116 */
aoqi@0 117 public void addMemberHeader(ClassDoc fieldType, String fieldTypeStr,
aoqi@0 118 String fieldDimensions, String fieldName, Content contentTree) {
aoqi@0 119 Content nameContent = new RawHtml(fieldName);
aoqi@0 120 Content heading = HtmlTree.HEADING(HtmlConstants.MEMBER_HEADING, nameContent);
aoqi@0 121 contentTree.addContent(heading);
aoqi@0 122 Content pre = new HtmlTree(HtmlTag.PRE);
aoqi@0 123 if (fieldType == null) {
aoqi@0 124 pre.addContent(fieldTypeStr);
aoqi@0 125 } else {
aoqi@0 126 Content fieldContent = writer.getLink(new LinkInfoImpl(
aoqi@0 127 configuration, LinkInfoImpl.Kind.SERIAL_MEMBER, fieldType));
aoqi@0 128 pre.addContent(fieldContent);
aoqi@0 129 }
aoqi@0 130 pre.addContent(fieldDimensions + " ");
aoqi@0 131 pre.addContent(fieldName);
aoqi@0 132 contentTree.addContent(pre);
aoqi@0 133 }
aoqi@0 134
aoqi@0 135 /**
aoqi@0 136 * Add the deprecated information for this member.
aoqi@0 137 *
aoqi@0 138 * @param field the field to document.
aoqi@0 139 * @param contentTree the tree to which the deprecated info will be added
aoqi@0 140 */
aoqi@0 141 public void addMemberDeprecatedInfo(FieldDoc field, Content contentTree) {
aoqi@0 142 addDeprecatedInfo(field, contentTree);
aoqi@0 143 }
aoqi@0 144
aoqi@0 145 /**
aoqi@0 146 * Add the description text for this member.
aoqi@0 147 *
aoqi@0 148 * @param field the field to document.
aoqi@0 149 * @param contentTree the tree to which the deprecated info will be added
aoqi@0 150 */
aoqi@0 151 public void addMemberDescription(FieldDoc field, Content contentTree) {
aoqi@0 152 if (field.inlineTags().length > 0) {
aoqi@0 153 writer.addInlineComment(field, contentTree);
aoqi@0 154 }
aoqi@0 155 Tag[] tags = field.tags("serial");
aoqi@0 156 if (tags.length > 0) {
aoqi@0 157 writer.addInlineComment(field, tags[0], contentTree);
aoqi@0 158 }
aoqi@0 159 }
aoqi@0 160
aoqi@0 161 /**
aoqi@0 162 * Add the description text for this member represented by the tag.
aoqi@0 163 *
aoqi@0 164 * @param serialFieldTag the field to document (represented by tag)
aoqi@0 165 * @param contentTree the tree to which the deprecated info will be added
aoqi@0 166 */
aoqi@0 167 public void addMemberDescription(SerialFieldTag serialFieldTag, Content contentTree) {
aoqi@0 168 String serialFieldTagDesc = serialFieldTag.description().trim();
aoqi@0 169 if (!serialFieldTagDesc.isEmpty()) {
aoqi@0 170 Content serialFieldContent = new RawHtml(serialFieldTagDesc);
aoqi@0 171 Content div = HtmlTree.DIV(HtmlStyle.block, serialFieldContent);
aoqi@0 172 contentTree.addContent(div);
aoqi@0 173 }
aoqi@0 174 }
aoqi@0 175
aoqi@0 176 /**
aoqi@0 177 * Add the tag information for this member.
aoqi@0 178 *
aoqi@0 179 * @param field the field to document.
aoqi@0 180 * @param contentTree the tree to which the member tags info will be added
aoqi@0 181 */
aoqi@0 182 public void addMemberTags(FieldDoc field, Content contentTree) {
aoqi@0 183 Content tagContent = new ContentBuilder();
aoqi@0 184 TagletWriter.genTagOuput(configuration.tagletManager, field,
aoqi@0 185 configuration.tagletManager.getCustomTaglets(field),
aoqi@0 186 writer.getTagletWriterInstance(false), tagContent);
aoqi@0 187 Content dlTags = new HtmlTree(HtmlTag.DL);
aoqi@0 188 dlTags.addContent(tagContent);
aoqi@0 189 contentTree.addContent(dlTags); // TODO: what if empty?
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 /**
aoqi@0 193 * Check to see if overview details should be printed. If
aoqi@0 194 * nocomment option set or if there is no text to be printed
aoqi@0 195 * for deprecation info, comment or tags, do not print overview details.
aoqi@0 196 *
aoqi@0 197 * @param field the field to check overview details for.
aoqi@0 198 * @return true if overview details need to be printed
aoqi@0 199 */
aoqi@0 200 public boolean shouldPrintOverview(FieldDoc field) {
aoqi@0 201 if (!configuration.nocomment) {
aoqi@0 202 if(!field.commentText().isEmpty() ||
aoqi@0 203 writer.hasSerializationOverviewTags(field))
aoqi@0 204 return true;
aoqi@0 205 }
aoqi@0 206 if (field.tags("deprecated").length > 0)
aoqi@0 207 return true;
aoqi@0 208 return false;
aoqi@0 209 }
aoqi@0 210 }

mercurial