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

Mon, 09 Mar 2009 23:53:41 -0700

author
tbell
date
Mon, 09 Mar 2009 23:53:41 -0700
changeset 240
8c55d5b0ed71
parent 229
03bcd66bd8e7
parent 233
5240b1120530
child 554
9d9f26857129
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright 1998-2009 Sun Microsystems, Inc.  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.  Sun designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
    23  * have any questions.
    24  */
    26 package com.sun.tools.doclets.formats.html;
    28 import java.util.*;
    30 import com.sun.javadoc.*;
    31 import com.sun.tools.doclets.internal.toolkit.*;
    32 import com.sun.tools.doclets.internal.toolkit.taglets.*;
    33 import com.sun.tools.doclets.internal.toolkit.util.*;
    35 /**
    36  * Generate serialized form for serializable fields.
    37  * Documentation denoted by the tags <code>serial</code> and
    38  * <code>serialField</code> is processed.
    39  *
    40  * @author Joe Fialli
    41  * @author Bhavesh Patel (Modified)
    42  */
    43 public class HtmlSerialFieldWriter extends FieldWriterImpl
    44     implements SerializedFormWriter.SerialFieldWriter {
    45     ProgramElementDoc[] members = null;
    47     private boolean printedOverallAnchor = false;
    49     private boolean printedFirstMember = false;
    51     public HtmlSerialFieldWriter(SubWriterHolderWriter writer,
    52                                     ClassDoc classdoc) {
    53         super(writer, classdoc);
    54     }
    56     public List<FieldDoc> members(ClassDoc cd) {
    57         return Util.asList(cd.serializableFields());
    58     }
    60     protected void printTypeLinkNoDimension(Type type) {
    61         ClassDoc cd = type.asClassDoc();
    62         //Linking to package private classes in serialized for causes
    63         //broken links.  Don't link to them.
    64         if (type.isPrimitive() || cd.isPackagePrivate()) {
    65             print(type.typeName());
    66         } else {
    67             writer.printLink(new LinkInfoImpl(
    68                 LinkInfoImpl.CONTEXT_SERIAL_MEMBER, type));
    69         }
    70     }
    72     public void writeHeader(String heading) {
    73         if (! printedOverallAnchor) {
    74             writer.anchor("serializedForm");
    75             printedOverallAnchor = true;
    76             writer.printTableHeadingBackground(heading);
    77             writer.println();
    78             if (heading.equals(
    79                    configuration().getText("doclet.Serialized_Form_class"))) {
    80                 assert !writer.getMemberDetailsListPrinted();
    81             }
    82         } else {
    83             writer.printTableHeadingBackground(heading);
    84             writer.println();
    85         }
    86     }
    88     public void writeMemberHeader(ClassDoc fieldType, String fieldTypeStr,
    89             String fieldDimensions, String fieldName) {
    90         if (printedFirstMember) {
    91             writer.printMemberHeader();
    92         }
    93         printedFirstMember = true;
    94         writer.h3();
    95         writer.print(fieldName);
    96         writer.h3End();
    97         writer.pre();
    98         if (fieldType == null) {
    99             writer.print(fieldTypeStr);
   100         } else {
   101             writer.printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_SERIAL_MEMBER,
   102                 fieldType));
   103         }
   104         print(fieldDimensions + ' ');
   105         strong(fieldName);
   106         writer.preEnd();
   107         assert !writer.getMemberDetailsListPrinted();
   108     }
   110     /**
   111      * Write the deprecated information for this member.
   112      *
   113      * @param field the field to document.
   114      */
   115     public void writeMemberDeprecatedInfo(FieldDoc field) {
   116         printDeprecated(field);
   117     }
   119     /**
   120      * Write the description text for this member.
   121      *
   122      * @param field the field to document.
   123      */
   124     public void writeMemberDescription(FieldDoc field) {
   125         if (field.inlineTags().length > 0) {
   126             writer.printMemberDetailsListStartTag();
   127             writer.dd();
   128             writer.printInlineComment(field);
   129             writer.ddEnd();
   130         }
   131         Tag[] tags = field.tags("serial");
   132         if (tags.length > 0) {
   133             writer.printMemberDetailsListStartTag();
   134             writer.dd();
   135             writer.printInlineComment(field, tags[0]);
   136             writer.ddEnd();
   137         }
   138     }
   140     /**
   141      * Write the description text for this member represented by the tag.
   142      *
   143      * @param serialFieldTag the field to document (represented by tag).
   144      */
   145     public void writeMemberDescription(SerialFieldTag serialFieldTag) {
   146         String serialFieldTagDesc = serialFieldTag.description().trim();
   147         if (!serialFieldTagDesc.isEmpty()) {
   148             writer.dl();
   149             writer.dd();
   150             writer.print(serialFieldTagDesc);
   151             writer.ddEnd();
   152             writer.dlEnd();
   153         }
   154     }
   156     /**
   157      * Write the tag information for this member.
   158      *
   159      * @param field the field to document.
   160      */
   161     public void writeMemberTags(FieldDoc field) {
   162         TagletOutputImpl output = new TagletOutputImpl("");
   163         TagletWriter.genTagOuput(configuration().tagletManager, field,
   164             configuration().tagletManager.getCustomTags(field),
   165                 writer.getTagletWriterInstance(false), output);
   166         String outputString = output.toString().trim();
   167         if (!outputString.isEmpty()) {
   168             writer.printMemberDetailsListStartTag();
   169             writer.dd();
   170             writer.dl();
   171             print(outputString);
   172             writer.dlEnd();
   173             writer.ddEnd();
   174         }
   175     }
   177     /**
   178      * Check to see if overview details should be printed. If
   179      * nocomment option set or if there is no text to be printed
   180      * for deprecation info, comment or tags, do not print overview details.
   181      *
   182      * @param field the field to check overview details for.
   183      * @return true if overview details need to be printed
   184      */
   185     public boolean shouldPrintOverview(FieldDoc field) {
   186         if (!configuration().nocomment) {
   187             if(!field.commentText().isEmpty() ||
   188                     writer.hasSerializationOverviewTags(field))
   189                 return true;
   190         }
   191         if (field.tags("deprecated").length > 0)
   192             return true;
   193         return false;
   194     }
   196     public void writeMemberFooter() {
   197         printMemberFooter();
   198     }
   200     /**
   201      * Write the footer information. If the serilization overview section was
   202      * printed, check for definition list and close list tag.
   203      *
   204      * @param heading the heading that was written.
   205      */
   206     public void writeFooter(String heading) {
   207         if (printedOverallAnchor) {
   208             if (heading.equals(
   209                    configuration().getText("doclet.Serialized_Form_class"))) {
   210                 writer.printMemberDetailsListEndTag();
   211                 assert !writer.getMemberDetailsListPrinted();
   212             }
   213         }
   214     }
   215 }

mercurial