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

Tue, 09 Oct 2012 19:10:00 -0700

author
jjg
date
Tue, 09 Oct 2012 19:10:00 -0700
changeset 1357
c75be5bc5283
parent 995
62bc3775d5bb
child 1358
fc123bdeddb8
permissions
-rw-r--r--

8000663: clean up langtools imports
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 1997, 2012, 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  */
    26 package com.sun.tools.doclets.formats.html;
    28 import java.io.*;
    30 import com.sun.tools.doclets.formats.html.markup.*;
    31 import com.sun.tools.doclets.internal.toolkit.*;
    32 import com.sun.tools.doclets.internal.toolkit.util.*;
    34 /**
    35  * Generate File to list all the deprecated classes and class members with the
    36  * appropriate links.
    37  *
    38  * @see java.util.List
    39  * @author Atul M Dambalkar
    40  * @author Bhavesh Patel (Modified)
    41  */
    42 public class DeprecatedListWriter extends SubWriterHolderWriter {
    44     private static final String[] ANCHORS = new String[] {
    45         "package", "interface", "class", "enum", "exception", "error",
    46         "annotation_type", "field", "method", "constructor", "enum_constant",
    47         "annotation_type_member"
    48     };
    50     private static final String[] HEADING_KEYS = new String[] {
    51         "doclet.Deprecated_Packages", "doclet.Deprecated_Interfaces",
    52         "doclet.Deprecated_Classes", "doclet.Deprecated_Enums",
    53         "doclet.Deprecated_Exceptions", "doclet.Deprecated_Errors",
    54         "doclet.Deprecated_Annotation_Types",
    55         "doclet.Deprecated_Fields",
    56         "doclet.Deprecated_Methods", "doclet.Deprecated_Constructors",
    57         "doclet.Deprecated_Enum_Constants",
    58         "doclet.Deprecated_Annotation_Type_Members"
    59     };
    61     private static final String[] SUMMARY_KEYS = new String[] {
    62         "doclet.deprecated_packages", "doclet.deprecated_interfaces",
    63         "doclet.deprecated_classes", "doclet.deprecated_enums",
    64         "doclet.deprecated_exceptions", "doclet.deprecated_errors",
    65         "doclet.deprecated_annotation_types",
    66         "doclet.deprecated_fields",
    67         "doclet.deprecated_methods", "doclet.deprecated_constructors",
    68         "doclet.deprecated_enum_constants",
    69         "doclet.deprecated_annotation_type_members"
    70     };
    72     private static final String[] HEADER_KEYS = new String[] {
    73         "doclet.Package", "doclet.Interface", "doclet.Class",
    74         "doclet.Enum", "doclet.Exceptions",
    75         "doclet.Errors",
    76         "doclet.AnnotationType",
    77         "doclet.Field",
    78         "doclet.Method", "doclet.Constructor",
    79         "doclet.Enum_Constant",
    80         "doclet.Annotation_Type_Member"
    81     };
    83     private AbstractMemberWriter[] writers;
    85     private ConfigurationImpl configuration;
    87     /**
    88      * Constructor.
    89      *
    90      * @param filename the file to be generated.
    91      */
    92     public DeprecatedListWriter(ConfigurationImpl configuration,
    93                                 String filename) throws IOException {
    94         super(configuration, filename);
    95         this.configuration = configuration;
    96         NestedClassWriterImpl classW = new NestedClassWriterImpl(this);
    97         writers = new AbstractMemberWriter[]
    98             {classW, classW, classW, classW, classW, classW,
    99             new FieldWriterImpl(this),
   100             new MethodWriterImpl(this),
   101             new ConstructorWriterImpl(this),
   102             new EnumConstantWriterImpl(this),
   103             new AnnotationTypeOptionalMemberWriterImpl(this, null)};
   104     }
   106     /**
   107      * Get list of all the deprecated classes and members in all the Packages
   108      * specified on the Command Line.
   109      * Then instantiate DeprecatedListWriter and generate File.
   110      *
   111      * @param configuration the current configuration of the doclet.
   112      */
   113     public static void generate(ConfigurationImpl configuration) {
   114         String filename = "deprecated-list.html";
   115         try {
   116             DeprecatedListWriter depr =
   117                    new DeprecatedListWriter(configuration, filename);
   118             depr.generateDeprecatedListFile(
   119                    new DeprecatedAPIListBuilder(configuration));
   120             depr.close();
   121         } catch (IOException exc) {
   122             configuration.standardmessage.error(
   123                         "doclet.exception_encountered",
   124                         exc.toString(), filename);
   125             throw new DocletAbortException();
   126         }
   127     }
   129     /**
   130      * Generate the deprecated API list.
   131      *
   132      * @param deprapi list of deprecated API built already.
   133      */
   134     protected void generateDeprecatedListFile(DeprecatedAPIListBuilder deprapi)
   135             throws IOException {
   136         Content body = getHeader();
   137         body.addContent(getContentsList(deprapi));
   138         String memberTableSummary;
   139         String[] memberTableHeader = new String[1];
   140         HtmlTree div = new HtmlTree(HtmlTag.DIV);
   141         div.addStyle(HtmlStyle.contentContainer);
   142         for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) {
   143             if (deprapi.hasDocumentation(i)) {
   144                 addAnchor(deprapi, i, div);
   145                 memberTableSummary =
   146                         configuration.getText("doclet.Member_Table_Summary",
   147                         configuration.getText(HEADING_KEYS[i]),
   148                         configuration.getText(SUMMARY_KEYS[i]));
   149                 memberTableHeader[0] = configuration.getText("doclet.0_and_1",
   150                         configuration.getText(HEADER_KEYS[i]),
   151                         configuration.getText("doclet.Description"));
   152                 // DeprecatedAPIListBuilder.PACKAGE == 0, so if i == 0, it is
   153                 // a PackageDoc.
   154                 if (i == DeprecatedAPIListBuilder.PACKAGE)
   155                     addPackageDeprecatedAPI(deprapi.getList(i),
   156                             HEADING_KEYS[i], memberTableSummary, memberTableHeader, div);
   157                 else
   158                     writers[i - 1].addDeprecatedAPI(deprapi.getList(i),
   159                             HEADING_KEYS[i], memberTableSummary, memberTableHeader, div);
   160             }
   161         }
   162         body.addContent(div);
   163         addNavLinks(false, body);
   164         addBottom(body);
   165         printHtmlDocument(null, true, body);
   166     }
   168     /**
   169      * Add the index link.
   170      *
   171      * @param builder the deprecated list builder
   172      * @param type the type of list being documented
   173      * @param contentTree the content tree to which the index link will be added
   174      */
   175     private void addIndexLink(DeprecatedAPIListBuilder builder,
   176             int type, Content contentTree) {
   177         if (builder.hasDocumentation(type)) {
   178             Content li = HtmlTree.LI(getHyperLink("#" + ANCHORS[type],
   179                     getResource(HEADING_KEYS[type])));
   180             contentTree.addContent(li);
   181         }
   182     }
   184     /**
   185      * Get the contents list.
   186      *
   187      * @param deprapi the deprecated list builder
   188      * @return a content tree for the contents list
   189      */
   190     public Content getContentsList(DeprecatedAPIListBuilder deprapi) {
   191         Content headContent = getResource("doclet.Deprecated_API");
   192         Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
   193                 HtmlStyle.title, headContent);
   194         Content div = HtmlTree.DIV(HtmlStyle.header, heading);
   195         Content headingContent = getResource("doclet.Contents");
   196         div.addContent(HtmlTree.HEADING(HtmlConstants.CONTENT_HEADING, true,
   197                 headingContent));
   198         Content ul = new HtmlTree(HtmlTag.UL);
   199         for (int i = 0; i < DeprecatedAPIListBuilder.NUM_TYPES; i++) {
   200             addIndexLink(deprapi, i, ul);
   201         }
   202         div.addContent(ul);
   203         return div;
   204     }
   206     /**
   207      * Add the anchor.
   208      *
   209      * @param builder the deprecated list builder
   210      * @param type the type of list being documented
   211      * @param contentTree the content tree to which the anchor will be added
   212      */
   213     private void addAnchor(DeprecatedAPIListBuilder builder, int type, Content htmlTree) {
   214         if (builder.hasDocumentation(type)) {
   215             htmlTree.addContent(getMarkerAnchor(ANCHORS[type]));
   216         }
   217     }
   219     /**
   220      * Get the header for the deprecated API Listing.
   221      *
   222      * @return a content tree for the header
   223      */
   224     public Content getHeader() {
   225         String title = configuration.getText("doclet.Window_Deprecated_List");
   226         Content bodyTree = getBody(true, getWindowTitle(title));
   227         addTop(bodyTree);
   228         addNavLinks(true, bodyTree);
   229         return bodyTree;
   230     }
   232     /**
   233      * Get the deprecated label.
   234      *
   235      * @return a content tree for the deprecated label
   236      */
   237     protected Content getNavLinkDeprecated() {
   238         Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, deprecatedLabel);
   239         return li;
   240     }
   241 }

mercurial