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

Mon, 13 Dec 2010 13:44:47 -0800

author
bpatel
date
Mon, 13 Dec 2010 13:44:47 -0800
changeset 793
ffbf2b2a8611
parent 766
90af8d87741f
child 798
4868a36f6fd8
permissions
-rw-r--r--

7006270: Several javadoc regression tests are failing on windows
Reviewed-by: jjg

duke@1 1 /*
ohair@554 2 * Copyright (c) 1998, 2008, 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
duke@1 28 import java.io.*;
duke@1 29 import java.util.*;
bpatel@766 30 import com.sun.javadoc.*;
bpatel@766 31 import com.sun.tools.doclets.internal.toolkit.util.*;
bpatel@766 32 import com.sun.tools.doclets.formats.html.markup.*;
bpatel@766 33 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 34
duke@1 35 /**
duke@1 36 * Generate package usage information.
duke@1 37 *
duke@1 38 * @author Robert G. Field
bpatel@243 39 * @author Bhavesh Patel (Modified)
duke@1 40 */
duke@1 41 public class PackageUseWriter extends SubWriterHolderWriter {
duke@1 42
duke@1 43 final PackageDoc pkgdoc;
jjg@74 44 final SortedMap<String,Set<ClassDoc>> usingPackageToUsedClasses = new TreeMap<String,Set<ClassDoc>>();
duke@1 45
duke@1 46 /**
duke@1 47 * Constructor.
duke@1 48 *
duke@1 49 * @param filename the file to be generated.
duke@1 50 * @throws IOException
duke@1 51 * @throws DocletAbortException
duke@1 52 */
duke@1 53 public PackageUseWriter(ConfigurationImpl configuration,
duke@1 54 ClassUseMapper mapper, String filename,
duke@1 55 PackageDoc pkgdoc) throws IOException {
duke@1 56 super(configuration, DirectoryManager.getDirectoryPath(pkgdoc),
duke@1 57 filename,
duke@1 58 DirectoryManager.getRelativePath(pkgdoc.name()));
duke@1 59 this.pkgdoc = pkgdoc;
duke@1 60
duke@1 61 // by examining all classes in this package, find what packages
duke@1 62 // use these classes - produce a map between using package and
duke@1 63 // used classes.
duke@1 64 ClassDoc[] content = pkgdoc.allClasses();
duke@1 65 for (int i = 0; i < content.length; ++i) {
duke@1 66 ClassDoc usedClass = content[i];
jjg@74 67 Set<ClassDoc> usingClasses = mapper.classToClass.get(usedClass.qualifiedName());
duke@1 68 if (usingClasses != null) {
mcimadamore@184 69 for (Iterator<ClassDoc> it = usingClasses.iterator(); it.hasNext(); ) {
mcimadamore@184 70 ClassDoc usingClass = it.next();
duke@1 71 PackageDoc usingPackage = usingClass.containingPackage();
jjg@74 72 Set<ClassDoc> usedClasses = usingPackageToUsedClasses
duke@1 73 .get(usingPackage.name());
duke@1 74 if (usedClasses == null) {
jjg@74 75 usedClasses = new TreeSet<ClassDoc>();
duke@1 76 usingPackageToUsedClasses.put(Util.getPackageName(usingPackage),
duke@1 77 usedClasses);
duke@1 78 }
duke@1 79 usedClasses.add(usedClass);
duke@1 80 }
duke@1 81 }
duke@1 82 }
duke@1 83 }
duke@1 84
duke@1 85 /**
duke@1 86 * Generate a class page.
duke@1 87 *
duke@1 88 * @param configuration the current configuration of the doclet.
duke@1 89 * @param mapper the mapping of the class usage.
duke@1 90 * @param pkgdoc the package doc being documented.
duke@1 91 */
duke@1 92 public static void generate(ConfigurationImpl configuration,
duke@1 93 ClassUseMapper mapper, PackageDoc pkgdoc) {
duke@1 94 PackageUseWriter pkgusegen;
duke@1 95 String filename = "package-use.html";
duke@1 96 try {
duke@1 97 pkgusegen = new PackageUseWriter(configuration,
duke@1 98 mapper, filename, pkgdoc);
duke@1 99 pkgusegen.generatePackageUseFile();
duke@1 100 pkgusegen.close();
duke@1 101 } catch (IOException exc) {
duke@1 102 configuration.standardmessage.error(
duke@1 103 "doclet.exception_encountered",
duke@1 104 exc.toString(), filename);
duke@1 105 throw new DocletAbortException();
duke@1 106 }
duke@1 107 }
duke@1 108
duke@1 109
duke@1 110 /**
bpatel@766 111 * Generate the package use list.
duke@1 112 */
duke@1 113 protected void generatePackageUseFile() throws IOException {
bpatel@766 114 Content body = getPackageUseHeader();
bpatel@766 115 HtmlTree div = new HtmlTree(HtmlTag.DIV);
bpatel@766 116 div.addStyle(HtmlStyle.contentContainer);
duke@1 117 if (usingPackageToUsedClasses.isEmpty()) {
bpatel@766 118 div.addContent(getResource(
bpatel@766 119 "doclet.ClassUse_No.usage.of.0", pkgdoc.name()));
duke@1 120 } else {
bpatel@766 121 addPackageUse(div);
duke@1 122 }
bpatel@766 123 body.addContent(div);
bpatel@766 124 addNavLinks(false, body);
bpatel@766 125 addBottom(body);
bpatel@766 126 printHtmlDocument(null, true, body);
duke@1 127 }
duke@1 128
duke@1 129 /**
bpatel@766 130 * Add the package use information.
bpatel@766 131 *
bpatel@766 132 * @param contentTree the content tree to which the package use information will be added
duke@1 133 */
bpatel@766 134 protected void addPackageUse(Content contentTree) throws IOException {
bpatel@766 135 HtmlTree ul = new HtmlTree(HtmlTag.UL);
bpatel@766 136 ul.addStyle(HtmlStyle.blockList);
duke@1 137 if (configuration.packages.length > 1) {
bpatel@766 138 addPackageList(ul);
duke@1 139 }
bpatel@766 140 addClassList(ul);
bpatel@766 141 contentTree.addContent(ul);
duke@1 142 }
duke@1 143
bpatel@766 144 /**
bpatel@766 145 * Add the list of packages that use the given package.
bpatel@766 146 *
bpatel@766 147 * @param contentTree the content tree to which the package list will be added
bpatel@766 148 */
bpatel@766 149 protected void addPackageList(Content contentTree) throws IOException {
bpatel@766 150 Content table = HtmlTree.TABLE(0, 3, 0, useTableSummary,
bpatel@766 151 getTableCaption(configuration().getText(
bpatel@766 152 "doclet.ClassUse_Packages.that.use.0",
bpatel@766 153 getPackageLinkString(pkgdoc, Util.getPackageName(pkgdoc), false))));
bpatel@766 154 table.addContent(getSummaryTableHeader(packageTableHeader, "col"));
bpatel@766 155 Content tbody = new HtmlTree(HtmlTag.TBODY);
mcimadamore@184 156 Iterator<String> it = usingPackageToUsedClasses.keySet().iterator();
bpatel@766 157 for (int i = 0; it.hasNext(); i++) {
mcimadamore@184 158 PackageDoc pkg = configuration.root.packageNamed(it.next());
bpatel@766 159 HtmlTree tr = new HtmlTree(HtmlTag.TR);
bpatel@766 160 if (i % 2 == 0) {
bpatel@766 161 tr.addStyle(HtmlStyle.altColor);
bpatel@766 162 } else {
bpatel@766 163 tr.addStyle(HtmlStyle.rowColor);
bpatel@766 164 }
bpatel@766 165 addPackageUse(pkg, tr);
bpatel@766 166 tbody.addContent(tr);
duke@1 167 }
bpatel@766 168 table.addContent(tbody);
bpatel@766 169 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
bpatel@766 170 contentTree.addContent(li);
duke@1 171 }
duke@1 172
bpatel@766 173 /**
bpatel@766 174 * Add the list of classes that use the given package.
bpatel@766 175 *
bpatel@766 176 * @param contentTree the content tree to which the class list will be added
bpatel@766 177 */
bpatel@766 178 protected void addClassList(Content contentTree) throws IOException {
bpatel@243 179 String[] classTableHeader = new String[] {
bpatel@243 180 configuration.getText("doclet.0_and_1",
bpatel@243 181 configuration.getText("doclet.Class"),
bpatel@243 182 configuration.getText("doclet.Description"))
bpatel@243 183 };
mcimadamore@184 184 Iterator<String> itp = usingPackageToUsedClasses.keySet().iterator();
duke@1 185 while (itp.hasNext()) {
mcimadamore@184 186 String packageName = itp.next();
duke@1 187 PackageDoc usingPackage = configuration.root.packageNamed(packageName);
bpatel@766 188 HtmlTree li = new HtmlTree(HtmlTag.LI);
bpatel@766 189 li.addStyle(HtmlStyle.blockList);
duke@1 190 if (usingPackage != null) {
bpatel@766 191 li.addContent(getMarkerAnchor(usingPackage.name()));
duke@1 192 }
bpatel@766 193 String tableSummary = configuration.getText("doclet.Use_Table_Summary",
bpatel@766 194 configuration.getText("doclet.classes"));
bpatel@766 195 Content table = HtmlTree.TABLE(0, 3, 0, tableSummary,
bpatel@766 196 getTableCaption(configuration().getText(
bpatel@766 197 "doclet.ClassUse_Classes.in.0.used.by.1",
bpatel@766 198 getPackageLinkString(pkgdoc, Util.getPackageName(pkgdoc), false),
bpatel@766 199 getPackageLinkString(usingPackage,Util.getPackageName(usingPackage), false))));
bpatel@766 200 table.addContent(getSummaryTableHeader(classTableHeader, "col"));
bpatel@766 201 Content tbody = new HtmlTree(HtmlTag.TBODY);
mcimadamore@184 202 Iterator<ClassDoc> itc =
mcimadamore@184 203 usingPackageToUsedClasses.get(packageName).iterator();
bpatel@766 204 for (int i = 0; itc.hasNext(); i++) {
bpatel@766 205 HtmlTree tr = new HtmlTree(HtmlTag.TR);
bpatel@766 206 if (i % 2 == 0) {
bpatel@766 207 tr.addStyle(HtmlStyle.altColor);
bpatel@766 208 } else {
bpatel@766 209 tr.addStyle(HtmlStyle.rowColor);
bpatel@766 210 }
bpatel@766 211 addClassRow(itc.next(), packageName, tr);
bpatel@766 212 tbody.addContent(tr);
duke@1 213 }
bpatel@766 214 table.addContent(tbody);
bpatel@766 215 li.addContent(table);
bpatel@766 216 contentTree.addContent(li);
duke@1 217 }
duke@1 218 }
duke@1 219
bpatel@766 220 /**
bpatel@766 221 * Add a row for the class that uses the given package.
bpatel@766 222 *
bpatel@766 223 * @param usedClass the class that uses the given package
bpatel@766 224 * @param packageName the name of the package to which the class belongs
bpatel@766 225 * @param contentTree the content tree to which the row will be added
bpatel@766 226 */
bpatel@766 227 protected void addClassRow(ClassDoc usedClass, String packageName,
bpatel@766 228 Content contentTree) {
duke@1 229 String path = pathString(usedClass,
bpatel@766 230 "class-use/" + usedClass.name() + ".html");
bpatel@766 231 Content td = HtmlTree.TD(HtmlStyle.colOne,
bpatel@766 232 getHyperLink(path, packageName, new StringContent(usedClass.name())));
bpatel@766 233 addIndexComment(usedClass, td);
bpatel@766 234 contentTree.addContent(td);
duke@1 235 }
duke@1 236
duke@1 237 /**
bpatel@766 238 * Add the package use information.
bpatel@766 239 *
bpatel@766 240 * @param pkg the package that used the given package
bpatel@766 241 * @param contentTree the content tree to which the information will be added
duke@1 242 */
bpatel@766 243 protected void addPackageUse(PackageDoc pkg, Content contentTree) throws IOException {
bpatel@766 244 Content tdFirst = HtmlTree.TD(HtmlStyle.colFirst,
bpatel@766 245 getHyperLink("", pkg.name(), new StringContent(Util.getPackageName(pkg))));
bpatel@766 246 contentTree.addContent(tdFirst);
bpatel@766 247 HtmlTree tdLast = new HtmlTree(HtmlTag.TD);
bpatel@766 248 tdLast.addStyle(HtmlStyle.colLast);
bpatel@766 249 if (pkg != null)
bpatel@766 250 addSummaryComment(pkg, tdLast);
bpatel@766 251 else
bpatel@766 252 tdLast.addContent(getSpace());
bpatel@766 253 contentTree.addContent(tdLast);
duke@1 254 }
duke@1 255
duke@1 256 /**
bpatel@766 257 * Get the header for the package use listing.
bpatel@766 258 *
bpatel@766 259 * @return a content tree representing the package use header
duke@1 260 */
bpatel@766 261 protected Content getPackageUseHeader() {
bpatel@766 262 String packageText = configuration.getText("doclet.Package");
duke@1 263 String name = pkgdoc.name();
bpatel@766 264 String title = configuration.getText("doclet.Window_ClassUse_Header",
bpatel@766 265 packageText, name);
bpatel@766 266 Content bodyTree = getBody(true, getWindowTitle(title));
bpatel@766 267 addTop(bodyTree);
bpatel@766 268 addNavLinks(true, bodyTree);
bpatel@766 269 Content headContent = getResource("doclet.ClassUse_Title", packageText, name);
bpatel@766 270 Content heading = HtmlTree.HEADING(HtmlConstants.TITLE_HEADING, true,
bpatel@766 271 HtmlStyle.title, headContent);
bpatel@766 272 Content div = HtmlTree.DIV(HtmlStyle.header, heading);
bpatel@766 273 bodyTree.addContent(div);
bpatel@766 274 return bodyTree;
duke@1 275 }
duke@1 276
duke@1 277 /**
bpatel@766 278 * Get this package link.
bpatel@766 279 *
bpatel@766 280 * @return a content tree for the package link
duke@1 281 */
bpatel@766 282 protected Content getNavLinkPackage() {
bpatel@766 283 Content linkContent = getHyperLink("package-summary.html", "",
bpatel@766 284 packageLabel);
bpatel@766 285 Content li = HtmlTree.LI(linkContent);
bpatel@766 286 return li;
duke@1 287 }
duke@1 288
duke@1 289 /**
bpatel@766 290 * Get the use link.
bpatel@766 291 *
bpatel@766 292 * @return a content tree for the use link
duke@1 293 */
bpatel@766 294 protected Content getNavLinkClassUse() {
bpatel@766 295 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, useLabel);
bpatel@766 296 return li;
duke@1 297 }
duke@1 298
bpatel@766 299 /**
bpatel@766 300 * Get the tree link.
bpatel@766 301 *
bpatel@766 302 * @return a content tree for the tree link
bpatel@766 303 */
bpatel@766 304 protected Content getNavLinkTree() {
bpatel@766 305 Content linkContent = getHyperLink("package-tree.html", "",
bpatel@766 306 treeLabel);
bpatel@766 307 Content li = HtmlTree.LI(linkContent);
bpatel@766 308 return li;
duke@1 309 }
duke@1 310 }

mercurial