Tue, 14 May 2013 13:55:35 -0700
8014557: Mutable static field in HtmlDocletWriter
Reviewed-by: ksrini
1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 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.
24 */
26 package com.sun.tools.doclets.formats.html;
28 import java.io.*;
29 import java.text.SimpleDateFormat;
30 import java.util.*;
32 import com.sun.javadoc.*;
33 import com.sun.tools.doclets.formats.html.markup.*;
34 import com.sun.tools.doclets.internal.toolkit.*;
35 import com.sun.tools.doclets.internal.toolkit.taglets.*;
36 import com.sun.tools.doclets.internal.toolkit.util.*;
38 /**
39 * Class for the Html Format Code Generation specific to JavaDoc.
40 * This Class contains methods related to the Html Code Generation which
41 * are used extensively while generating the entire documentation.
42 *
43 * <p><b>This is NOT part of any supported API.
44 * If you write code that depends on this, you do so at your own risk.
45 * This code and its internal interfaces are subject to change or
46 * deletion without notice.</b>
47 *
48 * @since 1.2
49 * @author Atul M Dambalkar
50 * @author Robert Field
51 * @author Bhavesh Patel (Modified)
52 */
53 public class HtmlDocletWriter extends HtmlDocWriter {
55 /**
56 * Relative path from the file getting generated to the destination
57 * directory. For example, if the file getting generated is
58 * "java/lang/Object.html", then the path to the root is "../..".
59 * This string can be empty if the file getting generated is in
60 * the destination directory.
61 */
62 public final DocPath pathToRoot;
64 /**
65 * Platform-independent path from the current or the
66 * destination directory to the file getting generated.
67 * Used when creating the file.
68 */
69 public final DocPath path;
71 /**
72 * Name of the file getting generated. If the file getting generated is
73 * "java/lang/Object.html", then the filename is "Object.html".
74 */
75 public final DocPath filename;
77 /**
78 * The global configuration information for this run.
79 */
80 public final ConfigurationImpl configuration;
82 /**
83 * To check whether annotation heading is printed or not.
84 */
85 protected boolean printedAnnotationHeading = false;
87 /**
88 * To check whether the repeated annotations is documented or not.
89 */
90 private boolean isAnnotationDocumented = false;
92 /**
93 * To check whether the container annotations is documented or not.
94 */
95 private boolean isContainerDocumented = false;
97 /**
98 * Constructor to construct the HtmlStandardWriter object.
99 *
100 * @param path File to be generated.
101 */
102 public HtmlDocletWriter(ConfigurationImpl configuration, DocPath path)
103 throws IOException {
104 super(configuration, path);
105 this.configuration = configuration;
106 this.path = path;
107 this.pathToRoot = path.parent().invert();
108 this.filename = path.basename();
109 }
111 /**
112 * Replace {@docRoot} tag used in options that accept HTML text, such
113 * as -header, -footer, -top and -bottom, and when converting a relative
114 * HREF where commentTagsToString inserts a {@docRoot} where one was
115 * missing. (Also see DocRootTaglet for {@docRoot} tags in doc
116 * comments.)
117 * <p>
118 * Replace {@docRoot} tag in htmlstr with the relative path to the
119 * destination directory from the directory where the file is being
120 * written, looping to handle all such tags in htmlstr.
121 * <p>
122 * For example, for "-d docs" and -header containing {@docRoot}, when
123 * the HTML page for source file p/C1.java is being generated, the
124 * {@docRoot} tag would be inserted into the header as "../",
125 * the relative path from docs/p/ to docs/ (the document root).
126 * <p>
127 * Note: This doc comment was written with '&#064;' representing '@'
128 * to prevent the inline tag from being interpreted.
129 */
130 public String replaceDocRootDir(String htmlstr) {
131 // Return if no inline tags exist
132 int index = htmlstr.indexOf("{@");
133 if (index < 0) {
134 return htmlstr;
135 }
136 String lowerHtml = htmlstr.toLowerCase();
137 // Return index of first occurrence of {@docroot}
138 // Note: {@docRoot} is not case sensitive when passed in w/command line option
139 index = lowerHtml.indexOf("{@docroot}", index);
140 if (index < 0) {
141 return htmlstr;
142 }
143 StringBuilder buf = new StringBuilder();
144 int previndex = 0;
145 while (true) {
146 if (configuration.docrootparent.length() > 0) {
147 final String docroot_parent = "{@docroot}/..";
148 // Search for lowercase version of {@docRoot}/..
149 index = lowerHtml.indexOf(docroot_parent, previndex);
150 // If next {@docRoot}/.. pattern not found, append rest of htmlstr and exit loop
151 if (index < 0) {
152 buf.append(htmlstr.substring(previndex));
153 break;
154 }
155 // If next {@docroot}/.. pattern found, append htmlstr up to start of tag
156 buf.append(htmlstr.substring(previndex, index));
157 previndex = index + docroot_parent.length();
158 // Insert docrootparent absolute path where {@docRoot}/.. was located
160 buf.append(configuration.docrootparent);
161 // Append slash if next character is not a slash
162 if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
163 buf.append('/');
164 }
165 } else {
166 final String docroot = "{@docroot}";
167 // Search for lowercase version of {@docRoot}
168 index = lowerHtml.indexOf(docroot, previndex);
169 // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
170 if (index < 0) {
171 buf.append(htmlstr.substring(previndex));
172 break;
173 }
174 // If next {@docroot} tag found, append htmlstr up to start of tag
175 buf.append(htmlstr.substring(previndex, index));
176 previndex = index + docroot.length();
177 // Insert relative path where {@docRoot} was located
178 buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath());
179 // Append slash if next character is not a slash
180 if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
181 buf.append('/');
182 }
183 }
184 }
185 return buf.toString();
186 }
188 /**
189 * Get the script to show or hide the All classes link.
190 *
191 * @param id id of the element to show or hide
192 * @return a content tree for the script
193 */
194 public Content getAllClassesLinkScript(String id) {
195 HtmlTree script = new HtmlTree(HtmlTag.SCRIPT);
196 script.addAttr(HtmlAttr.TYPE, "text/javascript");
197 String scriptCode = "<!--" + DocletConstants.NL +
198 " allClassesLink = document.getElementById(\"" + id + "\");" + DocletConstants.NL +
199 " if(window==top) {" + DocletConstants.NL +
200 " allClassesLink.style.display = \"block\";" + DocletConstants.NL +
201 " }" + DocletConstants.NL +
202 " else {" + DocletConstants.NL +
203 " allClassesLink.style.display = \"none\";" + DocletConstants.NL +
204 " }" + DocletConstants.NL +
205 " //-->" + DocletConstants.NL;
206 Content scriptContent = new RawHtml(scriptCode);
207 script.addContent(scriptContent);
208 Content div = HtmlTree.DIV(script);
209 return div;
210 }
212 /**
213 * Add method information.
214 *
215 * @param method the method to be documented
216 * @param dl the content tree to which the method information will be added
217 */
218 private void addMethodInfo(MethodDoc method, Content dl) {
219 ClassDoc[] intfacs = method.containingClass().interfaces();
220 MethodDoc overriddenMethod = method.overriddenMethod();
221 // Check whether there is any implementation or overridden info to be
222 // printed. If no overridden or implementation info needs to be
223 // printed, do not print this section.
224 if ((intfacs.length > 0 &&
225 new ImplementedMethods(method, this.configuration).build().length > 0) ||
226 overriddenMethod != null) {
227 MethodWriterImpl.addImplementsInfo(this, method, dl);
228 if (overriddenMethod != null) {
229 MethodWriterImpl.addOverridden(this,
230 method.overriddenType(), overriddenMethod, dl);
231 }
232 }
233 }
235 /**
236 * Adds the tags information.
237 *
238 * @param doc the doc for which the tags will be generated
239 * @param htmltree the documentation tree to which the tags will be added
240 */
241 protected void addTagsInfo(Doc doc, Content htmltree) {
242 if (configuration.nocomment) {
243 return;
244 }
245 Content dl = new HtmlTree(HtmlTag.DL);
246 if (doc instanceof MethodDoc) {
247 addMethodInfo((MethodDoc) doc, dl);
248 }
249 Content output = new ContentBuilder();
250 TagletWriter.genTagOuput(configuration.tagletManager, doc,
251 configuration.tagletManager.getCustomTaglets(doc),
252 getTagletWriterInstance(false), output);
253 dl.addContent(output);
254 htmltree.addContent(dl);
255 }
257 /**
258 * Check whether there are any tags for Serialization Overview
259 * section to be printed.
260 *
261 * @param field the FieldDoc object to check for tags.
262 * @return true if there are tags to be printed else return false.
263 */
264 protected boolean hasSerializationOverviewTags(FieldDoc field) {
265 Content output = new ContentBuilder();
266 TagletWriter.genTagOuput(configuration.tagletManager, field,
267 configuration.tagletManager.getCustomTaglets(field),
268 getTagletWriterInstance(false), output);
269 return !output.isEmpty();
270 }
272 /**
273 * Returns a TagletWriter that knows how to write HTML.
274 *
275 * @return a TagletWriter that knows how to write HTML.
276 */
277 public TagletWriter getTagletWriterInstance(boolean isFirstSentence) {
278 return new TagletWriterImpl(this, isFirstSentence);
279 }
281 /**
282 * Get Package link, with target frame.
283 *
284 * @param pd The link will be to the "package-summary.html" page for this package
285 * @param target name of the target frame
286 * @param label tag for the link
287 * @return a content for the target package link
288 */
289 public Content getTargetPackageLink(PackageDoc pd, String target,
290 Content label) {
291 return getHyperLink(pathString(pd, DocPaths.PACKAGE_SUMMARY), label, "", target);
292 }
294 /**
295 * Get Profile Package link, with target frame.
296 *
297 * @param pd the packageDoc object
298 * @param target name of the target frame
299 * @param label tag for the link
300 * @param profileName the name of the profile being documented
301 * @return a content for the target profile packages link
302 */
303 public Content getTargetProfilePackageLink(PackageDoc pd, String target,
304 Content label, String profileName) {
305 return getHyperLink(pathString(pd, DocPaths.profilePackageSummary(profileName)),
306 label, "", target);
307 }
309 /**
310 * Get Profile link, with target frame.
311 *
312 * @param target name of the target frame
313 * @param label tag for the link
314 * @param profileName the name of the profile being documented
315 * @return a content for the target profile link
316 */
317 public Content getTargetProfileLink(String target, Content label,
318 String profileName) {
319 return getHyperLink(pathToRoot.resolve(
320 DocPaths.profileSummary(profileName)), label, "", target);
321 }
323 /**
324 * Get the type name for profile search.
325 *
326 * @param cd the classDoc object for which the type name conversion is needed
327 * @return a type name string for the type
328 */
329 public String getTypeNameForProfile(ClassDoc cd) {
330 StringBuilder typeName =
331 new StringBuilder((cd.containingPackage()).name().replace(".", "/"));
332 typeName.append("/")
333 .append(cd.name().replace(".", "$"));
334 return typeName.toString();
335 }
337 /**
338 * Check if a type belongs to a profile.
339 *
340 * @param cd the classDoc object that needs to be checked
341 * @param profileValue the profile in which the type needs to be checked
342 * @return true if the type is in the profile
343 */
344 public boolean isTypeInProfile(ClassDoc cd, int profileValue) {
345 return (configuration.profiles.getProfile(getTypeNameForProfile(cd)) <= profileValue);
346 }
348 public void addClassesSummary(ClassDoc[] classes, String label,
349 String tableSummary, String[] tableHeader, Content summaryContentTree,
350 int profileValue) {
351 if(classes.length > 0) {
352 Arrays.sort(classes);
353 Content caption = getTableCaption(new RawHtml(label));
354 Content table = HtmlTree.TABLE(HtmlStyle.packageSummary, 0, 3, 0,
355 tableSummary, caption);
356 table.addContent(getSummaryTableHeader(tableHeader, "col"));
357 Content tbody = new HtmlTree(HtmlTag.TBODY);
358 for (int i = 0; i < classes.length; i++) {
359 if (!isTypeInProfile(classes[i], profileValue)) {
360 continue;
361 }
362 if (!Util.isCoreClass(classes[i]) ||
363 !configuration.isGeneratedDoc(classes[i])) {
364 continue;
365 }
366 Content classContent = getLink(new LinkInfoImpl(
367 configuration, LinkInfoImpl.Kind.PACKAGE, classes[i]));
368 Content tdClass = HtmlTree.TD(HtmlStyle.colFirst, classContent);
369 HtmlTree tr = HtmlTree.TR(tdClass);
370 if (i%2 == 0)
371 tr.addStyle(HtmlStyle.altColor);
372 else
373 tr.addStyle(HtmlStyle.rowColor);
374 HtmlTree tdClassDescription = new HtmlTree(HtmlTag.TD);
375 tdClassDescription.addStyle(HtmlStyle.colLast);
376 if (Util.isDeprecated(classes[i])) {
377 tdClassDescription.addContent(deprecatedLabel);
378 if (classes[i].tags("deprecated").length > 0) {
379 addSummaryDeprecatedComment(classes[i],
380 classes[i].tags("deprecated")[0], tdClassDescription);
381 }
382 }
383 else
384 addSummaryComment(classes[i], tdClassDescription);
385 tr.addContent(tdClassDescription);
386 tbody.addContent(tr);
387 }
388 table.addContent(tbody);
389 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
390 summaryContentTree.addContent(li);
391 }
392 }
394 /**
395 * Generates the HTML document tree and prints it out.
396 *
397 * @param metakeywords Array of String keywords for META tag. Each element
398 * of the array is assigned to a separate META tag.
399 * Pass in null for no array
400 * @param includeScript true if printing windowtitle script
401 * false for files that appear in the left-hand frames
402 * @param body the body htmltree to be included in the document
403 */
404 public void printHtmlDocument(String[] metakeywords, boolean includeScript,
405 Content body) throws IOException {
406 Content htmlDocType = DocType.TRANSITIONAL;
407 Content htmlComment = new Comment(configuration.getText("doclet.New_Page"));
408 Content head = new HtmlTree(HtmlTag.HEAD);
409 if (!configuration.notimestamp) {
410 Content headComment = new Comment(getGeneratedByString());
411 head.addContent(headComment);
412 }
413 if (configuration.charset.length() > 0) {
414 Content meta = HtmlTree.META("Content-Type", "text/html",
415 configuration.charset);
416 head.addContent(meta);
417 }
418 head.addContent(getTitle());
419 if (!configuration.notimestamp) {
420 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
421 Content meta = HtmlTree.META("date", dateFormat.format(new Date()));
422 head.addContent(meta);
423 }
424 if (metakeywords != null) {
425 for (int i=0; i < metakeywords.length; i++) {
426 Content meta = HtmlTree.META("keywords", metakeywords[i]);
427 head.addContent(meta);
428 }
429 }
430 head.addContent(getStyleSheetProperties());
431 head.addContent(getScriptProperties());
432 Content htmlTree = HtmlTree.HTML(configuration.getLocale().getLanguage(),
433 head, body);
434 Content htmlDocument = new HtmlDocument(htmlDocType,
435 htmlComment, htmlTree);
436 write(htmlDocument);
437 }
439 /**
440 * Get the window title.
441 *
442 * @param title the title string to construct the complete window title
443 * @return the window title string
444 */
445 public String getWindowTitle(String title) {
446 if (configuration.windowtitle.length() > 0) {
447 title += " (" + configuration.windowtitle + ")";
448 }
449 return title;
450 }
452 /**
453 * Get user specified header and the footer.
454 *
455 * @param header if true print the user provided header else print the
456 * user provided footer.
457 */
458 public Content getUserHeaderFooter(boolean header) {
459 String content;
460 if (header) {
461 content = replaceDocRootDir(configuration.header);
462 } else {
463 if (configuration.footer.length() != 0) {
464 content = replaceDocRootDir(configuration.footer);
465 } else {
466 content = replaceDocRootDir(configuration.header);
467 }
468 }
469 Content rawContent = new RawHtml(content);
470 Content em = HtmlTree.EM(rawContent);
471 return em;
472 }
474 /**
475 * Adds the user specified top.
476 *
477 * @param body the content tree to which user specified top will be added
478 */
479 public void addTop(Content body) {
480 Content top = new RawHtml(replaceDocRootDir(configuration.top));
481 body.addContent(top);
482 }
484 /**
485 * Adds the user specified bottom.
486 *
487 * @param body the content tree to which user specified bottom will be added
488 */
489 public void addBottom(Content body) {
490 Content bottom = new RawHtml(replaceDocRootDir(configuration.bottom));
491 Content small = HtmlTree.SMALL(bottom);
492 Content p = HtmlTree.P(HtmlStyle.legalCopy, small);
493 body.addContent(p);
494 }
496 /**
497 * Adds the navigation bar for the Html page at the top and and the bottom.
498 *
499 * @param header If true print navigation bar at the top of the page else
500 * @param body the HtmlTree to which the nav links will be added
501 */
502 protected void addNavLinks(boolean header, Content body) {
503 if (!configuration.nonavbar) {
504 String allClassesId = "allclasses_";
505 HtmlTree navDiv = new HtmlTree(HtmlTag.DIV);
506 if (header) {
507 body.addContent(HtmlConstants.START_OF_TOP_NAVBAR);
508 navDiv.addStyle(HtmlStyle.topNav);
509 allClassesId += "navbar_top";
510 Content a = getMarkerAnchor("navbar_top");
511 navDiv.addContent(a);
512 Content skipLinkContent = getHyperLink(DocLink.fragment("skip-navbar_top"),
513 HtmlTree.EMPTY,
514 configuration.getText("doclet.Skip_navigation_links"),
515 "");
516 navDiv.addContent(skipLinkContent);
517 } else {
518 body.addContent(HtmlConstants.START_OF_BOTTOM_NAVBAR);
519 navDiv.addStyle(HtmlStyle.bottomNav);
520 allClassesId += "navbar_bottom";
521 Content a = getMarkerAnchor("navbar_bottom");
522 navDiv.addContent(a);
523 Content skipLinkContent = getHyperLink(DocLink.fragment("skip-navbar_bottom"),
524 HtmlTree.EMPTY,
525 configuration.getText("doclet.Skip_navigation_links"),
526 "");
527 navDiv.addContent(skipLinkContent);
528 }
529 if (header) {
530 navDiv.addContent(getMarkerAnchor("navbar_top_firstrow"));
531 } else {
532 navDiv.addContent(getMarkerAnchor("navbar_bottom_firstrow"));
533 }
534 HtmlTree navList = new HtmlTree(HtmlTag.UL);
535 navList.addStyle(HtmlStyle.navList);
536 navList.addAttr(HtmlAttr.TITLE,
537 configuration.getText("doclet.Navigation"));
538 if (configuration.createoverview) {
539 navList.addContent(getNavLinkContents());
540 }
541 if (configuration.packages.length == 1) {
542 navList.addContent(getNavLinkPackage(configuration.packages[0]));
543 } else if (configuration.packages.length > 1) {
544 navList.addContent(getNavLinkPackage());
545 }
546 navList.addContent(getNavLinkClass());
547 if(configuration.classuse) {
548 navList.addContent(getNavLinkClassUse());
549 }
550 if(configuration.createtree) {
551 navList.addContent(getNavLinkTree());
552 }
553 if(!(configuration.nodeprecated ||
554 configuration.nodeprecatedlist)) {
555 navList.addContent(getNavLinkDeprecated());
556 }
557 if(configuration.createindex) {
558 navList.addContent(getNavLinkIndex());
559 }
560 if (!configuration.nohelp) {
561 navList.addContent(getNavLinkHelp());
562 }
563 navDiv.addContent(navList);
564 Content aboutDiv = HtmlTree.DIV(HtmlStyle.aboutLanguage, getUserHeaderFooter(header));
565 navDiv.addContent(aboutDiv);
566 body.addContent(navDiv);
567 Content ulNav = HtmlTree.UL(HtmlStyle.navList, getNavLinkPrevious());
568 ulNav.addContent(getNavLinkNext());
569 Content subDiv = HtmlTree.DIV(HtmlStyle.subNav, ulNav);
570 Content ulFrames = HtmlTree.UL(HtmlStyle.navList, getNavShowLists());
571 ulFrames.addContent(getNavHideLists(filename));
572 subDiv.addContent(ulFrames);
573 HtmlTree ulAllClasses = HtmlTree.UL(HtmlStyle.navList, getNavLinkClassIndex());
574 ulAllClasses.addAttr(HtmlAttr.ID, allClassesId.toString());
575 subDiv.addContent(ulAllClasses);
576 subDiv.addContent(getAllClassesLinkScript(allClassesId.toString()));
577 addSummaryDetailLinks(subDiv);
578 if (header) {
579 subDiv.addContent(getMarkerAnchor("skip-navbar_top"));
580 body.addContent(subDiv);
581 body.addContent(HtmlConstants.END_OF_TOP_NAVBAR);
582 } else {
583 subDiv.addContent(getMarkerAnchor("skip-navbar_bottom"));
584 body.addContent(subDiv);
585 body.addContent(HtmlConstants.END_OF_BOTTOM_NAVBAR);
586 }
587 }
588 }
590 /**
591 * Get the word "NEXT" to indicate that no link is available. Override
592 * this method to customize next link.
593 *
594 * @return a content tree for the link
595 */
596 protected Content getNavLinkNext() {
597 return getNavLinkNext(null);
598 }
600 /**
601 * Get the word "PREV" to indicate that no link is available. Override
602 * this method to customize prev link.
603 *
604 * @return a content tree for the link
605 */
606 protected Content getNavLinkPrevious() {
607 return getNavLinkPrevious(null);
608 }
610 /**
611 * Do nothing. This is the default method.
612 */
613 protected void addSummaryDetailLinks(Content navDiv) {
614 }
616 /**
617 * Get link to the "overview-summary.html" page.
618 *
619 * @return a content tree for the link
620 */
621 protected Content getNavLinkContents() {
622 Content linkContent = getHyperLink(pathToRoot.resolve(DocPaths.OVERVIEW_SUMMARY),
623 overviewLabel, "", "");
624 Content li = HtmlTree.LI(linkContent);
625 return li;
626 }
628 /**
629 * Get link to the "package-summary.html" page for the package passed.
630 *
631 * @param pkg Package to which link will be generated
632 * @return a content tree for the link
633 */
634 protected Content getNavLinkPackage(PackageDoc pkg) {
635 Content linkContent = getPackageLink(pkg,
636 packageLabel);
637 Content li = HtmlTree.LI(linkContent);
638 return li;
639 }
641 /**
642 * Get the word "Package" , to indicate that link is not available here.
643 *
644 * @return a content tree for the link
645 */
646 protected Content getNavLinkPackage() {
647 Content li = HtmlTree.LI(packageLabel);
648 return li;
649 }
651 /**
652 * Get the word "Use", to indicate that link is not available.
653 *
654 * @return a content tree for the link
655 */
656 protected Content getNavLinkClassUse() {
657 Content li = HtmlTree.LI(useLabel);
658 return li;
659 }
661 /**
662 * Get link for previous file.
663 *
664 * @param prev File name for the prev link
665 * @return a content tree for the link
666 */
667 public Content getNavLinkPrevious(DocPath prev) {
668 Content li;
669 if (prev != null) {
670 li = HtmlTree.LI(getHyperLink(prev, prevLabel, "", ""));
671 }
672 else
673 li = HtmlTree.LI(prevLabel);
674 return li;
675 }
677 /**
678 * Get link for next file. If next is null, just print the label
679 * without linking it anywhere.
680 *
681 * @param next File name for the next link
682 * @return a content tree for the link
683 */
684 public Content getNavLinkNext(DocPath next) {
685 Content li;
686 if (next != null) {
687 li = HtmlTree.LI(getHyperLink(next, nextLabel, "", ""));
688 }
689 else
690 li = HtmlTree.LI(nextLabel);
691 return li;
692 }
694 /**
695 * Get "FRAMES" link, to switch to the frame version of the output.
696 *
697 * @param link File to be linked, "index.html"
698 * @return a content tree for the link
699 */
700 protected Content getNavShowLists(DocPath link) {
701 DocLink dl = new DocLink(link, path.getPath(), null);
702 Content framesContent = getHyperLink(dl, framesLabel, "", "_top");
703 Content li = HtmlTree.LI(framesContent);
704 return li;
705 }
707 /**
708 * Get "FRAMES" link, to switch to the frame version of the output.
709 *
710 * @return a content tree for the link
711 */
712 protected Content getNavShowLists() {
713 return getNavShowLists(pathToRoot.resolve(DocPaths.INDEX));
714 }
716 /**
717 * Get "NO FRAMES" link, to switch to the non-frame version of the output.
718 *
719 * @param link File to be linked
720 * @return a content tree for the link
721 */
722 protected Content getNavHideLists(DocPath link) {
723 Content noFramesContent = getHyperLink(link, noframesLabel, "", "_top");
724 Content li = HtmlTree.LI(noFramesContent);
725 return li;
726 }
728 /**
729 * Get "Tree" link in the navigation bar. If there is only one package
730 * specified on the command line, then the "Tree" link will be to the
731 * only "package-tree.html" file otherwise it will be to the
732 * "overview-tree.html" file.
733 *
734 * @return a content tree for the link
735 */
736 protected Content getNavLinkTree() {
737 Content treeLinkContent;
738 PackageDoc[] packages = configuration.root.specifiedPackages();
739 if (packages.length == 1 && configuration.root.specifiedClasses().length == 0) {
740 treeLinkContent = getHyperLink(pathString(packages[0],
741 DocPaths.PACKAGE_TREE), treeLabel,
742 "", "");
743 } else {
744 treeLinkContent = getHyperLink(pathToRoot.resolve(DocPaths.OVERVIEW_TREE),
745 treeLabel, "", "");
746 }
747 Content li = HtmlTree.LI(treeLinkContent);
748 return li;
749 }
751 /**
752 * Get the overview tree link for the main tree.
753 *
754 * @param label the label for the link
755 * @return a content tree for the link
756 */
757 protected Content getNavLinkMainTree(String label) {
758 Content mainTreeContent = getHyperLink(pathToRoot.resolve(DocPaths.OVERVIEW_TREE),
759 new StringContent(label));
760 Content li = HtmlTree.LI(mainTreeContent);
761 return li;
762 }
764 /**
765 * Get the word "Class", to indicate that class link is not available.
766 *
767 * @return a content tree for the link
768 */
769 protected Content getNavLinkClass() {
770 Content li = HtmlTree.LI(classLabel);
771 return li;
772 }
774 /**
775 * Get "Deprecated" API link in the navigation bar.
776 *
777 * @return a content tree for the link
778 */
779 protected Content getNavLinkDeprecated() {
780 Content linkContent = getHyperLink(pathToRoot.resolve(DocPaths.DEPRECATED_LIST),
781 deprecatedLabel, "", "");
782 Content li = HtmlTree.LI(linkContent);
783 return li;
784 }
786 /**
787 * Get link for generated index. If the user has used "-splitindex"
788 * command line option, then link to file "index-files/index-1.html" is
789 * generated otherwise link to file "index-all.html" is generated.
790 *
791 * @return a content tree for the link
792 */
793 protected Content getNavLinkClassIndex() {
794 Content allClassesContent = getHyperLink(pathToRoot.resolve(
795 DocPaths.ALLCLASSES_NOFRAME),
796 allclassesLabel, "", "");
797 Content li = HtmlTree.LI(allClassesContent);
798 return li;
799 }
801 /**
802 * Get link for generated class index.
803 *
804 * @return a content tree for the link
805 */
806 protected Content getNavLinkIndex() {
807 Content linkContent = getHyperLink(pathToRoot.resolve(
808 (configuration.splitindex
809 ? DocPaths.INDEX_FILES.resolve(DocPaths.indexN(1))
810 : DocPaths.INDEX_ALL)),
811 indexLabel, "", "");
812 Content li = HtmlTree.LI(linkContent);
813 return li;
814 }
816 /**
817 * Get help file link. If user has provided a help file, then generate a
818 * link to the user given file, which is already copied to current or
819 * destination directory.
820 *
821 * @return a content tree for the link
822 */
823 protected Content getNavLinkHelp() {
824 String helpfile = configuration.helpfile;
825 DocPath helpfilenm;
826 if (helpfile.isEmpty()) {
827 helpfilenm = DocPaths.HELP_DOC;
828 } else {
829 DocFile file = DocFile.createFileForInput(configuration, helpfile);
830 helpfilenm = DocPath.create(file.getName());
831 }
832 Content linkContent = getHyperLink(pathToRoot.resolve(helpfilenm),
833 helpLabel, "", "");
834 Content li = HtmlTree.LI(linkContent);
835 return li;
836 }
838 /**
839 * Get summary table header.
840 *
841 * @param header the header for the table
842 * @param scope the scope of the headers
843 * @return a content tree for the header
844 */
845 public Content getSummaryTableHeader(String[] header, String scope) {
846 Content tr = new HtmlTree(HtmlTag.TR);
847 int size = header.length;
848 Content tableHeader;
849 if (size == 1) {
850 tableHeader = new StringContent(header[0]);
851 tr.addContent(HtmlTree.TH(HtmlStyle.colOne, scope, tableHeader));
852 return tr;
853 }
854 for (int i = 0; i < size; i++) {
855 tableHeader = new StringContent(header[i]);
856 if(i == 0)
857 tr.addContent(HtmlTree.TH(HtmlStyle.colFirst, scope, tableHeader));
858 else if(i == (size - 1))
859 tr.addContent(HtmlTree.TH(HtmlStyle.colLast, scope, tableHeader));
860 else
861 tr.addContent(HtmlTree.TH(scope, tableHeader));
862 }
863 return tr;
864 }
866 /**
867 * Get table caption.
868 *
869 * @param rawText the caption for the table which could be raw Html
870 * @return a content tree for the caption
871 */
872 public Content getTableCaption(Content title) {
873 Content captionSpan = HtmlTree.SPAN(title);
874 Content space = getSpace();
875 Content tabSpan = HtmlTree.SPAN(HtmlStyle.tabEnd, space);
876 Content caption = HtmlTree.CAPTION(captionSpan);
877 caption.addContent(tabSpan);
878 return caption;
879 }
881 /**
882 * Get the marker anchor which will be added to the documentation tree.
883 *
884 * @param anchorName the anchor name attribute
885 * @return a content tree for the marker anchor
886 */
887 public Content getMarkerAnchor(String anchorName) {
888 return getMarkerAnchor(anchorName, null);
889 }
891 /**
892 * Get the marker anchor which will be added to the documentation tree.
893 *
894 * @param anchorName the anchor name attribute
895 * @param anchorContent the content that should be added to the anchor
896 * @return a content tree for the marker anchor
897 */
898 public Content getMarkerAnchor(String anchorName, Content anchorContent) {
899 if (anchorContent == null)
900 anchorContent = new Comment(" ");
901 Content markerAnchor = HtmlTree.A_NAME(anchorName, anchorContent);
902 return markerAnchor;
903 }
905 /**
906 * Returns a packagename content.
907 *
908 * @param packageDoc the package to check
909 * @return package name content
910 */
911 public Content getPackageName(PackageDoc packageDoc) {
912 return packageDoc == null || packageDoc.name().length() == 0 ?
913 defaultPackageLabel :
914 getPackageLabel(packageDoc.name());
915 }
917 /**
918 * Returns a package name label.
919 *
920 * @param packageName the package name
921 * @return the package name content
922 */
923 public Content getPackageLabel(String packageName) {
924 return new StringContent(packageName);
925 }
927 /**
928 * Add package deprecation information to the documentation tree
929 *
930 * @param deprPkgs list of deprecated packages
931 * @param headingKey the caption for the deprecated package table
932 * @param tableSummary the summary for the deprecated package table
933 * @param tableHeader table headers for the deprecated package table
934 * @param contentTree the content tree to which the deprecated package table will be added
935 */
936 protected void addPackageDeprecatedAPI(List<Doc> deprPkgs, String headingKey,
937 String tableSummary, String[] tableHeader, Content contentTree) {
938 if (deprPkgs.size() > 0) {
939 Content table = HtmlTree.TABLE(0, 3, 0, tableSummary,
940 getTableCaption(configuration.getResource(headingKey)));
941 table.addContent(getSummaryTableHeader(tableHeader, "col"));
942 Content tbody = new HtmlTree(HtmlTag.TBODY);
943 for (int i = 0; i < deprPkgs.size(); i++) {
944 PackageDoc pkg = (PackageDoc) deprPkgs.get(i);
945 HtmlTree td = HtmlTree.TD(HtmlStyle.colOne,
946 getPackageLink(pkg, getPackageName(pkg)));
947 if (pkg.tags("deprecated").length > 0) {
948 addInlineDeprecatedComment(pkg, pkg.tags("deprecated")[0], td);
949 }
950 HtmlTree tr = HtmlTree.TR(td);
951 if (i % 2 == 0) {
952 tr.addStyle(HtmlStyle.altColor);
953 } else {
954 tr.addStyle(HtmlStyle.rowColor);
955 }
956 tbody.addContent(tr);
957 }
958 table.addContent(tbody);
959 Content li = HtmlTree.LI(HtmlStyle.blockList, table);
960 Content ul = HtmlTree.UL(HtmlStyle.blockList, li);
961 contentTree.addContent(ul);
962 }
963 }
965 /**
966 * Return the path to the class page for a classdoc.
967 *
968 * @param cd Class to which the path is requested.
969 * @param name Name of the file(doesn't include path).
970 */
971 protected DocPath pathString(ClassDoc cd, DocPath name) {
972 return pathString(cd.containingPackage(), name);
973 }
975 /**
976 * Return path to the given file name in the given package. So if the name
977 * passed is "Object.html" and the name of the package is "java.lang", and
978 * if the relative path is "../.." then returned string will be
979 * "../../java/lang/Object.html"
980 *
981 * @param pd Package in which the file name is assumed to be.
982 * @param name File name, to which path string is.
983 */
984 protected DocPath pathString(PackageDoc pd, DocPath name) {
985 return pathToRoot.resolve(DocPath.forPackage(pd).resolve(name));
986 }
988 /**
989 * Return the link to the given package.
990 *
991 * @param pkg the package to link to.
992 * @param label the label for the link.
993 * @return a content tree for the package link.
994 */
995 public Content getPackageLink(PackageDoc pkg, String label) {
996 return getPackageLink(pkg, new StringContent(label));
997 }
999 /**
1000 * Return the link to the given package.
1001 *
1002 * @param pkg the package to link to.
1003 * @param label the label for the link.
1004 * @return a content tree for the package link.
1005 */
1006 public Content getPackageLink(PackageDoc pkg, Content label) {
1007 boolean included = pkg != null && pkg.isIncluded();
1008 if (! included) {
1009 PackageDoc[] packages = configuration.packages;
1010 for (int i = 0; i < packages.length; i++) {
1011 if (packages[i].equals(pkg)) {
1012 included = true;
1013 break;
1014 }
1015 }
1016 }
1017 if (included || pkg == null) {
1018 return getHyperLink(pathString(pkg, DocPaths.PACKAGE_SUMMARY),
1019 label);
1020 } else {
1021 DocLink crossPkgLink = getCrossPackageLink(Util.getPackageName(pkg));
1022 if (crossPkgLink != null) {
1023 return getHyperLink(crossPkgLink, label);
1024 } else {
1025 return label;
1026 }
1027 }
1028 }
1030 public Content italicsClassName(ClassDoc cd, boolean qual) {
1031 Content name = new StringContent((qual)? cd.qualifiedName(): cd.name());
1032 return (cd.isInterface())? HtmlTree.I(name): name;
1033 }
1035 /**
1036 * Add the link to the content tree.
1037 *
1038 * @param doc program element doc for which the link will be added
1039 * @param label label for the link
1040 * @param htmltree the content tree to which the link will be added
1041 */
1042 public void addSrcLink(ProgramElementDoc doc, Content label, Content htmltree) {
1043 if (doc == null) {
1044 return;
1045 }
1046 ClassDoc cd = doc.containingClass();
1047 if (cd == null) {
1048 //d must be a class doc since in has no containing class.
1049 cd = (ClassDoc) doc;
1050 }
1051 DocPath href = pathToRoot
1052 .resolve(DocPaths.SOURCE_OUTPUT)
1053 .resolve(DocPath.forClass(cd));
1054 Content linkContent = getHyperLink(href.fragment(SourceToHTMLConverter.getAnchorName(doc)), label, "", "");
1055 htmltree.addContent(linkContent);
1056 }
1058 /**
1059 * Return the link to the given class.
1060 *
1061 * @param linkInfo the information about the link.
1062 *
1063 * @return the link for the given class.
1064 */
1065 public Content getLink(LinkInfoImpl linkInfo) {
1066 LinkFactoryImpl factory = new LinkFactoryImpl(this);
1067 return factory.getLink(linkInfo);
1068 }
1070 /**
1071 * Return the type parameters for the given class.
1072 *
1073 * @param linkInfo the information about the link.
1074 * @return the type for the given class.
1075 */
1076 public Content getTypeParameterLinks(LinkInfoImpl linkInfo) {
1077 LinkFactoryImpl factory = new LinkFactoryImpl(this);
1078 return factory.getTypeParameterLinks(linkInfo, false);
1079 }
1081 /*************************************************************
1082 * Return a class cross link to external class documentation.
1083 * The name must be fully qualified to determine which package
1084 * the class is in. The -link option does not allow users to
1085 * link to external classes in the "default" package.
1086 *
1087 * @param qualifiedClassName the qualified name of the external class.
1088 * @param refMemName the name of the member being referenced. This should
1089 * be null or empty string if no member is being referenced.
1090 * @param label the label for the external link.
1091 * @param strong true if the link should be strong.
1092 * @param style the style of the link.
1093 * @param code true if the label should be code font.
1094 */
1095 public Content getCrossClassLink(String qualifiedClassName, String refMemName,
1096 Content label, boolean strong, String style,
1097 boolean code) {
1098 String className = "";
1099 String packageName = qualifiedClassName == null ? "" : qualifiedClassName;
1100 int periodIndex;
1101 while ((periodIndex = packageName.lastIndexOf('.')) != -1) {
1102 className = packageName.substring(periodIndex + 1, packageName.length()) +
1103 (className.length() > 0 ? "." + className : "");
1104 Content defaultLabel = new StringContent(className);
1105 if (code)
1106 defaultLabel = HtmlTree.CODE(defaultLabel);
1107 packageName = packageName.substring(0, periodIndex);
1108 if (getCrossPackageLink(packageName) != null) {
1109 //The package exists in external documentation, so link to the external
1110 //class (assuming that it exists). This is definitely a limitation of
1111 //the -link option. There are ways to determine if an external package
1112 //exists, but no way to determine if the external class exists. We just
1113 //have to assume that it does.
1114 DocLink link = configuration.extern.getExternalLink(packageName, pathToRoot,
1115 className + ".html", refMemName);
1116 return getHyperLink(link,
1117 (label == null) || label.isEmpty() ? defaultLabel : label,
1118 strong, style,
1119 configuration.getText("doclet.Href_Class_Or_Interface_Title", packageName),
1120 "");
1121 }
1122 }
1123 return null;
1124 }
1126 public boolean isClassLinkable(ClassDoc cd) {
1127 if (cd.isIncluded()) {
1128 return configuration.isGeneratedDoc(cd);
1129 }
1130 return configuration.extern.isExternal(cd);
1131 }
1133 public DocLink getCrossPackageLink(String pkgName) {
1134 return configuration.extern.getExternalLink(pkgName, pathToRoot,
1135 DocPaths.PACKAGE_SUMMARY.getPath());
1136 }
1138 /**
1139 * Get the class link.
1140 *
1141 * @param context the id of the context where the link will be added
1142 * @param cd the class doc to link to
1143 * @return a content tree for the link
1144 */
1145 public Content getQualifiedClassLink(LinkInfoImpl.Kind context, ClassDoc cd) {
1146 return getLink(new LinkInfoImpl(configuration, context, cd)
1147 .label(configuration.getClassName(cd)));
1148 }
1150 /**
1151 * Add the class link.
1152 *
1153 * @param context the id of the context where the link will be added
1154 * @param cd the class doc to link to
1155 * @param contentTree the content tree to which the link will be added
1156 */
1157 public void addPreQualifiedClassLink(LinkInfoImpl.Kind context, ClassDoc cd, Content contentTree) {
1158 addPreQualifiedClassLink(context, cd, false, contentTree);
1159 }
1161 /**
1162 * Retrieve the class link with the package portion of the label in
1163 * plain text. If the qualifier is excluded, it will not be included in the
1164 * link label.
1165 *
1166 * @param cd the class to link to.
1167 * @param isStrong true if the link should be strong.
1168 * @return the link with the package portion of the label in plain text.
1169 */
1170 public Content getPreQualifiedClassLink(LinkInfoImpl.Kind context,
1171 ClassDoc cd, boolean isStrong) {
1172 ContentBuilder classlink = new ContentBuilder();
1173 PackageDoc pd = cd.containingPackage();
1174 if (pd != null && ! configuration.shouldExcludeQualifier(pd.name())) {
1175 classlink.addContent(getPkgName(cd));
1176 }
1177 classlink.addContent(getLink(new LinkInfoImpl(configuration,
1178 context, cd).label(cd.name()).strong(isStrong)));
1179 return classlink;
1180 }
1182 /**
1183 * Add the class link with the package portion of the label in
1184 * plain text. If the qualifier is excluded, it will not be included in the
1185 * link label.
1186 *
1187 * @param context the id of the context where the link will be added
1188 * @param cd the class to link to
1189 * @param isStrong true if the link should be strong
1190 * @param contentTree the content tree to which the link with be added
1191 */
1192 public void addPreQualifiedClassLink(LinkInfoImpl.Kind context,
1193 ClassDoc cd, boolean isStrong, Content contentTree) {
1194 PackageDoc pd = cd.containingPackage();
1195 if(pd != null && ! configuration.shouldExcludeQualifier(pd.name())) {
1196 contentTree.addContent(getPkgName(cd));
1197 }
1198 contentTree.addContent(getLink(new LinkInfoImpl(configuration,
1199 context, cd).label(cd.name()).strong(isStrong)));
1200 }
1202 /**
1203 * Add the class link, with only class name as the strong link and prefixing
1204 * plain package name.
1205 *
1206 * @param context the id of the context where the link will be added
1207 * @param cd the class to link to
1208 * @param contentTree the content tree to which the link with be added
1209 */
1210 public void addPreQualifiedStrongClassLink(LinkInfoImpl.Kind context, ClassDoc cd, Content contentTree) {
1211 addPreQualifiedClassLink(context, cd, true, contentTree);
1212 }
1214 /**
1215 * Get the link for the given member.
1216 *
1217 * @param context the id of the context where the link will be added
1218 * @param doc the member being linked to
1219 * @param label the label for the link
1220 * @return a content tree for the doc link
1221 */
1222 public Content getDocLink(LinkInfoImpl.Kind context, MemberDoc doc, String label) {
1223 return getDocLink(context, doc.containingClass(), doc,
1224 new StringContent(label));
1225 }
1227 /**
1228 * Return the link for the given member.
1229 *
1230 * @param context the id of the context where the link will be printed.
1231 * @param doc the member being linked to.
1232 * @param label the label for the link.
1233 * @param strong true if the link should be strong.
1234 * @return the link for the given member.
1235 */
1236 public Content getDocLink(LinkInfoImpl.Kind context, MemberDoc doc, String label,
1237 boolean strong) {
1238 return getDocLink(context, doc.containingClass(), doc, label, strong);
1239 }
1241 /**
1242 * Return the link for the given member.
1243 *
1244 * @param context the id of the context where the link will be printed.
1245 * @param classDoc the classDoc that we should link to. This is not
1246 * necessarily equal to doc.containingClass(). We may be
1247 * inheriting comments.
1248 * @param doc the member being linked to.
1249 * @param label the label for the link.
1250 * @param strong true if the link should be strong.
1251 * @return the link for the given member.
1252 */
1253 public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
1254 String label, boolean strong) {
1255 return getDocLink(context, classDoc, doc, label, strong, false);
1256 }
1257 public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
1258 Content label, boolean strong) {
1259 return getDocLink(context, classDoc, doc, label, strong, false);
1260 }
1262 /**
1263 * Return the link for the given member.
1264 *
1265 * @param context the id of the context where the link will be printed.
1266 * @param classDoc the classDoc that we should link to. This is not
1267 * necessarily equal to doc.containingClass(). We may be
1268 * inheriting comments.
1269 * @param doc the member being linked to.
1270 * @param label the label for the link.
1271 * @param strong true if the link should be strong.
1272 * @param isProperty true if the doc parameter is a JavaFX property.
1273 * @return the link for the given member.
1274 */
1275 public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
1276 String label, boolean strong, boolean isProperty) {
1277 return getDocLink(context, classDoc, doc, new StringContent(check(label)), strong, isProperty);
1278 }
1280 String check(String s) {
1281 if (s.matches(".*[&<>].*"))throw new IllegalArgumentException(s);
1282 return s;
1283 }
1285 public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
1286 Content label, boolean strong, boolean isProperty) {
1287 if (! (doc.isIncluded() ||
1288 Util.isLinkable(classDoc, configuration))) {
1289 return label;
1290 } else if (doc instanceof ExecutableMemberDoc) {
1291 ExecutableMemberDoc emd = (ExecutableMemberDoc)doc;
1292 return getLink(new LinkInfoImpl(configuration, context, classDoc)
1293 .label(label).where(getAnchor(emd, isProperty)).strong(strong));
1294 } else if (doc instanceof MemberDoc) {
1295 return getLink(new LinkInfoImpl(configuration, context, classDoc)
1296 .label(label).where(doc.name()).strong(strong));
1297 } else {
1298 return label;
1299 }
1300 }
1302 /**
1303 * Return the link for the given member.
1304 *
1305 * @param context the id of the context where the link will be added
1306 * @param classDoc the classDoc that we should link to. This is not
1307 * necessarily equal to doc.containingClass(). We may be
1308 * inheriting comments
1309 * @param doc the member being linked to
1310 * @param label the label for the link
1311 * @return the link for the given member
1312 */
1313 public Content getDocLink(LinkInfoImpl.Kind context, ClassDoc classDoc, MemberDoc doc,
1314 Content label) {
1315 if (! (doc.isIncluded() ||
1316 Util.isLinkable(classDoc, configuration))) {
1317 return label;
1318 } else if (doc instanceof ExecutableMemberDoc) {
1319 ExecutableMemberDoc emd = (ExecutableMemberDoc) doc;
1320 return getLink(new LinkInfoImpl(configuration, context, classDoc)
1321 .label(label).where(getAnchor(emd)));
1322 } else if (doc instanceof MemberDoc) {
1323 return getLink(new LinkInfoImpl(configuration, context, classDoc)
1324 .label(label).where(doc.name()));
1325 } else {
1326 return label;
1327 }
1328 }
1330 public String getAnchor(ExecutableMemberDoc emd) {
1331 return getAnchor(emd, false);
1332 }
1334 public String getAnchor(ExecutableMemberDoc emd, boolean isProperty) {
1335 if (isProperty) {
1336 return emd.name();
1337 }
1338 StringBuilder signature = new StringBuilder(emd.signature());
1339 StringBuilder signatureParsed = new StringBuilder();
1340 int counter = 0;
1341 for (int i = 0; i < signature.length(); i++) {
1342 char c = signature.charAt(i);
1343 if (c == '<') {
1344 counter++;
1345 } else if (c == '>') {
1346 counter--;
1347 } else if (counter == 0) {
1348 signatureParsed.append(c);
1349 }
1350 }
1351 return emd.name() + signatureParsed.toString();
1352 }
1354 public Content seeTagToContent(SeeTag see) {
1355 String tagName = see.name();
1356 if (! (tagName.startsWith("@link") || tagName.equals("@see"))) {
1357 return new ContentBuilder();
1358 }
1360 String seetext = replaceDocRootDir(see.text());
1362 //Check if @see is an href or "string"
1363 if (seetext.startsWith("<") || seetext.startsWith("\"")) {
1364 return new RawHtml(seetext);
1365 }
1367 boolean plain = tagName.equalsIgnoreCase("@linkplain");
1368 Content label = plainOrCode(plain, new RawHtml(see.label()));
1370 //The text from the @see tag. We will output this text when a label is not specified.
1371 Content text = plainOrCode(plain, new RawHtml(seetext));
1373 ClassDoc refClass = see.referencedClass();
1374 String refClassName = see.referencedClassName();
1375 MemberDoc refMem = see.referencedMember();
1376 String refMemName = see.referencedMemberName();
1378 if (refClass == null) {
1379 //@see is not referencing an included class
1380 PackageDoc refPackage = see.referencedPackage();
1381 if (refPackage != null && refPackage.isIncluded()) {
1382 //@see is referencing an included package
1383 if (label.isEmpty())
1384 label = plainOrCode(plain, new StringContent(refPackage.name()));
1385 return getPackageLink(refPackage, label);
1386 } else {
1387 //@see is not referencing an included class or package. Check for cross links.
1388 Content classCrossLink;
1389 DocLink packageCrossLink = getCrossPackageLink(refClassName);
1390 if (packageCrossLink != null) {
1391 //Package cross link found
1392 return getHyperLink(packageCrossLink,
1393 (label.isEmpty() ? text : label));
1394 } else if ((classCrossLink = getCrossClassLink(refClassName,
1395 refMemName, label, false, "", !plain)) != null) {
1396 //Class cross link found (possibly to a member in the class)
1397 return classCrossLink;
1398 } else {
1399 //No cross link found so print warning
1400 configuration.getDocletSpecificMsg().warning(see.position(), "doclet.see.class_or_package_not_found",
1401 tagName, seetext);
1402 return (label.isEmpty() ? text: label);
1403 }
1404 }
1405 } else if (refMemName == null) {
1406 // Must be a class reference since refClass is not null and refMemName is null.
1407 if (label.isEmpty()) {
1408 label = plainOrCode(plain, new StringContent(refClass.name()));
1409 }
1410 return getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.DEFAULT, refClass)
1411 .label(label));
1412 } else if (refMem == null) {
1413 // Must be a member reference since refClass is not null and refMemName is not null.
1414 // However, refMem is null, so this referenced member does not exist.
1415 return (label.isEmpty() ? text: label);
1416 } else {
1417 // Must be a member reference since refClass is not null and refMemName is not null.
1418 // refMem is not null, so this @see tag must be referencing a valid member.
1419 ClassDoc containing = refMem.containingClass();
1420 if (see.text().trim().startsWith("#") &&
1421 ! (containing.isPublic() ||
1422 Util.isLinkable(containing, configuration))) {
1423 // Since the link is relative and the holder is not even being
1424 // documented, this must be an inherited link. Redirect it.
1425 // The current class either overrides the referenced member or
1426 // inherits it automatically.
1427 if (this instanceof ClassWriterImpl) {
1428 containing = ((ClassWriterImpl) this).getClassDoc();
1429 } else if (!containing.isPublic()){
1430 configuration.getDocletSpecificMsg().warning(
1431 see.position(), "doclet.see.class_or_package_not_accessible",
1432 tagName, containing.qualifiedName());
1433 } else {
1434 configuration.getDocletSpecificMsg().warning(
1435 see.position(), "doclet.see.class_or_package_not_found",
1436 tagName, seetext);
1437 }
1438 }
1439 if (configuration.currentcd != containing) {
1440 refMemName = containing.name() + "." + refMemName;
1441 }
1442 if (refMem instanceof ExecutableMemberDoc) {
1443 if (refMemName.indexOf('(') < 0) {
1444 refMemName += ((ExecutableMemberDoc)refMem).signature();
1445 }
1446 }
1448 text = plainOrCode(plain, new StringContent(refMemName));
1450 return getDocLink(LinkInfoImpl.Kind.SEE_TAG, containing,
1451 refMem, (label.isEmpty() ? text: label), false);
1452 }
1453 }
1455 private Content plainOrCode(boolean plain, Content body) {
1456 return (plain || body.isEmpty()) ? body : HtmlTree.CODE(body);
1457 }
1459 /**
1460 * Add the inline comment.
1461 *
1462 * @param doc the doc for which the inline comment will be added
1463 * @param tag the inline tag to be added
1464 * @param htmltree the content tree to which the comment will be added
1465 */
1466 public void addInlineComment(Doc doc, Tag tag, Content htmltree) {
1467 addCommentTags(doc, tag, tag.inlineTags(), false, false, htmltree);
1468 }
1470 /**
1471 * Add the inline deprecated comment.
1472 *
1473 * @param doc the doc for which the inline deprecated comment will be added
1474 * @param tag the inline tag to be added
1475 * @param htmltree the content tree to which the comment will be added
1476 */
1477 public void addInlineDeprecatedComment(Doc doc, Tag tag, Content htmltree) {
1478 addCommentTags(doc, tag.inlineTags(), true, false, htmltree);
1479 }
1481 /**
1482 * Adds the summary content.
1483 *
1484 * @param doc the doc for which the summary will be generated
1485 * @param htmltree the documentation tree to which the summary will be added
1486 */
1487 public void addSummaryComment(Doc doc, Content htmltree) {
1488 addSummaryComment(doc, doc.firstSentenceTags(), htmltree);
1489 }
1491 /**
1492 * Adds the summary content.
1493 *
1494 * @param doc the doc for which the summary will be generated
1495 * @param firstSentenceTags the first sentence tags for the doc
1496 * @param htmltree the documentation tree to which the summary will be added
1497 */
1498 public void addSummaryComment(Doc doc, Tag[] firstSentenceTags, Content htmltree) {
1499 addCommentTags(doc, firstSentenceTags, false, true, htmltree);
1500 }
1502 public void addSummaryDeprecatedComment(Doc doc, Tag tag, Content htmltree) {
1503 addCommentTags(doc, tag.firstSentenceTags(), true, true, htmltree);
1504 }
1506 /**
1507 * Adds the inline comment.
1508 *
1509 * @param doc the doc for which the inline comments will be generated
1510 * @param htmltree the documentation tree to which the inline comments will be added
1511 */
1512 public void addInlineComment(Doc doc, Content htmltree) {
1513 addCommentTags(doc, doc.inlineTags(), false, false, htmltree);
1514 }
1516 /**
1517 * Adds the comment tags.
1518 *
1519 * @param doc the doc for which the comment tags will be generated
1520 * @param tags the first sentence tags for the doc
1521 * @param depr true if it is deprecated
1522 * @param first true if the first sentence tags should be added
1523 * @param htmltree the documentation tree to which the comment tags will be added
1524 */
1525 private void addCommentTags(Doc doc, Tag[] tags, boolean depr,
1526 boolean first, Content htmltree) {
1527 addCommentTags(doc, null, tags, depr, first, htmltree);
1528 }
1530 /**
1531 * Adds the comment tags.
1532 *
1533 * @param doc the doc for which the comment tags will be generated
1534 * @param holderTag the block tag context for the inline tags
1535 * @param tags the first sentence tags for the doc
1536 * @param depr true if it is deprecated
1537 * @param first true if the first sentence tags should be added
1538 * @param htmltree the documentation tree to which the comment tags will be added
1539 */
1540 private void addCommentTags(Doc doc, Tag holderTag, Tag[] tags, boolean depr,
1541 boolean first, Content htmltree) {
1542 if(configuration.nocomment){
1543 return;
1544 }
1545 Content div;
1546 Content result = commentTagsToContent(null, doc, tags, first);
1547 if (depr) {
1548 Content italic = HtmlTree.I(result);
1549 div = HtmlTree.DIV(HtmlStyle.block, italic);
1550 htmltree.addContent(div);
1551 }
1552 else {
1553 div = HtmlTree.DIV(HtmlStyle.block, result);
1554 htmltree.addContent(div);
1555 }
1556 if (tags.length == 0) {
1557 htmltree.addContent(getSpace());
1558 }
1559 }
1561 /**
1562 * Converts inline tags and text to text strings, expanding the
1563 * inline tags along the way. Called wherever text can contain
1564 * an inline tag, such as in comments or in free-form text arguments
1565 * to non-inline tags.
1566 *
1567 * @param holderTag specific tag where comment resides
1568 * @param doc specific doc where comment resides
1569 * @param tags array of text tags and inline tags (often alternating)
1570 * present in the text of interest for this doc
1571 * @param isFirstSentence true if text is first sentence
1572 */
1573 public Content commentTagsToContent(Tag holderTag, Doc doc, Tag[] tags,
1574 boolean isFirstSentence) {
1575 Content result = new ContentBuilder();
1576 boolean textTagChange = false;
1577 // Array of all possible inline tags for this javadoc run
1578 configuration.tagletManager.checkTags(doc, tags, true);
1579 for (int i = 0; i < tags.length; i++) {
1580 Tag tagelem = tags[i];
1581 String tagName = tagelem.name();
1582 if (tagelem instanceof SeeTag) {
1583 result.addContent(seeTagToContent((SeeTag) tagelem));
1584 } else if (! tagName.equals("Text")) {
1585 boolean wasEmpty = result.isEmpty();
1586 Content output = TagletWriter.getInlineTagOuput(
1587 configuration.tagletManager, holderTag,
1588 tagelem, getTagletWriterInstance(isFirstSentence));
1589 if (output != null)
1590 result.addContent(output);
1591 if (wasEmpty && isFirstSentence && tagelem.name().equals("@inheritDoc") && !result.isEmpty()) {
1592 break;
1593 } else if (configuration.docrootparent.length() > 0 &&
1594 tagelem.name().equals("@docRoot") &&
1595 ((tags[i + 1]).text()).startsWith("/..")) {
1596 //If Xdocrootparent switch ON, set the flag to remove the /.. occurance after
1597 //{@docRoot} tag in the very next Text tag.
1598 textTagChange = true;
1599 continue;
1600 } else {
1601 continue;
1602 }
1603 } else {
1604 String text = tagelem.text();
1605 //If Xdocrootparent switch ON, remove the /.. occurance after {@docRoot} tag.
1606 if (textTagChange) {
1607 text = text.replaceFirst("/..", "");
1608 textTagChange = false;
1609 }
1610 //This is just a regular text tag. The text may contain html links (<a>)
1611 //or inline tag {@docRoot}, which will be handled as special cases.
1612 text = redirectRelativeLinks(tagelem.holder(), text);
1614 // Replace @docRoot only if not represented by an instance of DocRootTaglet,
1615 // that is, only if it was not present in a source file doc comment.
1616 // This happens when inserted by the doclet (a few lines
1617 // above in this method). [It might also happen when passed in on the command
1618 // line as a text argument to an option (like -header).]
1619 text = replaceDocRootDir(text);
1620 if (isFirstSentence) {
1621 text = removeNonInlineHtmlTags(text);
1622 }
1623 text = Util.replaceTabs(configuration, text);
1624 result.addContent(new RawHtml(text));
1625 }
1626 }
1627 return result;
1628 }
1630 /**
1631 * Return true if relative links should not be redirected.
1632 *
1633 * @return Return true if a relative link should not be redirected.
1634 */
1635 private boolean shouldNotRedirectRelativeLinks() {
1636 return this instanceof AnnotationTypeWriter ||
1637 this instanceof ClassWriter ||
1638 this instanceof PackageSummaryWriter;
1639 }
1641 /**
1642 * Suppose a piece of documentation has a relative link. When you copy
1643 * that documentation to another place such as the index or class-use page,
1644 * that relative link will no longer work. We should redirect those links
1645 * so that they will work again.
1646 * <p>
1647 * Here is the algorithm used to fix the link:
1648 * <p>
1649 * {@literal <relative link> => docRoot + <relative path to file> + <relative link> }
1650 * <p>
1651 * For example, suppose com.sun.javadoc.RootDoc has this link:
1652 * {@literal <a href="package-summary.html">The package Page</a> }
1653 * <p>
1654 * If this link appeared in the index, we would redirect
1655 * the link like this:
1656 *
1657 * {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
1658 *
1659 * @param doc the Doc object whose documentation is being written.
1660 * @param text the text being written.
1661 *
1662 * @return the text, with all the relative links redirected to work.
1663 */
1664 private String redirectRelativeLinks(Doc doc, String text) {
1665 if (doc == null || shouldNotRedirectRelativeLinks()) {
1666 return text;
1667 }
1669 DocPath redirectPathFromRoot;
1670 if (doc instanceof ClassDoc) {
1671 redirectPathFromRoot = DocPath.forPackage(((ClassDoc) doc).containingPackage());
1672 } else if (doc instanceof MemberDoc) {
1673 redirectPathFromRoot = DocPath.forPackage(((MemberDoc) doc).containingPackage());
1674 } else if (doc instanceof PackageDoc) {
1675 redirectPathFromRoot = DocPath.forPackage((PackageDoc) doc);
1676 } else {
1677 return text;
1678 }
1680 //Redirect all relative links.
1681 int end, begin = text.toLowerCase().indexOf("<a");
1682 if(begin >= 0){
1683 StringBuilder textBuff = new StringBuilder(text);
1685 while(begin >=0){
1686 if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
1687 begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
1688 continue;
1689 }
1691 begin = textBuff.indexOf("=", begin) + 1;
1692 end = textBuff.indexOf(">", begin +1);
1693 if(begin == 0){
1694 //Link has no equal symbol.
1695 configuration.root.printWarning(
1696 doc.position(),
1697 configuration.getText("doclet.malformed_html_link_tag", text));
1698 break;
1699 }
1700 if (end == -1) {
1701 //Break without warning. This <a> tag is not necessarily malformed. The text
1702 //might be missing '>' character because the href has an inline tag.
1703 break;
1704 }
1705 if (textBuff.substring(begin, end).indexOf("\"") != -1){
1706 begin = textBuff.indexOf("\"", begin) + 1;
1707 end = textBuff.indexOf("\"", begin +1);
1708 if (begin == 0 || end == -1){
1709 //Link is missing a quote.
1710 break;
1711 }
1712 }
1713 String relativeLink = textBuff.substring(begin, end);
1714 if (!(relativeLink.toLowerCase().startsWith("mailto:") ||
1715 relativeLink.toLowerCase().startsWith("http:") ||
1716 relativeLink.toLowerCase().startsWith("https:") ||
1717 relativeLink.toLowerCase().startsWith("file:"))) {
1718 relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/"
1719 + redirectPathFromRoot.resolve(relativeLink).getPath();
1720 textBuff.replace(begin, end, relativeLink);
1721 }
1722 begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
1723 }
1724 return textBuff.toString();
1725 }
1726 return text;
1727 }
1729 static Set<String> blockTags = new HashSet<String>();
1730 static {
1731 for (HtmlTag t: HtmlTag.values()) {
1732 if (t.blockType == HtmlTag.BlockType.BLOCK)
1733 blockTags.add(t.value);
1734 }
1735 }
1737 public static String removeNonInlineHtmlTags(String text) {
1738 final int len = text.length();
1740 int startPos = 0; // start of text to copy
1741 int lessThanPos = text.indexOf('<'); // position of latest '<'
1742 if (lessThanPos < 0) {
1743 return text;
1744 }
1746 StringBuilder result = new StringBuilder();
1747 main: while (lessThanPos != -1) {
1748 int currPos = lessThanPos + 1;
1749 if (currPos == len)
1750 break;
1751 char ch = text.charAt(currPos);
1752 if (ch == '/') {
1753 if (++currPos == len)
1754 break;
1755 ch = text.charAt(currPos);
1756 }
1757 int tagPos = currPos;
1758 while (isHtmlTagLetterOrDigit(ch)) {
1759 if (++currPos == len)
1760 break main;
1761 ch = text.charAt(currPos);
1762 }
1763 if (ch == '>' && blockTags.contains(text.substring(tagPos, currPos).toLowerCase())) {
1764 result.append(text, startPos, lessThanPos);
1765 startPos = currPos + 1;
1766 }
1767 lessThanPos = text.indexOf('<', currPos);
1768 }
1769 result.append(text.substring(startPos));
1771 return result.toString();
1772 }
1774 private static final boolean isHtmlTagLetterOrDigit(char ch) {
1775 return ('a' <= ch && ch <= 'z') ||
1776 ('A' <= ch && ch <= 'Z') ||
1777 ('1' <= ch && ch <= '6');
1778 }
1780 /**
1781 * Returns a link to the stylesheet file.
1782 *
1783 * @return an HtmlTree for the lINK tag which provides the stylesheet location
1784 */
1785 public HtmlTree getStyleSheetProperties() {
1786 String stylesheetfile = configuration.stylesheetfile;
1787 DocPath stylesheet;
1788 if (stylesheetfile.isEmpty()) {
1789 stylesheet = DocPaths.STYLESHEET;
1790 } else {
1791 DocFile file = DocFile.createFileForInput(configuration, stylesheetfile);
1792 stylesheet = DocPath.create(file.getName());
1793 }
1794 HtmlTree link = HtmlTree.LINK("stylesheet", "text/css",
1795 pathToRoot.resolve(stylesheet).getPath(),
1796 "Style");
1797 return link;
1798 }
1800 /**
1801 * Returns a link to the JavaScript file.
1802 *
1803 * @return an HtmlTree for the Script tag which provides the JavaScript location
1804 */
1805 public HtmlTree getScriptProperties() {
1806 HtmlTree script = HtmlTree.SCRIPT("text/javascript",
1807 pathToRoot.resolve(DocPaths.JAVASCRIPT).getPath());
1808 return script;
1809 }
1811 /**
1812 * According to
1813 * <cite>The Java™ Language Specification</cite>,
1814 * all the outer classes and static nested classes are core classes.
1815 */
1816 public boolean isCoreClass(ClassDoc cd) {
1817 return cd.containingClass() == null || cd.isStatic();
1818 }
1820 /**
1821 * Adds the annotatation types for the given packageDoc.
1822 *
1823 * @param packageDoc the package to write annotations for.
1824 * @param htmltree the documentation tree to which the annotation info will be
1825 * added
1826 */
1827 public void addAnnotationInfo(PackageDoc packageDoc, Content htmltree) {
1828 addAnnotationInfo(packageDoc, packageDoc.annotations(), htmltree);
1829 }
1831 /**
1832 * Add the annotation types of the executable receiver.
1833 *
1834 * @param method the executable to write the receiver annotations for.
1835 * @param descList list of annotation description.
1836 * @param htmltree the documentation tree to which the annotation info will be
1837 * added
1838 */
1839 public void addReceiverAnnotationInfo(ExecutableMemberDoc method, AnnotationDesc[] descList,
1840 Content htmltree) {
1841 addAnnotationInfo(0, method, descList, false, htmltree);
1842 }
1844 /**
1845 * Adds the annotatation types for the given doc.
1846 *
1847 * @param doc the package to write annotations for
1848 * @param htmltree the content tree to which the annotation types will be added
1849 */
1850 public void addAnnotationInfo(ProgramElementDoc doc, Content htmltree) {
1851 addAnnotationInfo(doc, doc.annotations(), htmltree);
1852 }
1854 /**
1855 * Add the annotatation types for the given doc and parameter.
1856 *
1857 * @param indent the number of spaces to indent the parameters.
1858 * @param doc the doc to write annotations for.
1859 * @param param the parameter to write annotations for.
1860 * @param tree the content tree to which the annotation types will be added
1861 */
1862 public boolean addAnnotationInfo(int indent, Doc doc, Parameter param,
1863 Content tree) {
1864 return addAnnotationInfo(indent, doc, param.annotations(), false, tree);
1865 }
1867 /**
1868 * Adds the annotatation types for the given doc.
1869 *
1870 * @param doc the doc to write annotations for.
1871 * @param descList the array of {@link AnnotationDesc}.
1872 * @param htmltree the documentation tree to which the annotation info will be
1873 * added
1874 */
1875 private void addAnnotationInfo(Doc doc, AnnotationDesc[] descList,
1876 Content htmltree) {
1877 addAnnotationInfo(0, doc, descList, true, htmltree);
1878 }
1880 /**
1881 * Adds the annotation types for the given doc.
1882 *
1883 * @param indent the number of extra spaces to indent the annotations.
1884 * @param doc the doc to write annotations for.
1885 * @param descList the array of {@link AnnotationDesc}.
1886 * @param htmltree the documentation tree to which the annotation info will be
1887 * added
1888 */
1889 private boolean addAnnotationInfo(int indent, Doc doc,
1890 AnnotationDesc[] descList, boolean lineBreak, Content htmltree) {
1891 List<Content> annotations = getAnnotations(indent, descList, lineBreak);
1892 String sep ="";
1893 if (annotations.isEmpty()) {
1894 return false;
1895 }
1896 for (Content annotation: annotations) {
1897 htmltree.addContent(sep);
1898 htmltree.addContent(annotation);
1899 sep = " ";
1900 }
1901 return true;
1902 }
1904 /**
1905 * Return the string representations of the annotation types for
1906 * the given doc.
1907 *
1908 * @param indent the number of extra spaces to indent the annotations.
1909 * @param descList the array of {@link AnnotationDesc}.
1910 * @param linkBreak if true, add new line between each member value.
1911 * @return an array of strings representing the annotations being
1912 * documented.
1913 */
1914 private List<Content> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak) {
1915 return getAnnotations(indent, descList, linkBreak, true);
1916 }
1918 /**
1919 * Return the string representations of the annotation types for
1920 * the given doc.
1921 *
1922 * A {@code null} {@code elementType} indicates that all the
1923 * annotations should be returned without any filtering.
1924 *
1925 * @param indent the number of extra spaces to indent the annotations.
1926 * @param descList the array of {@link AnnotationDesc}.
1927 * @param linkBreak if true, add new line between each member value.
1928 * @param elementType the type of targeted element (used for filtering
1929 * type annotations from declaration annotations)
1930 * @return an array of strings representing the annotations being
1931 * documented.
1932 */
1933 public List<Content> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak,
1934 boolean isJava5DeclarationLocation) {
1935 List<Content> results = new ArrayList<Content>();
1936 ContentBuilder annotation;
1937 for (int i = 0; i < descList.length; i++) {
1938 AnnotationTypeDoc annotationDoc = descList[i].annotationType();
1939 // If an annotation is not documented, do not add it to the list. If
1940 // the annotation is of a repeatable type, and if it is not documented
1941 // and also if its container annotation is not documented, do not add it
1942 // to the list. If an annotation of a repeatable type is not documented
1943 // but its container is documented, it will be added to the list.
1944 if (! Util.isDocumentedAnnotation(annotationDoc) &&
1945 (!isAnnotationDocumented && !isContainerDocumented)) {
1946 continue;
1947 }
1948 /* TODO: check logic here to correctly handle declaration
1949 * and type annotations.
1950 if (Util.isDeclarationAnnotation(annotationDoc, isJava5DeclarationLocation)) {
1951 continue;
1952 }*/
1953 annotation = new ContentBuilder();
1954 isAnnotationDocumented = false;
1955 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
1956 LinkInfoImpl.Kind.ANNOTATION, annotationDoc);
1957 AnnotationDesc.ElementValuePair[] pairs = descList[i].elementValues();
1958 // If the annotation is synthesized, do not print the container.
1959 if (descList[i].isSynthesized()) {
1960 for (int j = 0; j < pairs.length; j++) {
1961 AnnotationValue annotationValue = pairs[j].value();
1962 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
1963 if (annotationValue.value() instanceof AnnotationValue[]) {
1964 AnnotationValue[] annotationArray =
1965 (AnnotationValue[]) annotationValue.value();
1966 annotationTypeValues.addAll(Arrays.asList(annotationArray));
1967 } else {
1968 annotationTypeValues.add(annotationValue);
1969 }
1970 String sep = "";
1971 for (AnnotationValue av : annotationTypeValues) {
1972 annotation.addContent(sep);
1973 annotation.addContent(annotationValueToContent(av));
1974 sep = " ";
1975 }
1976 }
1977 }
1978 else if (isAnnotationArray(pairs)) {
1979 // If the container has 1 or more value defined and if the
1980 // repeatable type annotation is not documented, do not print
1981 // the container.
1982 if (pairs.length == 1 && isAnnotationDocumented) {
1983 AnnotationValue[] annotationArray =
1984 (AnnotationValue[]) (pairs[0].value()).value();
1985 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
1986 annotationTypeValues.addAll(Arrays.asList(annotationArray));
1987 String sep = "";
1988 for (AnnotationValue av : annotationTypeValues) {
1989 annotation.addContent(sep);
1990 annotation.addContent(annotationValueToContent(av));
1991 sep = " ";
1992 }
1993 }
1994 // If the container has 1 or more value defined and if the
1995 // repeatable type annotation is not documented, print the container.
1996 else {
1997 addAnnotations(annotationDoc, linkInfo, annotation, pairs,
1998 indent, false);
1999 }
2000 }
2001 else {
2002 addAnnotations(annotationDoc, linkInfo, annotation, pairs,
2003 indent, linkBreak);
2004 }
2005 annotation.addContent(linkBreak ? DocletConstants.NL : "");
2006 results.add(annotation);
2007 }
2008 return results;
2009 }
2011 /**
2012 * Add annotation to the annotation string.
2013 *
2014 * @param annotationDoc the annotation being documented
2015 * @param linkInfo the information about the link
2016 * @param annotation the annotation string to which the annotation will be added
2017 * @param pairs annotation type element and value pairs
2018 * @param indent the number of extra spaces to indent the annotations.
2019 * @param linkBreak if true, add new line between each member value
2020 */
2021 private void addAnnotations(AnnotationTypeDoc annotationDoc, LinkInfoImpl linkInfo,
2022 ContentBuilder annotation, AnnotationDesc.ElementValuePair[] pairs,
2023 int indent, boolean linkBreak) {
2024 linkInfo.label = new StringContent("@" + annotationDoc.name());
2025 annotation.addContent(getLink(linkInfo));
2026 if (pairs.length > 0) {
2027 annotation.addContent("(");
2028 for (int j = 0; j < pairs.length; j++) {
2029 if (j > 0) {
2030 annotation.addContent(",");
2031 if (linkBreak) {
2032 annotation.addContent(DocletConstants.NL);
2033 int spaces = annotationDoc.name().length() + 2;
2034 for (int k = 0; k < (spaces + indent); k++) {
2035 annotation.addContent(" ");
2036 }
2037 }
2038 }
2039 annotation.addContent(getDocLink(LinkInfoImpl.Kind.ANNOTATION,
2040 pairs[j].element(), pairs[j].element().name(), false));
2041 annotation.addContent("=");
2042 AnnotationValue annotationValue = pairs[j].value();
2043 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
2044 if (annotationValue.value() instanceof AnnotationValue[]) {
2045 AnnotationValue[] annotationArray =
2046 (AnnotationValue[]) annotationValue.value();
2047 annotationTypeValues.addAll(Arrays.asList(annotationArray));
2048 } else {
2049 annotationTypeValues.add(annotationValue);
2050 }
2051 annotation.addContent(annotationTypeValues.size() == 1 ? "" : "{");
2052 String sep = "";
2053 for (AnnotationValue av : annotationTypeValues) {
2054 annotation.addContent(sep);
2055 annotation.addContent(annotationValueToContent(av));
2056 sep = ",";
2057 }
2058 annotation.addContent(annotationTypeValues.size() == 1 ? "" : "}");
2059 isContainerDocumented = false;
2060 }
2061 annotation.addContent(")");
2062 }
2063 }
2065 /**
2066 * Check if the annotation contains an array of annotation as a value. This
2067 * check is to verify if a repeatable type annotation is present or not.
2068 *
2069 * @param pairs annotation type element and value pairs
2070 *
2071 * @return true if the annotation contains an array of annotation as a value.
2072 */
2073 private boolean isAnnotationArray(AnnotationDesc.ElementValuePair[] pairs) {
2074 AnnotationValue annotationValue;
2075 for (int j = 0; j < pairs.length; j++) {
2076 annotationValue = pairs[j].value();
2077 if (annotationValue.value() instanceof AnnotationValue[]) {
2078 AnnotationValue[] annotationArray =
2079 (AnnotationValue[]) annotationValue.value();
2080 if (annotationArray.length > 1) {
2081 if (annotationArray[0].value() instanceof AnnotationDesc) {
2082 AnnotationTypeDoc annotationDoc =
2083 ((AnnotationDesc) annotationArray[0].value()).annotationType();
2084 isContainerDocumented = true;
2085 if (Util.isDocumentedAnnotation(annotationDoc)) {
2086 isAnnotationDocumented = true;
2087 }
2088 return true;
2089 }
2090 }
2091 }
2092 }
2093 return false;
2094 }
2096 private Content annotationValueToContent(AnnotationValue annotationValue) {
2097 if (annotationValue.value() instanceof Type) {
2098 Type type = (Type) annotationValue.value();
2099 if (type.asClassDoc() != null) {
2100 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
2101 LinkInfoImpl.Kind.ANNOTATION, type);
2102 linkInfo.label = new StringContent((type.asClassDoc().isIncluded() ?
2103 type.typeName() :
2104 type.qualifiedTypeName()) + type.dimension() + ".class");
2105 return getLink(linkInfo);
2106 } else {
2107 return new StringContent(type.typeName() + type.dimension() + ".class");
2108 }
2109 } else if (annotationValue.value() instanceof AnnotationDesc) {
2110 List<Content> list = getAnnotations(0,
2111 new AnnotationDesc[]{(AnnotationDesc) annotationValue.value()},
2112 false);
2113 ContentBuilder buf = new ContentBuilder();
2114 for (Content c: list) {
2115 buf.addContent(c);
2116 }
2117 return buf;
2118 } else if (annotationValue.value() instanceof MemberDoc) {
2119 return getDocLink(LinkInfoImpl.Kind.ANNOTATION,
2120 (MemberDoc) annotationValue.value(),
2121 ((MemberDoc) annotationValue.value()).name(), false);
2122 } else {
2123 return new StringContent(annotationValue.toString());
2124 }
2125 }
2127 /**
2128 * Return the configuation for this doclet.
2129 *
2130 * @return the configuration for this doclet.
2131 */
2132 public Configuration configuration() {
2133 return configuration;
2134 }
2135 }