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

Tue, 27 Aug 2013 11:41:39 -0700

author
bpatel
date
Tue, 27 Aug 2013 11:41:39 -0700
changeset 1981
7fb27bc201cc
parent 1936
33294f02c9a5
child 1995
dd64288f5659
permissions
-rw-r--r--

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

mercurial