23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package jdk.javadoc.internal.doclets.formats.html; |
26 package jdk.javadoc.internal.doclets.formats.html; |
27 |
27 |
28 import java.io.IOException; |
|
29 import java.util.ArrayList; |
28 import java.util.ArrayList; |
30 import java.util.Collections; |
29 import java.util.Collections; |
31 import java.util.HashMap; |
30 import java.util.HashMap; |
32 import java.util.List; |
31 import java.util.List; |
33 import java.util.Map; |
32 import java.util.Map; |
45 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; |
44 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; |
46 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; |
45 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; |
47 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; |
46 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; |
48 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; |
47 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent; |
49 import jdk.javadoc.internal.doclets.toolkit.Content; |
48 import jdk.javadoc.internal.doclets.toolkit.Content; |
50 import jdk.javadoc.internal.doclets.toolkit.Messages; |
|
51 import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; |
49 import jdk.javadoc.internal.doclets.toolkit.util.ClassTree; |
52 import jdk.javadoc.internal.doclets.toolkit.util.ClassUseMapper; |
50 import jdk.javadoc.internal.doclets.toolkit.util.ClassUseMapper; |
|
51 import jdk.javadoc.internal.doclets.toolkit.util.DocFileIOException; |
53 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
52 import jdk.javadoc.internal.doclets.toolkit.util.DocPath; |
54 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
53 import jdk.javadoc.internal.doclets.toolkit.util.DocPaths; |
55 import jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException; |
|
56 |
54 |
57 /** |
55 /** |
58 * Generate class usage information. |
56 * Generate class usage information. |
59 * |
57 * |
60 * <p><b>This is NOT part of any supported API. |
58 * <p><b>This is NOT part of any supported API. |
110 |
108 |
111 /** |
109 /** |
112 * Constructor. |
110 * Constructor. |
113 * |
111 * |
114 * @param filename the file to be generated. |
112 * @param filename the file to be generated. |
115 * @throws IOException |
|
116 * @throws DocletAbortException |
|
117 */ |
113 */ |
118 public ClassUseWriter(ConfigurationImpl configuration, |
114 public ClassUseWriter(ConfigurationImpl configuration, |
119 ClassUseMapper mapper, DocPath filename, |
115 ClassUseMapper mapper, DocPath filename, |
120 TypeElement typeElement) throws IOException { |
116 TypeElement typeElement) { |
121 super(configuration, filename); |
117 super(configuration, filename); |
122 this.typeElement = typeElement; |
118 this.typeElement = typeElement; |
123 if (mapper.classToPackageAnnotations.containsKey(typeElement)) { |
119 if (mapper.classToPackageAnnotations.containsKey(typeElement)) { |
124 pkgToPackageAnnotations = new TreeSet<>(utils.makeClassUseComparator()); |
120 pkgToPackageAnnotations = new TreeSet<>(utils.makeClassUseComparator()); |
125 pkgToPackageAnnotations.addAll(mapper.classToPackageAnnotations.get(typeElement)); |
121 pkgToPackageAnnotations.addAll(mapper.classToPackageAnnotations.get(typeElement)); |
173 configuration.getText("doclet.constructors")); |
169 configuration.getText("doclet.constructors")); |
174 } |
170 } |
175 |
171 |
176 /** |
172 /** |
177 * Write out class use pages. |
173 * Write out class use pages. |
178 * @throws DocletAbortException |
174 * |
179 */ |
175 * @param configuration the configuration for this doclet |
180 public static void generate(ConfigurationImpl configuration, ClassTree classtree) { |
176 * @param classtree the class tree hierarchy |
|
177 * @throws DocFileIOException if there is an error while generating the documentation |
|
178 */ |
|
179 public static void generate(ConfigurationImpl configuration, ClassTree classtree) throws DocFileIOException { |
181 ClassUseMapper mapper = new ClassUseMapper(configuration, classtree); |
180 ClassUseMapper mapper = new ClassUseMapper(configuration, classtree); |
182 for (TypeElement aClass : configuration.docEnv.getIncludedTypeElements()) { |
181 for (TypeElement aClass : configuration.docEnv.getIncludedTypeElements()) { |
183 // If -nodeprecated option is set and the containing package is marked |
182 // If -nodeprecated option is set and the containing package is marked |
184 // as deprecated, do not generate the class-use page. We will still generate |
183 // as deprecated, do not generate the class-use page. We will still generate |
185 // the class-use page if the class is marked as deprecated but the containing |
184 // the class-use page if the class is marked as deprecated but the containing |
215 return map; |
214 return map; |
216 } |
215 } |
217 |
216 |
218 /** |
217 /** |
219 * Generate a class page. |
218 * Generate a class page. |
|
219 * |
|
220 * @throws DocFileIOException if there is a problem while generating the documentation |
220 */ |
221 */ |
221 public static void generate(ConfigurationImpl configuration, ClassUseMapper mapper, |
222 public static void generate(ConfigurationImpl configuration, ClassUseMapper mapper, |
222 TypeElement typeElement) { |
223 TypeElement typeElement) throws DocFileIOException { |
223 ClassUseWriter clsgen; |
224 ClassUseWriter clsgen; |
224 DocPath path = DocPath.forPackage(configuration.utils, typeElement) |
225 DocPath path = DocPath.forPackage(configuration.utils, typeElement) |
225 .resolve(DocPaths.CLASS_USE) |
226 .resolve(DocPaths.CLASS_USE) |
226 .resolve(DocPath.forName(configuration.utils, typeElement)); |
227 .resolve(DocPath.forName(configuration.utils, typeElement)); |
227 try { |
228 clsgen = new ClassUseWriter(configuration, mapper, path, typeElement); |
228 clsgen = new ClassUseWriter(configuration, mapper, path, typeElement); |
229 clsgen.generateClassUseFile(); |
229 clsgen.generateClassUseFile(); |
|
230 } catch (IOException exc) { |
|
231 Messages messages = configuration.getMessages(); |
|
232 messages.error("doclet.exception_encountered", |
|
233 exc.toString(), path.getPath()); |
|
234 throw new DocletAbortException(exc); |
|
235 } |
|
236 } |
230 } |
237 |
231 |
238 /** |
232 /** |
239 * Generate the class use elements. |
233 * Generate the class use elements. |
240 */ |
234 * |
241 protected void generateClassUseFile() throws IOException { |
235 * @throws DocFileIOException if there is a problem while generating the documentation |
|
236 */ |
|
237 protected void generateClassUseFile() throws DocFileIOException { |
242 HtmlTree body = getClassUseHeader(); |
238 HtmlTree body = getClassUseHeader(); |
243 HtmlTree div = new HtmlTree(HtmlTag.DIV); |
239 HtmlTree div = new HtmlTree(HtmlTag.DIV); |
244 div.addStyle(HtmlStyle.classUseContainer); |
240 div.addStyle(HtmlStyle.classUseContainer); |
245 if (pkgSet.size() > 0) { |
241 if (pkgSet.size() > 0) { |
246 addClassUse(div); |
242 addClassUse(div); |
268 /** |
264 /** |
269 * Add the class use documentation. |
265 * Add the class use documentation. |
270 * |
266 * |
271 * @param contentTree the content tree to which the class use information will be added |
267 * @param contentTree the content tree to which the class use information will be added |
272 */ |
268 */ |
273 protected void addClassUse(Content contentTree) throws IOException { |
269 protected void addClassUse(Content contentTree) { |
274 HtmlTree ul = new HtmlTree(HtmlTag.UL); |
270 HtmlTree ul = new HtmlTree(HtmlTag.UL); |
275 ul.addStyle(HtmlStyle.blockList); |
271 ul.addStyle(HtmlStyle.blockList); |
276 if (configuration.packages.size() > 1) { |
272 if (configuration.packages.size() > 1) { |
277 addPackageList(ul); |
273 addPackageList(ul); |
278 addPackageAnnotationList(ul); |
274 addPackageAnnotationList(ul); |
284 /** |
280 /** |
285 * Add the packages elements that use the given class. |
281 * Add the packages elements that use the given class. |
286 * |
282 * |
287 * @param contentTree the content tree to which the packages elements will be added |
283 * @param contentTree the content tree to which the packages elements will be added |
288 */ |
284 */ |
289 protected void addPackageList(Content contentTree) throws IOException { |
285 protected void addPackageList(Content contentTree) { |
290 Content caption = getTableCaption(configuration.getContent( |
286 Content caption = getTableCaption(configuration.getContent( |
291 "doclet.ClassUse_Packages.that.use.0", |
287 "doclet.ClassUse_Packages.that.use.0", |
292 getLink(new LinkInfoImpl(configuration, |
288 getLink(new LinkInfoImpl(configuration, |
293 LinkInfoImpl.Kind.CLASS_USE_HEADER, typeElement)))); |
289 LinkInfoImpl.Kind.CLASS_USE_HEADER, typeElement)))); |
294 Content table = (configuration.isOutputHtml5()) |
290 Content table = (configuration.isOutputHtml5()) |
312 /** |
308 /** |
313 * Add the package annotation elements. |
309 * Add the package annotation elements. |
314 * |
310 * |
315 * @param contentTree the content tree to which the package annotation elements will be added |
311 * @param contentTree the content tree to which the package annotation elements will be added |
316 */ |
312 */ |
317 protected void addPackageAnnotationList(Content contentTree) throws IOException { |
313 protected void addPackageAnnotationList(Content contentTree) { |
318 if (!utils.isAnnotationType(typeElement) || |
314 if (!utils.isAnnotationType(typeElement) || |
319 pkgToPackageAnnotations == null || |
315 pkgToPackageAnnotations == null || |
320 pkgToPackageAnnotations.isEmpty()) { |
316 pkgToPackageAnnotations.isEmpty()) { |
321 return; |
317 return; |
322 } |
318 } |
350 /** |
346 /** |
351 * Add the class elements that use the given class. |
347 * Add the class elements that use the given class. |
352 * |
348 * |
353 * @param contentTree the content tree to which the class elements will be added |
349 * @param contentTree the content tree to which the class elements will be added |
354 */ |
350 */ |
355 protected void addClassList(Content contentTree) throws IOException { |
351 protected void addClassList(Content contentTree) { |
356 HtmlTree ul = new HtmlTree(HtmlTag.UL); |
352 HtmlTree ul = new HtmlTree(HtmlTag.UL); |
357 ul.addStyle(HtmlStyle.blockList); |
353 ul.addStyle(HtmlStyle.blockList); |
358 for (PackageElement pkg : pkgSet) { |
354 for (PackageElement pkg : pkgSet) { |
359 Content markerAnchor = getMarkerAnchor(getPackageAnchorName(pkg)); |
355 Content markerAnchor = getMarkerAnchor(getPackageAnchorName(pkg)); |
360 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.SECTION)) |
356 HtmlTree htmlTree = (configuration.allowTag(HtmlTag.SECTION)) |
381 * Add the package use information. |
377 * Add the package use information. |
382 * |
378 * |
383 * @param pkg the package that uses the given class |
379 * @param pkg the package that uses the given class |
384 * @param contentTree the content tree to which the package use information will be added |
380 * @param contentTree the content tree to which the package use information will be added |
385 */ |
381 */ |
386 protected void addPackageUse(PackageElement pkg, Content contentTree) throws IOException { |
382 protected void addPackageUse(PackageElement pkg, Content contentTree) { |
387 Content tdFirst = HtmlTree.TD(HtmlStyle.colFirst, |
383 Content tdFirst = HtmlTree.TD(HtmlStyle.colFirst, |
388 getHyperLink(getPackageAnchorName(pkg), new StringContent(utils.getPackageName(pkg)))); |
384 getHyperLink(getPackageAnchorName(pkg), new StringContent(utils.getPackageName(pkg)))); |
389 contentTree.addContent(tdFirst); |
385 contentTree.addContent(tdFirst); |
390 HtmlTree tdLast = new HtmlTree(HtmlTag.TD); |
386 HtmlTree tdLast = new HtmlTree(HtmlTag.TD); |
391 tdLast.addStyle(HtmlStyle.colLast); |
387 tdLast.addStyle(HtmlStyle.colLast); |
397 * Add the class use information. |
393 * Add the class use information. |
398 * |
394 * |
399 * @param pkg the package that uses the given class |
395 * @param pkg the package that uses the given class |
400 * @param contentTree the content tree to which the class use information will be added |
396 * @param contentTree the content tree to which the class use information will be added |
401 */ |
397 */ |
402 protected void addClassUse(PackageElement pkg, Content contentTree) throws IOException { |
398 protected void addClassUse(PackageElement pkg, Content contentTree) { |
403 Content classLink = getLink(new LinkInfoImpl(configuration, |
399 Content classLink = getLink(new LinkInfoImpl(configuration, |
404 LinkInfoImpl.Kind.CLASS_USE_HEADER, typeElement)); |
400 LinkInfoImpl.Kind.CLASS_USE_HEADER, typeElement)); |
405 Content pkgLink = getPackageLink(pkg, utils.getPackageName(pkg)); |
401 Content pkgLink = getPackageLink(pkg, utils.getPackageName(pkg)); |
406 classSubWriter.addUseInfo(pkgToClassAnnotations.get(pkg), |
402 classSubWriter.addUseInfo(pkgToClassAnnotations.get(pkg), |
407 configuration.getContent("doclet.ClassUse_Annotation", classLink, |
403 configuration.getContent("doclet.ClassUse_Annotation", classLink, |