src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java

Fri, 04 Oct 2013 13:32:30 -0700

author
bpatel
date
Fri, 04 Oct 2013 13:32:30 -0700
changeset 2084
6e186ca11ec0
parent 2035
a2a5ad0853ed
child 2101
933ba3f81a87
permissions
-rw-r--r--

8008164: Invisible table captions in javadoc-generated html
Reviewed-by: jjg

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

mercurial