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

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

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 import java.util.*;
aoqi@0 30
aoqi@0 31 import com.sun.javadoc.*;
aoqi@0 32 import com.sun.tools.doclets.formats.html.markup.*;
aoqi@0 33 import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0 34 import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0 35
aoqi@0 36 /**
aoqi@0 37 * Class to generate file for each package contents in the right-hand
aoqi@0 38 * frame. This will list all the Class Kinds in the package. A click on any
aoqi@0 39 * class-kind will update the frame with the clicked class-kind page.
aoqi@0 40 *
aoqi@0 41 * <p><b>This is NOT part of any supported API.
aoqi@0 42 * If you write code that depends on this, you do so at your own risk.
aoqi@0 43 * This code and its internal interfaces are subject to change or
aoqi@0 44 * deletion without notice.</b>
aoqi@0 45 *
aoqi@0 46 * @author Atul M Dambalkar
aoqi@0 47 * @author Bhavesh Patel (Modified)
aoqi@0 48 */
aoqi@0 49 public class PackageWriterImpl extends HtmlDocletWriter
aoqi@0 50 implements PackageSummaryWriter {
aoqi@0 51
aoqi@0 52 /**
aoqi@0 53 * The prev package name in the alpha-order list.
aoqi@0 54 */
aoqi@0 55 protected PackageDoc prev;
aoqi@0 56
aoqi@0 57 /**
aoqi@0 58 * The next package name in the alpha-order list.
aoqi@0 59 */
aoqi@0 60 protected PackageDoc next;
aoqi@0 61
aoqi@0 62 /**
aoqi@0 63 * The package being documented.
aoqi@0 64 */
aoqi@0 65 protected PackageDoc packageDoc;
aoqi@0 66
aoqi@0 67 /**
aoqi@0 68 * Constructor to construct PackageWriter object and to generate
aoqi@0 69 * "package-summary.html" file in the respective package directory.
aoqi@0 70 * For example for package "java.lang" this will generate file
aoqi@0 71 * "package-summary.html" file in the "java/lang" directory. It will also
aoqi@0 72 * create "java/lang" directory in the current or the destination directory
aoqi@0 73 * if it doesn't exist.
aoqi@0 74 *
aoqi@0 75 * @param configuration the configuration of the doclet.
aoqi@0 76 * @param packageDoc PackageDoc under consideration.
aoqi@0 77 * @param prev Previous package in the sorted array.
aoqi@0 78 * @param next Next package in the sorted array.
aoqi@0 79 */
aoqi@0 80 public PackageWriterImpl(ConfigurationImpl configuration,
aoqi@0 81 PackageDoc packageDoc, PackageDoc prev, PackageDoc next)
aoqi@0 82 throws IOException {
aoqi@0 83 super(configuration, DocPath.forPackage(packageDoc).resolve(DocPaths.PACKAGE_SUMMARY));
aoqi@0 84 this.prev = prev;
aoqi@0 85 this.next = next;
aoqi@0 86 this.packageDoc = packageDoc;
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 /**
aoqi@0 90 * {@inheritDoc}
aoqi@0 91 */
aoqi@0 92 public Content getPackageHeader(String heading) {
aoqi@0 93 String pkgName = packageDoc.name();
aoqi@0 94 Content bodyTree = getBody(true, getWindowTitle(pkgName));
aoqi@0 95 addTop(bodyTree);
aoqi@0 96 addNavLinks(true, bodyTree);
aoqi@0 97 HtmlTree div = new HtmlTree(HtmlTag.DIV);
aoqi@0 98 div.addStyle(HtmlStyle.header);
aoqi@0 99 Content annotationContent = new HtmlTree(HtmlTag.P);
aoqi@0 100 addAnnotationInfo(packageDoc, annotationContent);
aoqi@0 101 div.addContent(annotationContent);
aoqi@0 102 Content tHeading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
aoqi@0 103 HtmlStyle.title, packageLabel);
aoqi@0 104 tHeading.addContent(getSpace());
aoqi@0 105 Content packageHead = new StringContent(heading);
aoqi@0 106 tHeading.addContent(packageHead);
aoqi@0 107 div.addContent(tHeading);
aoqi@0 108 addDeprecationInfo(div);
aoqi@0 109 if (packageDoc.inlineTags().length > 0 && ! configuration.nocomment) {
aoqi@0 110 HtmlTree docSummaryDiv = new HtmlTree(HtmlTag.DIV);
aoqi@0 111 docSummaryDiv.addStyle(HtmlStyle.docSummary);
aoqi@0 112 addSummaryComment(packageDoc, docSummaryDiv);
aoqi@0 113 div.addContent(docSummaryDiv);
aoqi@0 114 Content space = getSpace();
aoqi@0 115 Content descLink = getHyperLink(getDocLink(
aoqi@0 116 SectionName.PACKAGE_DESCRIPTION),
aoqi@0 117 descriptionLabel, "", "");
aoqi@0 118 Content descPara = new HtmlTree(HtmlTag.P, seeLabel, space, descLink);
aoqi@0 119 div.addContent(descPara);
aoqi@0 120 }
aoqi@0 121 bodyTree.addContent(div);
aoqi@0 122 return bodyTree;
aoqi@0 123 }
aoqi@0 124
aoqi@0 125 /**
aoqi@0 126 * {@inheritDoc}
aoqi@0 127 */
aoqi@0 128 public Content getContentHeader() {
aoqi@0 129 HtmlTree div = new HtmlTree(HtmlTag.DIV);
aoqi@0 130 div.addStyle(HtmlStyle.contentContainer);
aoqi@0 131 return div;
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 /**
aoqi@0 135 * Add the package deprecation information to the documentation tree.
aoqi@0 136 *
aoqi@0 137 * @param div the content tree to which the deprecation information will be added
aoqi@0 138 */
aoqi@0 139 public void addDeprecationInfo(Content div) {
aoqi@0 140 Tag[] deprs = packageDoc.tags("deprecated");
aoqi@0 141 if (Util.isDeprecated(packageDoc)) {
aoqi@0 142 HtmlTree deprDiv = new HtmlTree(HtmlTag.DIV);
aoqi@0 143 deprDiv.addStyle(HtmlStyle.deprecatedContent);
aoqi@0 144 Content deprPhrase = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase);
aoqi@0 145 deprDiv.addContent(deprPhrase);
aoqi@0 146 if (deprs.length > 0) {
aoqi@0 147 Tag[] commentTags = deprs[0].inlineTags();
aoqi@0 148 if (commentTags.length > 0) {
aoqi@0 149 addInlineDeprecatedComment(packageDoc, deprs[0], deprDiv);
aoqi@0 150 }
aoqi@0 151 }
aoqi@0 152 div.addContent(deprDiv);
aoqi@0 153 }
aoqi@0 154 }
aoqi@0 155
aoqi@0 156 /**
aoqi@0 157 * {@inheritDoc}
aoqi@0 158 */
aoqi@0 159 public Content getSummaryHeader() {
aoqi@0 160 HtmlTree ul = new HtmlTree(HtmlTag.UL);
aoqi@0 161 ul.addStyle(HtmlStyle.blockList);
aoqi@0 162 return ul;
aoqi@0 163 }
aoqi@0 164
aoqi@0 165 /**
aoqi@0 166 * {@inheritDoc}
aoqi@0 167 */
aoqi@0 168 public void addClassesSummary(ClassDoc[] classes, String label,
aoqi@0 169 String tableSummary, String[] tableHeader, Content summaryContentTree) {
aoqi@0 170 if(classes.length > 0) {
aoqi@0 171 Arrays.sort(classes);
aoqi@0 172 Content caption = getTableCaption(new RawHtml(label));
aoqi@0 173 Content table = HtmlTree.TABLE(HtmlStyle.typeSummary, 0, 3, 0,
aoqi@0 174 tableSummary, caption);
aoqi@0 175 table.addContent(getSummaryTableHeader(tableHeader, "col"));
aoqi@0 176 Content tbody = new HtmlTree(HtmlTag.TBODY);
aoqi@0 177 for (int i = 0; i < classes.length; i++) {
aoqi@0 178 if (!Util.isCoreClass(classes[i]) ||
aoqi@0 179 !configuration.isGeneratedDoc(classes[i])) {
aoqi@0 180 continue;
aoqi@0 181 }
aoqi@0 182 Content classContent = getLink(new LinkInfoImpl(
aoqi@0 183 configuration, LinkInfoImpl.Kind.PACKAGE, classes[i]));
aoqi@0 184 Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
aoqi@0 185 HtmlTree tr = HtmlTree.TR(tdClass);
aoqi@0 186 if (i%2 == 0)
aoqi@0 187 tr.addStyle(HtmlStyle.altColor);
aoqi@0 188 else
aoqi@0 189 tr.addStyle(HtmlStyle.rowColor);
aoqi@0 190 HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD);
aoqi@0 191 tdClassDescription.addStyle(HtmlStyle.colLast);
aoqi@0 192 if (Util.isDeprecated(classes[i])) {
aoqi@0 193 tdClassDescription.addContent(deprecatedLabel);
aoqi@0 194 if (classes[i].tags("deprecated").length > 0) {
aoqi@0 195 addSummaryDeprecatedComment(classes[i],
aoqi@0 196 classes[i].tags("deprecated")[0], tdClassDescription);
aoqi@0 197 }
aoqi@0 198 }
aoqi@0 199 else
aoqi@0 200 addSummaryComment(classes[i], tdClassDescription);
aoqi@0 201 tr.addContent(tdClassDescription);
aoqi@0 202 tbody.addContent(tr);
aoqi@0 203 }
aoqi@0 204 table.addContent(tbody);
aoqi@0 205 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
aoqi@0 206 summaryContentTree.addContent(li);
aoqi@0 207 }
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 /**
aoqi@0 211 * {@inheritDoc}
aoqi@0 212 */
aoqi@0 213 public void addPackageDescription(Content packageContentTree) {
aoqi@0 214 if (packageDoc.inlineTags().length > 0) {
aoqi@0 215 packageContentTree.addContent(
aoqi@0 216 getMarkerAnchor(SectionName.PACKAGE_DESCRIPTION));
aoqi@0 217 Content h2Content = new StringContent(
aoqi@0 218 configuration.getText("doclet.Package_Description",
aoqi@0 219 packageDoc.name()));
aoqi@0 220 packageContentTree.addContent(HtmlTree.HEADING(HtmlConstants.PACKAGE_HEADING,
aoqi@0 221 true, h2Content));
aoqi@0 222 addInlineComment(packageDoc, packageContentTree);
aoqi@0 223 }
aoqi@0 224 }
aoqi@0 225
aoqi@0 226 /**
aoqi@0 227 * {@inheritDoc}
aoqi@0 228 */
aoqi@0 229 public void addPackageTags(Content packageContentTree) {
aoqi@0 230 addTagsInfo(packageDoc, packageContentTree);
aoqi@0 231 }
aoqi@0 232
aoqi@0 233 /**
aoqi@0 234 * {@inheritDoc}
aoqi@0 235 */
aoqi@0 236 public void addPackageFooter(Content contentTree) {
aoqi@0 237 addNavLinks(false, contentTree);
aoqi@0 238 addBottom(contentTree);
aoqi@0 239 }
aoqi@0 240
aoqi@0 241 /**
aoqi@0 242 * {@inheritDoc}
aoqi@0 243 */
aoqi@0 244 public void printDocument(Content contentTree) throws IOException {
aoqi@0 245 printHtmlDocument(configuration.metakeywords.getMetaKeywords(packageDoc),
aoqi@0 246 true, contentTree);
aoqi@0 247 }
aoqi@0 248
aoqi@0 249 /**
aoqi@0 250 * Get "Use" link for this pacakge in the navigation bar.
aoqi@0 251 *
aoqi@0 252 * @return a content tree for the class use link
aoqi@0 253 */
aoqi@0 254 protected Content getNavLinkClassUse() {
aoqi@0 255 Content useLink = getHyperLink(DocPaths.PACKAGE_USE,
aoqi@0 256 useLabel, "", "");
aoqi@0 257 Content li = HtmlTree.LI(useLink);
aoqi@0 258 return li;
aoqi@0 259 }
aoqi@0 260
aoqi@0 261 /**
aoqi@0 262 * Get "PREV PACKAGE" link in the navigation bar.
aoqi@0 263 *
aoqi@0 264 * @return a content tree for the previous link
aoqi@0 265 */
aoqi@0 266 public Content getNavLinkPrevious() {
aoqi@0 267 Content li;
aoqi@0 268 if (prev == null) {
aoqi@0 269 li = HtmlTree.LI(prevpackageLabel);
aoqi@0 270 } else {
aoqi@0 271 DocPath path = DocPath.relativePath(packageDoc, prev);
aoqi@0 272 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
aoqi@0 273 prevpackageLabel, "", ""));
aoqi@0 274 }
aoqi@0 275 return li;
aoqi@0 276 }
aoqi@0 277
aoqi@0 278 /**
aoqi@0 279 * Get "NEXT PACKAGE" link in the navigation bar.
aoqi@0 280 *
aoqi@0 281 * @return a content tree for the next link
aoqi@0 282 */
aoqi@0 283 public Content getNavLinkNext() {
aoqi@0 284 Content li;
aoqi@0 285 if (next == null) {
aoqi@0 286 li = HtmlTree.LI(nextpackageLabel);
aoqi@0 287 } else {
aoqi@0 288 DocPath path = DocPath.relativePath(packageDoc, next);
aoqi@0 289 li = HtmlTree.LI(getHyperLink(path.resolve(DocPaths.PACKAGE_SUMMARY),
aoqi@0 290 nextpackageLabel, "", ""));
aoqi@0 291 }
aoqi@0 292 return li;
aoqi@0 293 }
aoqi@0 294
aoqi@0 295 /**
aoqi@0 296 * Get "Tree" link in the navigation bar. This will be link to the package
aoqi@0 297 * tree file.
aoqi@0 298 *
aoqi@0 299 * @return a content tree for the tree link
aoqi@0 300 */
aoqi@0 301 protected Content getNavLinkTree() {
aoqi@0 302 Content useLink = getHyperLink(DocPaths.PACKAGE_TREE,
aoqi@0 303 treeLabel, "", "");
aoqi@0 304 Content li = HtmlTree.LI(useLink);
aoqi@0 305 return li;
aoqi@0 306 }
aoqi@0 307
aoqi@0 308 /**
aoqi@0 309 * Highlight "Package" in the navigation bar, as this is the package page.
aoqi@0 310 *
aoqi@0 311 * @return a content tree for the package link
aoqi@0 312 */
aoqi@0 313 protected Content getNavLinkPackage() {
aoqi@0 314 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, packageLabel);
aoqi@0 315 return li;
aoqi@0 316 }
aoqi@0 317 }

mercurial