author | ohair |
Tue, 25 May 2010 15:54:51 -0700 | |
changeset 5520 | 86e4b9a9da40 |
parent 2320 | 5b8c377175f4 |
child 7614 | cfadc977ca75 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.doclets.formats.html; |
|
27 |
||
28 |
import com.sun.tools.doclets.internal.toolkit.util.*; |
|
29 |
import com.sun.javadoc.*; |
|
30 |
import java.io.*; |
|
31 |
import java.util.*; |
|
32 |
||
33 |
/** |
|
34 |
* Generate package usage information. |
|
35 |
* |
|
36 |
* @author Robert G. Field |
|
2320
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
37 |
* @author Bhavesh Patel (Modified) |
10 | 38 |
*/ |
39 |
public class PackageUseWriter extends SubWriterHolderWriter { |
|
40 |
||
41 |
final PackageDoc pkgdoc; |
|
868 | 42 |
final SortedMap<String,Set<ClassDoc>> usingPackageToUsedClasses = new TreeMap<String,Set<ClassDoc>>(); |
10 | 43 |
|
44 |
/** |
|
45 |
* Constructor. |
|
46 |
* |
|
47 |
* @param filename the file to be generated. |
|
48 |
* @throws IOException |
|
49 |
* @throws DocletAbortException |
|
50 |
*/ |
|
51 |
public PackageUseWriter(ConfigurationImpl configuration, |
|
52 |
ClassUseMapper mapper, String filename, |
|
53 |
PackageDoc pkgdoc) throws IOException { |
|
54 |
super(configuration, DirectoryManager.getDirectoryPath(pkgdoc), |
|
55 |
filename, |
|
56 |
DirectoryManager.getRelativePath(pkgdoc.name())); |
|
57 |
this.pkgdoc = pkgdoc; |
|
58 |
||
59 |
// by examining all classes in this package, find what packages |
|
60 |
// use these classes - produce a map between using package and |
|
61 |
// used classes. |
|
62 |
ClassDoc[] content = pkgdoc.allClasses(); |
|
63 |
for (int i = 0; i < content.length; ++i) { |
|
64 |
ClassDoc usedClass = content[i]; |
|
868 | 65 |
Set<ClassDoc> usingClasses = mapper.classToClass.get(usedClass.qualifiedName()); |
10 | 66 |
if (usingClasses != null) { |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1787
diff
changeset
|
67 |
for (Iterator<ClassDoc> it = usingClasses.iterator(); it.hasNext(); ) { |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1787
diff
changeset
|
68 |
ClassDoc usingClass = it.next(); |
10 | 69 |
PackageDoc usingPackage = usingClass.containingPackage(); |
868 | 70 |
Set<ClassDoc> usedClasses = usingPackageToUsedClasses |
10 | 71 |
.get(usingPackage.name()); |
72 |
if (usedClasses == null) { |
|
868 | 73 |
usedClasses = new TreeSet<ClassDoc>(); |
10 | 74 |
usingPackageToUsedClasses.put(Util.getPackageName(usingPackage), |
75 |
usedClasses); |
|
76 |
} |
|
77 |
usedClasses.add(usedClass); |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
} |
|
82 |
||
83 |
/** |
|
84 |
* Generate a class page. |
|
85 |
* |
|
86 |
* @param configuration the current configuration of the doclet. |
|
87 |
* @param mapper the mapping of the class usage. |
|
88 |
* @param pkgdoc the package doc being documented. |
|
89 |
*/ |
|
90 |
public static void generate(ConfigurationImpl configuration, |
|
91 |
ClassUseMapper mapper, PackageDoc pkgdoc) { |
|
92 |
PackageUseWriter pkgusegen; |
|
93 |
String filename = "package-use.html"; |
|
94 |
try { |
|
95 |
pkgusegen = new PackageUseWriter(configuration, |
|
96 |
mapper, filename, pkgdoc); |
|
97 |
pkgusegen.generatePackageUseFile(); |
|
98 |
pkgusegen.close(); |
|
99 |
} catch (IOException exc) { |
|
100 |
configuration.standardmessage.error( |
|
101 |
"doclet.exception_encountered", |
|
102 |
exc.toString(), filename); |
|
103 |
throw new DocletAbortException(); |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
||
108 |
/** |
|
109 |
* Print the class use list. |
|
110 |
*/ |
|
111 |
protected void generatePackageUseFile() throws IOException { |
|
112 |
printPackageUseHeader(); |
|
113 |
||
114 |
if (usingPackageToUsedClasses.isEmpty()) { |
|
115 |
printText("doclet.ClassUse_No.usage.of.0", pkgdoc.name()); |
|
116 |
p(); |
|
117 |
} else { |
|
118 |
generatePackageUse(); |
|
119 |
} |
|
120 |
||
121 |
printPackageUseFooter(); |
|
122 |
} |
|
123 |
||
124 |
/** |
|
125 |
* Print the class use list. |
|
126 |
*/ |
|
127 |
protected void generatePackageUse() throws IOException { |
|
128 |
if (configuration.packages.length > 1) { |
|
129 |
generatePackageList(); |
|
130 |
} |
|
131 |
generateClassList(); |
|
132 |
} |
|
133 |
||
134 |
protected void generatePackageList() throws IOException { |
|
2320
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
135 |
tableIndexSummary(useTableSummary); |
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
136 |
tableCaptionStart(); |
10 | 137 |
printText("doclet.ClassUse_Packages.that.use.0", |
138 |
getPackageLink(pkgdoc, Util.getPackageName(pkgdoc), false)); |
|
2320
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
139 |
tableCaptionEnd(); |
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
140 |
summaryTableHeader(packageTableHeader, "col"); |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1787
diff
changeset
|
141 |
Iterator<String> it = usingPackageToUsedClasses.keySet().iterator(); |
10 | 142 |
while (it.hasNext()) { |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1787
diff
changeset
|
143 |
PackageDoc pkg = configuration.root.packageNamed(it.next()); |
10 | 144 |
generatePackageUse(pkg); |
145 |
} |
|
146 |
tableEnd(); |
|
147 |
space(); |
|
148 |
p(); |
|
149 |
} |
|
150 |
||
151 |
protected void generateClassList() throws IOException { |
|
2320
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
152 |
String[] classTableHeader = new String[] { |
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
153 |
configuration.getText("doclet.0_and_1", |
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
154 |
configuration.getText("doclet.Class"), |
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
155 |
configuration.getText("doclet.Description")) |
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
156 |
}; |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1787
diff
changeset
|
157 |
Iterator<String> itp = usingPackageToUsedClasses.keySet().iterator(); |
10 | 158 |
while (itp.hasNext()) { |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1787
diff
changeset
|
159 |
String packageName = itp.next(); |
10 | 160 |
PackageDoc usingPackage = configuration.root.packageNamed(packageName); |
161 |
if (usingPackage != null) { |
|
162 |
anchor(usingPackage.name()); |
|
163 |
} |
|
2320
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
164 |
tableIndexSummary(configuration.getText("doclet.Use_Table_Summary", |
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
165 |
configuration.getText("doclet.classes"))); |
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
166 |
tableCaptionStart(); |
10 | 167 |
printText("doclet.ClassUse_Classes.in.0.used.by.1", |
168 |
getPackageLink(pkgdoc, Util.getPackageName(pkgdoc), false), |
|
169 |
getPackageLink(usingPackage,Util.getPackageName(usingPackage), false)); |
|
2320
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
170 |
tableCaptionEnd(); |
5b8c377175f4
6786688: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Table must have captions and headers
bpatel
parents:
1789
diff
changeset
|
171 |
summaryTableHeader(classTableHeader, "col"); |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1787
diff
changeset
|
172 |
Iterator<ClassDoc> itc = |
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1787
diff
changeset
|
173 |
usingPackageToUsedClasses.get(packageName).iterator(); |
10 | 174 |
while (itc.hasNext()) { |
1789
7ac8c0815000
6765045: Remove rawtypes warnings from langtools
mcimadamore
parents:
1787
diff
changeset
|
175 |
printClassRow(itc.next(), packageName); |
10 | 176 |
} |
177 |
tableEnd(); |
|
178 |
space(); |
|
179 |
p(); |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
protected void printClassRow(ClassDoc usedClass, String packageName) { |
|
184 |
String path = pathString(usedClass, |
|
185 |
"class-use/" + usedClass.name() + ".html"); |
|
186 |
||
187 |
trBgcolorStyle("white", "TableRowColor"); |
|
188 |
summaryRow(0); |
|
1787
1aa079321cd2
6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents:
1264
diff
changeset
|
189 |
strong(); |
10 | 190 |
printHyperLink(path, packageName, usedClass.name(), true); |
1787
1aa079321cd2
6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents:
1264
diff
changeset
|
191 |
strongEnd(); |
10 | 192 |
println(); br(); |
193 |
printNbsps(); |
|
194 |
printIndexComment(usedClass); |
|
195 |
summaryRowEnd(); |
|
196 |
trEnd(); |
|
197 |
} |
|
198 |
||
199 |
/** |
|
200 |
* Print the package use list. |
|
201 |
*/ |
|
202 |
protected void generatePackageUse(PackageDoc pkg) throws IOException { |
|
203 |
trBgcolorStyle("white", "TableRowColor"); |
|
204 |
summaryRow(0); |
|
205 |
//Just want an anchor here. |
|
206 |
printHyperLink("", pkg.name(), Util.getPackageName(pkg), true); |
|
207 |
summaryRowEnd(); |
|
208 |
summaryRow(0); |
|
209 |
if (pkg != null) { |
|
210 |
printSummaryComment(pkg); |
|
211 |
} |
|
212 |
space(); |
|
213 |
summaryRowEnd(); |
|
214 |
trEnd(); |
|
215 |
} |
|
216 |
||
217 |
/** |
|
218 |
* Print the header for the class use Listing. |
|
219 |
*/ |
|
220 |
protected void printPackageUseHeader() { |
|
221 |
String packageLabel = configuration.getText("doclet.Package"); |
|
222 |
String name = pkgdoc.name(); |
|
223 |
printHtmlHeader(configuration.getText("doclet.Window_ClassUse_Header", |
|
224 |
packageLabel, name), null, true); |
|
225 |
printTop(); |
|
226 |
navLinks(true); |
|
227 |
hr(); |
|
228 |
center(); |
|
229 |
h2(); |
|
1787
1aa079321cd2
6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents:
1264
diff
changeset
|
230 |
strongText("doclet.ClassUse_Title", packageLabel, name); |
10 | 231 |
h2End(); |
232 |
centerEnd(); |
|
233 |
} |
|
234 |
||
235 |
/** |
|
236 |
* Print the footer for the class use Listing. |
|
237 |
*/ |
|
238 |
protected void printPackageUseFooter() { |
|
239 |
hr(); |
|
240 |
navLinks(false); |
|
241 |
printBottom(); |
|
242 |
printBodyHtmlEnd(); |
|
243 |
} |
|
244 |
||
245 |
||
246 |
/** |
|
247 |
* Print this package link |
|
248 |
*/ |
|
249 |
protected void navLinkPackage() { |
|
250 |
navCellStart(); |
|
251 |
printHyperLink("package-summary.html", "", configuration.getText("doclet.Package"), |
|
252 |
true, "NavBarFont1"); |
|
253 |
navCellEnd(); |
|
254 |
} |
|
255 |
||
256 |
/** |
|
257 |
* Print class use link |
|
258 |
*/ |
|
259 |
protected void navLinkClassUse() { |
|
260 |
navCellRevStart(); |
|
261 |
fontStyle("NavBarFont1Rev"); |
|
1787
1aa079321cd2
6786028: Javadoc HTML WCAG 2.0 accessibility issues in standard doclet - Bold tags should be strong
bpatel
parents:
1264
diff
changeset
|
262 |
strongText("doclet.navClassUse"); |
10 | 263 |
fontEnd(); |
264 |
navCellEnd(); |
|
265 |
} |
|
266 |
||
267 |
protected void navLinkTree() { |
|
268 |
navCellStart(); |
|
269 |
printHyperLink("package-tree.html", "", configuration.getText("doclet.Tree"), |
|
270 |
true, "NavBarFont1"); |
|
271 |
navCellEnd(); |
|
272 |
} |
|
273 |
||
274 |
} |