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

Wed, 23 Jan 2013 13:27:24 -0800

author
jjg
date
Wed, 23 Jan 2013 13:27:24 -0800
changeset 1521
71f35e4b93a5
parent 1477
8c0c63a6e3b7
child 1570
f91144b7da75
permissions
-rw-r--r--

8006775: JSR 308: Compiler changes in JDK8
Reviewed-by: jjg
Contributed-by: mernst@cs.washington.edu, wmdietl@cs.washington.edu, mpapi@csail.mit.edu, mahmood@notnoop.com

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

mercurial