Sun, 11 Apr 2010 23:24:24 -0700
6875904: Java 7 message synchronization 1
Reviewed-by: ogino, faryad
1 /*
2 * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
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
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
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 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
26 package com.sun.tools.doclets.formats.html;
28 import com.sun.tools.doclets.internal.toolkit.util.*;
29 import com.sun.javadoc.*;
30 import java.io.*;
31 import java.util.*;
33 /**
34 * Generate class usage information.
35 *
36 * @author Robert G. Field
37 * @author Bhavesh Patel (Modified)
38 */
39 public class ClassUseWriter extends SubWriterHolderWriter {
41 final ClassDoc classdoc;
42 Set<PackageDoc> pkgToPackageAnnotations = null;
43 final Map<String,List<ProgramElementDoc>> pkgToClassTypeParameter;
44 final Map<String,List<ProgramElementDoc>> pkgToClassAnnotations;
45 final Map<String,List<ProgramElementDoc>> pkgToMethodTypeParameter;
46 final Map<String,List<ProgramElementDoc>> pkgToMethodArgTypeParameter;
47 final Map<String,List<ProgramElementDoc>> pkgToMethodReturnTypeParameter;
48 final Map<String,List<ProgramElementDoc>> pkgToMethodAnnotations;
49 final Map<String,List<ProgramElementDoc>> pkgToMethodParameterAnnotations;
50 final Map<String,List<ProgramElementDoc>> pkgToFieldTypeParameter;
51 final Map<String,List<ProgramElementDoc>> pkgToFieldAnnotations;
52 final Map<String,List<ProgramElementDoc>> pkgToSubclass;
53 final Map<String,List<ProgramElementDoc>> pkgToSubinterface;
54 final Map<String,List<ProgramElementDoc>> pkgToImplementingClass;
55 final Map<String,List<ProgramElementDoc>> pkgToField;
56 final Map<String,List<ProgramElementDoc>> pkgToMethodReturn;
57 final Map<String,List<ProgramElementDoc>> pkgToMethodArgs;
58 final Map<String,List<ProgramElementDoc>> pkgToMethodThrows;
59 final Map<String,List<ProgramElementDoc>> pkgToConstructorAnnotations;
60 final Map<String,List<ProgramElementDoc>> pkgToConstructorParameterAnnotations;
61 final Map<String,List<ProgramElementDoc>> pkgToConstructorArgs;
62 final Map<String,List<ProgramElementDoc>> pkgToConstructorArgTypeParameter;
63 final Map<String,List<ProgramElementDoc>> pkgToConstructorThrows;
64 final SortedSet<PackageDoc> pkgSet;
65 final MethodWriterImpl methodSubWriter;
66 final ConstructorWriterImpl constrSubWriter;
67 final FieldWriterImpl fieldSubWriter;
68 final NestedClassWriterImpl classSubWriter;
69 // Summary for various use tables.
70 final String classUseTableSummary;
71 final String subclassUseTableSummary;
72 final String subinterfaceUseTableSummary;
73 final String fieldUseTableSummary;
74 final String methodUseTableSummary;
75 final String constructorUseTableSummary;
78 /**
79 * Constructor.
80 *
81 * @param filename the file to be generated.
82 * @throws IOException
83 * @throws DocletAbortException
84 */
85 public ClassUseWriter(ConfigurationImpl configuration,
86 ClassUseMapper mapper, String path,
87 String filename, String relpath,
88 ClassDoc classdoc) throws IOException {
89 super(configuration, path, filename, relpath);
90 this.classdoc = classdoc;
91 if (mapper.classToPackageAnnotations.containsKey(classdoc.qualifiedName()))
92 pkgToPackageAnnotations = new HashSet<PackageDoc>(mapper.classToPackageAnnotations.get(classdoc.qualifiedName()));
93 configuration.currentcd = classdoc;
94 this.pkgSet = new TreeSet<PackageDoc>();
95 this.pkgToClassTypeParameter = pkgDivide(mapper.classToClassTypeParam);
96 this.pkgToClassAnnotations = pkgDivide(mapper.classToClassAnnotations);
97 this.pkgToMethodTypeParameter = pkgDivide(mapper.classToExecMemberDocTypeParam);
98 this.pkgToMethodArgTypeParameter = pkgDivide(mapper.classToExecMemberDocArgTypeParam);
99 this.pkgToFieldTypeParameter = pkgDivide(mapper.classToFieldDocTypeParam);
100 this.pkgToFieldAnnotations = pkgDivide(mapper.annotationToFieldDoc);
101 this.pkgToMethodReturnTypeParameter = pkgDivide(mapper.classToExecMemberDocReturnTypeParam);
102 this.pkgToMethodAnnotations = pkgDivide(mapper.classToExecMemberDocAnnotations);
103 this.pkgToMethodParameterAnnotations = pkgDivide(mapper.classToExecMemberDocParamAnnotation);
104 this.pkgToSubclass = pkgDivide(mapper.classToSubclass);
105 this.pkgToSubinterface = pkgDivide(mapper.classToSubinterface);
106 this.pkgToImplementingClass = pkgDivide(mapper.classToImplementingClass);
107 this.pkgToField = pkgDivide(mapper.classToField);
108 this.pkgToMethodReturn = pkgDivide(mapper.classToMethodReturn);
109 this.pkgToMethodArgs = pkgDivide(mapper.classToMethodArgs);
110 this.pkgToMethodThrows = pkgDivide(mapper.classToMethodThrows);
111 this.pkgToConstructorAnnotations = pkgDivide(mapper.classToConstructorAnnotations);
112 this.pkgToConstructorParameterAnnotations = pkgDivide(mapper.classToConstructorParamAnnotation);
113 this.pkgToConstructorArgs = pkgDivide(mapper.classToConstructorArgs);
114 this.pkgToConstructorArgTypeParameter = pkgDivide(mapper.classToConstructorDocArgTypeParam);
115 this.pkgToConstructorThrows = pkgDivide(mapper.classToConstructorThrows);
116 //tmp test
117 if (pkgSet.size() > 0 &&
118 mapper.classToPackage.containsKey(classdoc.qualifiedName()) &&
119 !pkgSet.equals(mapper.classToPackage.get(classdoc.qualifiedName()))) {
120 configuration.root.printWarning("Internal error: package sets don't match: " + pkgSet + " with: " +
121 mapper.classToPackage.get(classdoc.qualifiedName()));
122 }
123 methodSubWriter = new MethodWriterImpl(this);
124 constrSubWriter = new ConstructorWriterImpl(this);
125 fieldSubWriter = new FieldWriterImpl(this);
126 classSubWriter = new NestedClassWriterImpl(this);
127 classUseTableSummary = configuration.getText("doclet.Use_Table_Summary",
128 configuration.getText("doclet.classes"));
129 subclassUseTableSummary = configuration.getText("doclet.Use_Table_Summary",
130 configuration.getText("doclet.subclasses"));
131 subinterfaceUseTableSummary = configuration.getText("doclet.Use_Table_Summary",
132 configuration.getText("doclet.subinterfaces"));
133 fieldUseTableSummary = configuration.getText("doclet.Use_Table_Summary",
134 configuration.getText("doclet.fields"));
135 methodUseTableSummary = configuration.getText("doclet.Use_Table_Summary",
136 configuration.getText("doclet.methods"));
137 constructorUseTableSummary = configuration.getText("doclet.Use_Table_Summary",
138 configuration.getText("doclet.constructors"));
139 }
141 /**
142 * Write out class use pages.
143 * @throws DocletAbortException
144 */
145 public static void generate(ConfigurationImpl configuration,
146 ClassTree classtree) {
147 ClassUseMapper mapper = new ClassUseMapper(configuration.root, classtree);
148 ClassDoc[] classes = configuration.root.classes();
149 for (int i = 0; i < classes.length; i++) {
150 ClassUseWriter.generate(configuration, mapper, classes[i]);
151 }
152 PackageDoc[] pkgs = configuration.packages;
153 for (int i = 0; i < pkgs.length; i++) {
154 PackageUseWriter.generate(configuration, mapper, pkgs[i]);
155 }
156 }
158 private Map<String,List<ProgramElementDoc>> pkgDivide(Map<String,? extends List<? extends ProgramElementDoc>> classMap) {
159 Map<String,List<ProgramElementDoc>> map = new HashMap<String,List<ProgramElementDoc>>();
160 List<? extends ProgramElementDoc> list= classMap.get(classdoc.qualifiedName());
161 if (list != null) {
162 Collections.sort(list);
163 Iterator<? extends ProgramElementDoc> it = list.iterator();
164 while (it.hasNext()) {
165 ProgramElementDoc doc = it.next();
166 PackageDoc pkg = doc.containingPackage();
167 pkgSet.add(pkg);
168 List<ProgramElementDoc> inPkg = map.get(pkg.name());
169 if (inPkg == null) {
170 inPkg = new ArrayList<ProgramElementDoc>();
171 map.put(pkg.name(), inPkg);
172 }
173 inPkg.add(doc);
174 }
175 }
176 return map;
177 }
179 /**
180 * Generate a class page.
181 */
182 public static void generate(ConfigurationImpl configuration,
183 ClassUseMapper mapper, ClassDoc classdoc) {
184 ClassUseWriter clsgen;
185 String path = DirectoryManager.getDirectoryPath(classdoc.
186 containingPackage());
187 if (path.length() > 0) {
188 path += File.separator;
189 }
190 path += "class-use";
191 String filename = classdoc.name() + ".html";
192 String pkgname = classdoc.containingPackage().name();
193 pkgname += (pkgname.length() > 0)? ".class-use": "class-use";
194 String relpath = DirectoryManager.getRelativePath(pkgname);
195 try {
196 clsgen = new ClassUseWriter(configuration,
197 mapper, path, filename,
198 relpath, classdoc);
199 clsgen.generateClassUseFile();
200 clsgen.close();
201 } catch (IOException exc) {
202 configuration.standardmessage.
203 error("doclet.exception_encountered",
204 exc.toString(), filename);
205 throw new DocletAbortException();
206 }
207 }
209 /**
210 * Print the class use list.
211 */
212 protected void generateClassUseFile() throws IOException {
214 printClassUseHeader();
216 if (pkgSet.size() > 0) {
217 generateClassUse();
218 } else {
219 printText("doclet.ClassUse_No.usage.of.0",
220 classdoc.qualifiedName());
221 p();
222 }
224 printClassUseFooter();
225 }
227 protected void generateClassUse() throws IOException {
228 if (configuration.packages.length > 1) {
229 generatePackageList();
230 generatePackageAnnotationList();
231 }
232 generateClassList();
233 }
235 protected void generatePackageList() throws IOException {
236 tableIndexSummary(useTableSummary);
237 tableCaptionStart();
238 printText("doclet.ClassUse_Packages.that.use.0",
239 getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CLASS_USE_HEADER, classdoc,
240 false)));
241 tableCaptionEnd();
242 summaryTableHeader(packageTableHeader, "col");
244 for (Iterator<PackageDoc> it = pkgSet.iterator(); it.hasNext();) {
245 PackageDoc pkg = it.next();
246 generatePackageUse(pkg);
247 }
248 tableEnd();
249 space();
250 p();
251 }
253 protected void generatePackageAnnotationList() throws IOException {
254 if ((! classdoc.isAnnotationType()) ||
255 pkgToPackageAnnotations == null ||
256 pkgToPackageAnnotations.size() == 0)
257 return;
258 tableIndexSummary(useTableSummary);
259 tableCaptionStart();
260 printText("doclet.ClassUse_PackageAnnotation",
261 getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CLASS_USE_HEADER, classdoc,
262 false)));
263 tableCaptionEnd();
264 summaryTableHeader(packageTableHeader, "col");
265 for (Iterator<PackageDoc> it = pkgToPackageAnnotations.iterator(); it.hasNext();) {
266 PackageDoc pkg = it.next();
267 trBgcolorStyle("white", "TableRowColor");
268 summaryRow(0);
269 //Just want an anchor here.
270 printPackageLink(pkg, pkg.name(), true);
271 summaryRowEnd();
272 summaryRow(0);
273 printSummaryComment(pkg);
274 space();
275 summaryRowEnd();
276 trEnd();
277 }
278 tableEnd();
279 space();
280 p();
281 }
283 protected void generateClassList() throws IOException {
284 for (Iterator<PackageDoc> it = pkgSet.iterator(); it.hasNext();) {
285 PackageDoc pkg = it.next();
286 anchor(pkg.name());
287 tableIndexSummary();
288 tableHeaderStart("#CCCCFF");
289 printText("doclet.ClassUse_Uses.of.0.in.1",
290 getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CLASS_USE_HEADER,
291 classdoc, false)),
292 getPackageLink(pkg, Util.getPackageName(pkg), false));
293 tableHeaderEnd();
294 tableEnd();
295 space();
296 p();
297 generateClassUse(pkg);
298 }
299 }
301 /**
302 * Print the package use list.
303 */
304 protected void generatePackageUse(PackageDoc pkg) throws IOException {
305 trBgcolorStyle("white", "TableRowColor");
306 summaryRow(0);
307 //Just want an anchor here.
308 printHyperLink("", pkg.name(), Util.getPackageName(pkg), true);
309 summaryRowEnd();
310 summaryRow(0);
311 printSummaryComment(pkg);
312 space();
313 summaryRowEnd();
314 trEnd();
315 }
317 /**
318 * Print the class use list.
319 */
320 protected void generateClassUse(PackageDoc pkg) throws IOException {
321 String classLink = getLink(new LinkInfoImpl(
322 LinkInfoImpl.CONTEXT_CLASS_USE_HEADER, classdoc, false));
323 String pkgLink = getPackageLink(pkg, Util.getPackageName(pkg), false);
324 classSubWriter.printUseInfo(pkgToClassAnnotations.get(pkg.name()),
325 configuration.getText("doclet.ClassUse_Annotation", classLink,
326 pkgLink), classUseTableSummary);
327 classSubWriter.printUseInfo(pkgToClassTypeParameter.get(pkg.name()),
328 configuration.getText("doclet.ClassUse_TypeParameter", classLink,
329 pkgLink), classUseTableSummary);
330 classSubWriter.printUseInfo(pkgToSubclass.get(pkg.name()),
331 configuration.getText("doclet.ClassUse_Subclass", classLink,
332 pkgLink), subclassUseTableSummary);
333 classSubWriter.printUseInfo(pkgToSubinterface.get(pkg.name()),
334 configuration.getText("doclet.ClassUse_Subinterface", classLink,
335 pkgLink), subinterfaceUseTableSummary);
336 classSubWriter.printUseInfo(pkgToImplementingClass.get(pkg.name()),
337 configuration.getText("doclet.ClassUse_ImplementingClass", classLink,
338 pkgLink), classUseTableSummary);
339 fieldSubWriter.printUseInfo(pkgToField.get(pkg.name()),
340 configuration.getText("doclet.ClassUse_Field", classLink,
341 pkgLink), fieldUseTableSummary);
342 fieldSubWriter.printUseInfo(pkgToFieldAnnotations.get(pkg.name()),
343 configuration.getText("doclet.ClassUse_FieldAnnotations", classLink,
344 pkgLink), fieldUseTableSummary);
345 fieldSubWriter.printUseInfo(pkgToFieldTypeParameter.get(pkg.name()),
346 configuration.getText("doclet.ClassUse_FieldTypeParameter", classLink,
347 pkgLink), fieldUseTableSummary);
348 methodSubWriter.printUseInfo(pkgToMethodAnnotations.get(pkg.name()),
349 configuration.getText("doclet.ClassUse_MethodAnnotations", classLink,
350 pkgLink), methodUseTableSummary);
351 methodSubWriter.printUseInfo(pkgToMethodParameterAnnotations.get(pkg.name()),
352 configuration.getText("doclet.ClassUse_MethodParameterAnnotations", classLink,
353 pkgLink), methodUseTableSummary);
354 methodSubWriter.printUseInfo(pkgToMethodTypeParameter.get(pkg.name()),
355 configuration.getText("doclet.ClassUse_MethodTypeParameter", classLink,
356 pkgLink), methodUseTableSummary);
357 methodSubWriter.printUseInfo(pkgToMethodReturn.get(pkg.name()),
358 configuration.getText("doclet.ClassUse_MethodReturn", classLink,
359 pkgLink), methodUseTableSummary);
360 methodSubWriter.printUseInfo(pkgToMethodReturnTypeParameter.get(pkg.name()),
361 configuration.getText("doclet.ClassUse_MethodReturnTypeParameter", classLink,
362 pkgLink), methodUseTableSummary);
363 methodSubWriter.printUseInfo(pkgToMethodArgs.get(pkg.name()),
364 configuration.getText("doclet.ClassUse_MethodArgs", classLink,
365 pkgLink), methodUseTableSummary);
366 methodSubWriter.printUseInfo(pkgToMethodArgTypeParameter.get(pkg.name()),
367 configuration.getText("doclet.ClassUse_MethodArgsTypeParameters", classLink,
368 pkgLink), methodUseTableSummary);
369 methodSubWriter.printUseInfo(pkgToMethodThrows.get(pkg.name()),
370 configuration.getText("doclet.ClassUse_MethodThrows", classLink,
371 pkgLink), methodUseTableSummary);
372 constrSubWriter.printUseInfo(pkgToConstructorAnnotations.get(pkg.name()),
373 configuration.getText("doclet.ClassUse_ConstructorAnnotations", classLink,
374 pkgLink), constructorUseTableSummary);
375 constrSubWriter.printUseInfo(pkgToConstructorParameterAnnotations.get(pkg.name()),
376 configuration.getText("doclet.ClassUse_ConstructorParameterAnnotations", classLink,
377 pkgLink), constructorUseTableSummary);
378 constrSubWriter.printUseInfo(pkgToConstructorArgs.get(pkg.name()),
379 configuration.getText("doclet.ClassUse_ConstructorArgs", classLink,
380 pkgLink), constructorUseTableSummary);
381 constrSubWriter.printUseInfo(pkgToConstructorArgTypeParameter.get(pkg.name()),
382 configuration.getText("doclet.ClassUse_ConstructorArgsTypeParameters", classLink,
383 pkgLink), constructorUseTableSummary);
384 constrSubWriter.printUseInfo(pkgToConstructorThrows.get(pkg.name()),
385 configuration.getText("doclet.ClassUse_ConstructorThrows", classLink,
386 pkgLink), constructorUseTableSummary);
387 }
389 /**
390 * Print the header for the class use Listing.
391 */
392 protected void printClassUseHeader() {
393 String cltype = configuration.getText(classdoc.isInterface()?
394 "doclet.Interface":
395 "doclet.Class");
396 String clname = classdoc.qualifiedName();
397 printHtmlHeader(configuration.getText("doclet.Window_ClassUse_Header",
398 cltype, clname), null, true);
399 printTop();
400 navLinks(true);
401 hr();
402 center();
403 h2();
404 strongText("doclet.ClassUse_Title", cltype, clname);
405 h2End();
406 centerEnd();
407 }
409 /**
410 * Print the footer for the class use Listing.
411 */
412 protected void printClassUseFooter() {
413 hr();
414 navLinks(false);
415 printBottom();
416 printBodyHtmlEnd();
417 }
420 /**
421 * Print this package link
422 */
423 protected void navLinkPackage() {
424 navCellStart();
425 printHyperLink("../package-summary.html", "",
426 configuration.getText("doclet.Package"), true, "NavBarFont1");
427 navCellEnd();
428 }
430 /**
431 * Print class page indicator
432 */
433 protected void navLinkClass() {
434 navCellStart();
435 printLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_CLASS_USE_HEADER, classdoc, "",
436 configuration.getText("doclet.Class"), true, "NavBarFont1"));
437 navCellEnd();
438 }
440 /**
441 * Print class use link
442 */
443 protected void navLinkClassUse() {
444 navCellRevStart();
445 fontStyle("NavBarFont1Rev");
446 strongText("doclet.navClassUse");
447 fontEnd();
448 navCellEnd();
449 }
451 protected void navLinkTree() {
452 navCellStart();
453 if (classdoc.containingPackage().isIncluded()) {
454 printHyperLink("../package-tree.html", "",
455 configuration.getText("doclet.Tree"), true, "NavBarFont1");
456 } else {
457 printHyperLink(relativePath + "overview-tree.html", "",
458 configuration.getText("doclet.Tree"), true, "NavBarFont1");
459 }
460 navCellEnd();
461 }
463 }