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