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

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 766
90af8d87741f
child 910
ebf7c13df6c0
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

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

mercurial