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

mercurial