Tue, 14 May 2013 10:14:55 -0700
8012183: replace some uses of Configuration.getText with Configuration.getResource
Reviewed-by: darcy
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 TagletOutputImpl output = new TagletOutputImpl();
250 TagletWriter.genTagOuput(configuration.tagletManager, doc,
251 configuration.tagletManager.getCustomTags(doc),
252 getTagletWriterInstance(false), output);
253 dl.addContent(output.getContent());
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 TagletOutputImpl output = new TagletOutputImpl();
266 TagletWriter.genTagOuput(configuration.tagletManager, field,
267 configuration.tagletManager.getCustomTags(field),
268 getTagletWriterInstance(false), output);
269 return !output.getContent().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 TagletOutput output = TagletWriter.getInlineTagOuput(
1587 configuration.tagletManager, holderTag,
1588 tagelem, getTagletWriterInstance(isFirstSentence));
1589 if (output != null)
1590 result.addContent(((TagletOutputImpl) output).getContent());
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 StringTokenizer lines = new StringTokenizer(text, "\r\n", true);
1624 StringBuilder textBuff = new StringBuilder();
1625 while (lines.hasMoreTokens()) {
1626 StringBuilder line = new StringBuilder(lines.nextToken());
1627 Util.replaceTabs(configuration, line);
1628 textBuff.append(line.toString());
1629 }
1630 result.addContent(new RawHtml(textBuff.toString()));
1631 }
1632 }
1633 return result;
1634 }
1636 /**
1637 * Return true if relative links should not be redirected.
1638 *
1639 * @return Return true if a relative link should not be redirected.
1640 */
1641 private boolean shouldNotRedirectRelativeLinks() {
1642 return this instanceof AnnotationTypeWriter ||
1643 this instanceof ClassWriter ||
1644 this instanceof PackageSummaryWriter;
1645 }
1647 /**
1648 * Suppose a piece of documentation has a relative link. When you copy
1649 * that documentation to another place such as the index or class-use page,
1650 * that relative link will no longer work. We should redirect those links
1651 * so that they will work again.
1652 * <p>
1653 * Here is the algorithm used to fix the link:
1654 * <p>
1655 * {@literal <relative link> => docRoot + <relative path to file> + <relative link> }
1656 * <p>
1657 * For example, suppose com.sun.javadoc.RootDoc has this link:
1658 * {@literal <a href="package-summary.html">The package Page</a> }
1659 * <p>
1660 * If this link appeared in the index, we would redirect
1661 * the link like this:
1662 *
1663 * {@literal <a href="./com/sun/javadoc/package-summary.html">The package Page</a>}
1664 *
1665 * @param doc the Doc object whose documentation is being written.
1666 * @param text the text being written.
1667 *
1668 * @return the text, with all the relative links redirected to work.
1669 */
1670 private String redirectRelativeLinks(Doc doc, String text) {
1671 if (doc == null || shouldNotRedirectRelativeLinks()) {
1672 return text;
1673 }
1675 DocPath redirectPathFromRoot;
1676 if (doc instanceof ClassDoc) {
1677 redirectPathFromRoot = DocPath.forPackage(((ClassDoc) doc).containingPackage());
1678 } else if (doc instanceof MemberDoc) {
1679 redirectPathFromRoot = DocPath.forPackage(((MemberDoc) doc).containingPackage());
1680 } else if (doc instanceof PackageDoc) {
1681 redirectPathFromRoot = DocPath.forPackage((PackageDoc) doc);
1682 } else {
1683 return text;
1684 }
1686 //Redirect all relative links.
1687 int end, begin = text.toLowerCase().indexOf("<a");
1688 if(begin >= 0){
1689 StringBuilder textBuff = new StringBuilder(text);
1691 while(begin >=0){
1692 if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
1693 begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
1694 continue;
1695 }
1697 begin = textBuff.indexOf("=", begin) + 1;
1698 end = textBuff.indexOf(">", begin +1);
1699 if(begin == 0){
1700 //Link has no equal symbol.
1701 configuration.root.printWarning(
1702 doc.position(),
1703 configuration.getText("doclet.malformed_html_link_tag", text));
1704 break;
1705 }
1706 if (end == -1) {
1707 //Break without warning. This <a> tag is not necessarily malformed. The text
1708 //might be missing '>' character because the href has an inline tag.
1709 break;
1710 }
1711 if (textBuff.substring(begin, end).indexOf("\"") != -1){
1712 begin = textBuff.indexOf("\"", begin) + 1;
1713 end = textBuff.indexOf("\"", begin +1);
1714 if (begin == 0 || end == -1){
1715 //Link is missing a quote.
1716 break;
1717 }
1718 }
1719 String relativeLink = textBuff.substring(begin, end);
1720 if (!(relativeLink.toLowerCase().startsWith("mailto:") ||
1721 relativeLink.toLowerCase().startsWith("http:") ||
1722 relativeLink.toLowerCase().startsWith("https:") ||
1723 relativeLink.toLowerCase().startsWith("file:"))) {
1724 relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/"
1725 + redirectPathFromRoot.resolve(relativeLink).getPath();
1726 textBuff.replace(begin, end, relativeLink);
1727 }
1728 begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
1729 }
1730 return textBuff.toString();
1731 }
1732 return text;
1733 }
1735 public String removeNonInlineHtmlTags(String text) {
1736 if (text.indexOf('<') < 0) {
1737 return text;
1738 }
1739 String noninlinetags[] = { "<ul>", "</ul>", "<ol>", "</ol>",
1740 "<dl>", "</dl>", "<table>", "</table>",
1741 "<tr>", "</tr>", "<td>", "</td>",
1742 "<th>", "</th>", "<p>", "</p>",
1743 "<li>", "</li>", "<dd>", "</dd>",
1744 "<dir>", "</dir>", "<dt>", "</dt>",
1745 "<h1>", "</h1>", "<h2>", "</h2>",
1746 "<h3>", "</h3>", "<h4>", "</h4>",
1747 "<h5>", "</h5>", "<h6>", "</h6>",
1748 "<pre>", "</pre>", "<menu>", "</menu>",
1749 "<listing>", "</listing>", "<hr>",
1750 "<blockquote>", "</blockquote>",
1751 "<center>", "</center>",
1752 "<UL>", "</UL>", "<OL>", "</OL>",
1753 "<DL>", "</DL>", "<TABLE>", "</TABLE>",
1754 "<TR>", "</TR>", "<TD>", "</TD>",
1755 "<TH>", "</TH>", "<P>", "</P>",
1756 "<LI>", "</LI>", "<DD>", "</DD>",
1757 "<DIR>", "</DIR>", "<DT>", "</DT>",
1758 "<H1>", "</H1>", "<H2>", "</H2>",
1759 "<H3>", "</H3>", "<H4>", "</H4>",
1760 "<H5>", "</H5>", "<H6>", "</H6>",
1761 "<PRE>", "</PRE>", "<MENU>", "</MENU>",
1762 "<LISTING>", "</LISTING>", "<HR>",
1763 "<BLOCKQUOTE>", "</BLOCKQUOTE>",
1764 "<CENTER>", "</CENTER>"
1765 };
1766 for (int i = 0; i < noninlinetags.length; i++) {
1767 text = replace(text, noninlinetags[i], "");
1768 }
1769 return text;
1770 }
1772 public String replace(String text, String tobe, String by) {
1773 while (true) {
1774 int startindex = text.indexOf(tobe);
1775 if (startindex < 0) {
1776 return text;
1777 }
1778 int endindex = startindex + tobe.length();
1779 StringBuilder replaced = new StringBuilder();
1780 if (startindex > 0) {
1781 replaced.append(text.substring(0, startindex));
1782 }
1783 replaced.append(by);
1784 if (text.length() > endindex) {
1785 replaced.append(text.substring(endindex));
1786 }
1787 text = replaced.toString();
1788 }
1789 }
1791 /**
1792 * Returns a link to the stylesheet file.
1793 *
1794 * @return an HtmlTree for the lINK tag which provides the stylesheet location
1795 */
1796 public HtmlTree getStyleSheetProperties() {
1797 String stylesheetfile = configuration.stylesheetfile;
1798 DocPath stylesheet;
1799 if (stylesheetfile.isEmpty()) {
1800 stylesheet = DocPaths.STYLESHEET;
1801 } else {
1802 DocFile file = DocFile.createFileForInput(configuration, stylesheetfile);
1803 stylesheet = DocPath.create(file.getName());
1804 }
1805 HtmlTree link = HtmlTree.LINK("stylesheet", "text/css",
1806 pathToRoot.resolve(stylesheet).getPath(),
1807 "Style");
1808 return link;
1809 }
1811 /**
1812 * Returns a link to the JavaScript file.
1813 *
1814 * @return an HtmlTree for the Script tag which provides the JavaScript location
1815 */
1816 public HtmlTree getScriptProperties() {
1817 HtmlTree script = HtmlTree.SCRIPT("text/javascript",
1818 pathToRoot.resolve(DocPaths.JAVASCRIPT).getPath());
1819 return script;
1820 }
1822 /**
1823 * According to
1824 * <cite>The Java™ Language Specification</cite>,
1825 * all the outer classes and static nested classes are core classes.
1826 */
1827 public boolean isCoreClass(ClassDoc cd) {
1828 return cd.containingClass() == null || cd.isStatic();
1829 }
1831 /**
1832 * Adds the annotatation types for the given packageDoc.
1833 *
1834 * @param packageDoc the package to write annotations for.
1835 * @param htmltree the documentation tree to which the annotation info will be
1836 * added
1837 */
1838 public void addAnnotationInfo(PackageDoc packageDoc, Content htmltree) {
1839 addAnnotationInfo(packageDoc, packageDoc.annotations(), htmltree);
1840 }
1842 /**
1843 * Add the annotation types of the executable receiver.
1844 *
1845 * @param method the executable to write the receiver annotations for.
1846 * @param descList list of annotation description.
1847 * @param htmltree the documentation tree to which the annotation info will be
1848 * added
1849 */
1850 public void addReceiverAnnotationInfo(ExecutableMemberDoc method, AnnotationDesc[] descList,
1851 Content htmltree) {
1852 addAnnotationInfo(0, method, descList, false, htmltree);
1853 }
1855 /**
1856 * Adds the annotatation types for the given doc.
1857 *
1858 * @param doc the package to write annotations for
1859 * @param htmltree the content tree to which the annotation types will be added
1860 */
1861 public void addAnnotationInfo(ProgramElementDoc doc, Content htmltree) {
1862 addAnnotationInfo(doc, doc.annotations(), htmltree);
1863 }
1865 /**
1866 * Add the annotatation types for the given doc and parameter.
1867 *
1868 * @param indent the number of spaces to indent the parameters.
1869 * @param doc the doc to write annotations for.
1870 * @param param the parameter to write annotations for.
1871 * @param tree the content tree to which the annotation types will be added
1872 */
1873 public boolean addAnnotationInfo(int indent, Doc doc, Parameter param,
1874 Content tree) {
1875 return addAnnotationInfo(indent, doc, param.annotations(), false, tree);
1876 }
1878 /**
1879 * Adds the annotatation types for the given doc.
1880 *
1881 * @param doc the doc to write annotations for.
1882 * @param descList the array of {@link AnnotationDesc}.
1883 * @param htmltree the documentation tree to which the annotation info will be
1884 * added
1885 */
1886 private void addAnnotationInfo(Doc doc, AnnotationDesc[] descList,
1887 Content htmltree) {
1888 addAnnotationInfo(0, doc, descList, true, htmltree);
1889 }
1891 /**
1892 * Adds the annotation types for the given doc.
1893 *
1894 * @param indent the number of extra spaces to indent the annotations.
1895 * @param doc the doc to write annotations for.
1896 * @param descList the array of {@link AnnotationDesc}.
1897 * @param htmltree the documentation tree to which the annotation info will be
1898 * added
1899 */
1900 private boolean addAnnotationInfo(int indent, Doc doc,
1901 AnnotationDesc[] descList, boolean lineBreak, Content htmltree) {
1902 List<Content> annotations = getAnnotations(indent, descList, lineBreak);
1903 String sep ="";
1904 if (annotations.isEmpty()) {
1905 return false;
1906 }
1907 for (Content annotation: annotations) {
1908 htmltree.addContent(sep);
1909 htmltree.addContent(annotation);
1910 sep = " ";
1911 }
1912 return true;
1913 }
1915 /**
1916 * Return the string representations of the annotation types for
1917 * the given doc.
1918 *
1919 * @param indent the number of extra spaces to indent the annotations.
1920 * @param descList the array of {@link AnnotationDesc}.
1921 * @param linkBreak if true, add new line between each member value.
1922 * @return an array of strings representing the annotations being
1923 * documented.
1924 */
1925 private List<Content> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak) {
1926 return getAnnotations(indent, descList, linkBreak, true);
1927 }
1929 /**
1930 * Return the string representations of the annotation types for
1931 * the given doc.
1932 *
1933 * A {@code null} {@code elementType} indicates that all the
1934 * annotations should be returned without any filtering.
1935 *
1936 * @param indent the number of extra spaces to indent the annotations.
1937 * @param descList the array of {@link AnnotationDesc}.
1938 * @param linkBreak if true, add new line between each member value.
1939 * @param elementType the type of targeted element (used for filtering
1940 * type annotations from declaration annotations)
1941 * @return an array of strings representing the annotations being
1942 * documented.
1943 */
1944 public List<Content> getAnnotations(int indent, AnnotationDesc[] descList, boolean linkBreak,
1945 boolean isJava5DeclarationLocation) {
1946 List<Content> results = new ArrayList<Content>();
1947 ContentBuilder annotation;
1948 for (int i = 0; i < descList.length; i++) {
1949 AnnotationTypeDoc annotationDoc = descList[i].annotationType();
1950 // If an annotation is not documented, do not add it to the list. If
1951 // the annotation is of a repeatable type, and if it is not documented
1952 // and also if its container annotation is not documented, do not add it
1953 // to the list. If an annotation of a repeatable type is not documented
1954 // but its container is documented, it will be added to the list.
1955 if (! Util.isDocumentedAnnotation(annotationDoc) &&
1956 (!isAnnotationDocumented && !isContainerDocumented)) {
1957 continue;
1958 }
1959 /* TODO: check logic here to correctly handle declaration
1960 * and type annotations.
1961 if (Util.isDeclarationAnnotation(annotationDoc, isJava5DeclarationLocation)) {
1962 continue;
1963 }*/
1964 annotation = new ContentBuilder();
1965 isAnnotationDocumented = false;
1966 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
1967 LinkInfoImpl.Kind.ANNOTATION, annotationDoc);
1968 AnnotationDesc.ElementValuePair[] pairs = descList[i].elementValues();
1969 // If the annotation is synthesized, do not print the container.
1970 if (descList[i].isSynthesized()) {
1971 for (int j = 0; j < pairs.length; j++) {
1972 AnnotationValue annotationValue = pairs[j].value();
1973 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
1974 if (annotationValue.value() instanceof AnnotationValue[]) {
1975 AnnotationValue[] annotationArray =
1976 (AnnotationValue[]) annotationValue.value();
1977 annotationTypeValues.addAll(Arrays.asList(annotationArray));
1978 } else {
1979 annotationTypeValues.add(annotationValue);
1980 }
1981 String sep = "";
1982 for (AnnotationValue av : annotationTypeValues) {
1983 annotation.addContent(sep);
1984 annotation.addContent(annotationValueToContent(av));
1985 sep = " ";
1986 }
1987 }
1988 }
1989 else if (isAnnotationArray(pairs)) {
1990 // If the container has 1 or more value defined and if the
1991 // repeatable type annotation is not documented, do not print
1992 // the container.
1993 if (pairs.length == 1 && isAnnotationDocumented) {
1994 AnnotationValue[] annotationArray =
1995 (AnnotationValue[]) (pairs[0].value()).value();
1996 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
1997 annotationTypeValues.addAll(Arrays.asList(annotationArray));
1998 String sep = "";
1999 for (AnnotationValue av : annotationTypeValues) {
2000 annotation.addContent(sep);
2001 annotation.addContent(annotationValueToContent(av));
2002 sep = " ";
2003 }
2004 }
2005 // If the container has 1 or more value defined and if the
2006 // repeatable type annotation is not documented, print the container.
2007 else {
2008 addAnnotations(annotationDoc, linkInfo, annotation, pairs,
2009 indent, false);
2010 }
2011 }
2012 else {
2013 addAnnotations(annotationDoc, linkInfo, annotation, pairs,
2014 indent, linkBreak);
2015 }
2016 annotation.addContent(linkBreak ? DocletConstants.NL : "");
2017 results.add(annotation);
2018 }
2019 return results;
2020 }
2022 /**
2023 * Add annotation to the annotation string.
2024 *
2025 * @param annotationDoc the annotation being documented
2026 * @param linkInfo the information about the link
2027 * @param annotation the annotation string to which the annotation will be added
2028 * @param pairs annotation type element and value pairs
2029 * @param indent the number of extra spaces to indent the annotations.
2030 * @param linkBreak if true, add new line between each member value
2031 */
2032 private void addAnnotations(AnnotationTypeDoc annotationDoc, LinkInfoImpl linkInfo,
2033 ContentBuilder annotation, AnnotationDesc.ElementValuePair[] pairs,
2034 int indent, boolean linkBreak) {
2035 linkInfo.label = new StringContent("@" + annotationDoc.name());
2036 annotation.addContent(getLink(linkInfo));
2037 if (pairs.length > 0) {
2038 annotation.addContent("(");
2039 for (int j = 0; j < pairs.length; j++) {
2040 if (j > 0) {
2041 annotation.addContent(",");
2042 if (linkBreak) {
2043 annotation.addContent(DocletConstants.NL);
2044 int spaces = annotationDoc.name().length() + 2;
2045 for (int k = 0; k < (spaces + indent); k++) {
2046 annotation.addContent(" ");
2047 }
2048 }
2049 }
2050 annotation.addContent(getDocLink(LinkInfoImpl.Kind.ANNOTATION,
2051 pairs[j].element(), pairs[j].element().name(), false));
2052 annotation.addContent("=");
2053 AnnotationValue annotationValue = pairs[j].value();
2054 List<AnnotationValue> annotationTypeValues = new ArrayList<AnnotationValue>();
2055 if (annotationValue.value() instanceof AnnotationValue[]) {
2056 AnnotationValue[] annotationArray =
2057 (AnnotationValue[]) annotationValue.value();
2058 annotationTypeValues.addAll(Arrays.asList(annotationArray));
2059 } else {
2060 annotationTypeValues.add(annotationValue);
2061 }
2062 annotation.addContent(annotationTypeValues.size() == 1 ? "" : "{");
2063 String sep = "";
2064 for (AnnotationValue av : annotationTypeValues) {
2065 annotation.addContent(sep);
2066 annotation.addContent(annotationValueToContent(av));
2067 sep = ",";
2068 }
2069 annotation.addContent(annotationTypeValues.size() == 1 ? "" : "}");
2070 isContainerDocumented = false;
2071 }
2072 annotation.addContent(")");
2073 }
2074 }
2076 /**
2077 * Check if the annotation contains an array of annotation as a value. This
2078 * check is to verify if a repeatable type annotation is present or not.
2079 *
2080 * @param pairs annotation type element and value pairs
2081 *
2082 * @return true if the annotation contains an array of annotation as a value.
2083 */
2084 private boolean isAnnotationArray(AnnotationDesc.ElementValuePair[] pairs) {
2085 AnnotationValue annotationValue;
2086 for (int j = 0; j < pairs.length; j++) {
2087 annotationValue = pairs[j].value();
2088 if (annotationValue.value() instanceof AnnotationValue[]) {
2089 AnnotationValue[] annotationArray =
2090 (AnnotationValue[]) annotationValue.value();
2091 if (annotationArray.length > 1) {
2092 if (annotationArray[0].value() instanceof AnnotationDesc) {
2093 AnnotationTypeDoc annotationDoc =
2094 ((AnnotationDesc) annotationArray[0].value()).annotationType();
2095 isContainerDocumented = true;
2096 if (Util.isDocumentedAnnotation(annotationDoc)) {
2097 isAnnotationDocumented = true;
2098 }
2099 return true;
2100 }
2101 }
2102 }
2103 }
2104 return false;
2105 }
2107 private Content annotationValueToContent(AnnotationValue annotationValue) {
2108 if (annotationValue.value() instanceof Type) {
2109 Type type = (Type) annotationValue.value();
2110 if (type.asClassDoc() != null) {
2111 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
2112 LinkInfoImpl.Kind.ANNOTATION, type);
2113 linkInfo.label = new StringContent((type.asClassDoc().isIncluded() ?
2114 type.typeName() :
2115 type.qualifiedTypeName()) + type.dimension() + ".class");
2116 return getLink(linkInfo);
2117 } else {
2118 return new StringContent(type.typeName() + type.dimension() + ".class");
2119 }
2120 } else if (annotationValue.value() instanceof AnnotationDesc) {
2121 List<Content> list = getAnnotations(0,
2122 new AnnotationDesc[]{(AnnotationDesc) annotationValue.value()},
2123 false);
2124 ContentBuilder buf = new ContentBuilder();
2125 for (Content c: list) {
2126 buf.addContent(c);
2127 }
2128 return buf;
2129 } else if (annotationValue.value() instanceof MemberDoc) {
2130 return getDocLink(LinkInfoImpl.Kind.ANNOTATION,
2131 (MemberDoc) annotationValue.value(),
2132 ((MemberDoc) annotationValue.value()).name(), false);
2133 } else {
2134 return new StringContent(annotationValue.toString());
2135 }
2136 }
2138 /**
2139 * Return the configuation for this doclet.
2140 *
2141 * @return the configuration for this doclet.
2142 */
2143 public Configuration configuration() {
2144 return configuration;
2145 }
2146 }