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

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 2233
4a6f853f8721
parent 0
959103a6100f
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.doclets.formats.html;
aoqi@0 27
aoqi@0 28 import java.util.*;
aoqi@0 29
aoqi@0 30 import com.sun.javadoc.*;
aoqi@0 31 import com.sun.tools.javac.jvm.Profile;
aoqi@0 32 import com.sun.tools.javadoc.RootDocImpl;
aoqi@0 33 import com.sun.tools.doclets.formats.html.markup.*;
aoqi@0 34 import com.sun.tools.doclets.internal.toolkit.*;
aoqi@0 35 import com.sun.tools.doclets.internal.toolkit.builders.*;
aoqi@0 36 import com.sun.tools.doclets.internal.toolkit.taglets.*;
aoqi@0 37 import com.sun.tools.doclets.internal.toolkit.util.*;
aoqi@0 38 import java.io.IOException;
aoqi@0 39
aoqi@0 40 /**
aoqi@0 41 * Generate the Class Information Page.
aoqi@0 42 *
aoqi@0 43 * <p><b>This is NOT part of any supported API.
aoqi@0 44 * If you write code that depends on this, you do so at your own risk.
aoqi@0 45 * This code and its internal interfaces are subject to change or
aoqi@0 46 * deletion without notice.</b>
aoqi@0 47 *
aoqi@0 48 * @see com.sun.javadoc.ClassDoc
aoqi@0 49 * @see java.util.Collections
aoqi@0 50 * @see java.util.List
aoqi@0 51 * @see java.util.ArrayList
aoqi@0 52 * @see java.util.HashMap
aoqi@0 53 *
aoqi@0 54 * @author Atul M Dambalkar
aoqi@0 55 * @author Robert Field
aoqi@0 56 * @author Bhavesh Patel (Modified)
aoqi@0 57 */
aoqi@0 58 public class ClassWriterImpl extends SubWriterHolderWriter
aoqi@0 59 implements ClassWriter {
aoqi@0 60
aoqi@0 61 protected final ClassDoc classDoc;
aoqi@0 62
aoqi@0 63 protected final ClassTree classtree;
aoqi@0 64
aoqi@0 65 protected final ClassDoc prev;
aoqi@0 66
aoqi@0 67 protected final ClassDoc next;
aoqi@0 68
aoqi@0 69 /**
aoqi@0 70 * @param configuration the configuration data for the doclet
aoqi@0 71 * @param classDoc the class being documented.
aoqi@0 72 * @param prevClass the previous class that was documented.
aoqi@0 73 * @param nextClass the next class being documented.
aoqi@0 74 * @param classTree the class tree for the given class.
aoqi@0 75 */
aoqi@0 76 public ClassWriterImpl (ConfigurationImpl configuration, ClassDoc classDoc,
aoqi@0 77 ClassDoc prevClass, ClassDoc nextClass, ClassTree classTree)
aoqi@0 78 throws IOException {
aoqi@0 79 super(configuration, DocPath.forClass(classDoc));
aoqi@0 80 this.classDoc = classDoc;
aoqi@0 81 configuration.currentcd = classDoc;
aoqi@0 82 this.classtree = classTree;
aoqi@0 83 this.prev = prevClass;
aoqi@0 84 this.next = nextClass;
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 /**
aoqi@0 88 * Get this package link.
aoqi@0 89 *
aoqi@0 90 * @return a content tree for the package link
aoqi@0 91 */
aoqi@0 92 protected Content getNavLinkPackage() {
aoqi@0 93 Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY,
aoqi@0 94 packageLabel);
aoqi@0 95 Content li = HtmlTree.LI(linkContent);
aoqi@0 96 return li;
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 /**
aoqi@0 100 * Get the class link.
aoqi@0 101 *
aoqi@0 102 * @return a content tree for the class link
aoqi@0 103 */
aoqi@0 104 protected Content getNavLinkClass() {
aoqi@0 105 Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, classLabel);
aoqi@0 106 return li;
aoqi@0 107 }
aoqi@0 108
aoqi@0 109 /**
aoqi@0 110 * Get the class use link.
aoqi@0 111 *
aoqi@0 112 * @return a content tree for the class use link
aoqi@0 113 */
aoqi@0 114 protected Content getNavLinkClassUse() {
aoqi@0 115 Content linkContent = getHyperLink(DocPaths.CLASS_USE.resolve(filename), useLabel);
aoqi@0 116 Content li = HtmlTree.LI(linkContent);
aoqi@0 117 return li;
aoqi@0 118 }
aoqi@0 119
aoqi@0 120 /**
aoqi@0 121 * Get link to previous class.
aoqi@0 122 *
aoqi@0 123 * @return a content tree for the previous class link
aoqi@0 124 */
aoqi@0 125 public Content getNavLinkPrevious() {
aoqi@0 126 Content li;
aoqi@0 127 if (prev != null) {
aoqi@0 128 Content prevLink = getLink(new LinkInfoImpl(configuration,
aoqi@0 129 LinkInfoImpl.Kind.CLASS, prev)
aoqi@0 130 .label(prevclassLabel).strong(true));
aoqi@0 131 li = HtmlTree.LI(prevLink);
aoqi@0 132 }
aoqi@0 133 else
aoqi@0 134 li = HtmlTree.LI(prevclassLabel);
aoqi@0 135 return li;
aoqi@0 136 }
aoqi@0 137
aoqi@0 138 /**
aoqi@0 139 * Get link to next class.
aoqi@0 140 *
aoqi@0 141 * @return a content tree for the next class link
aoqi@0 142 */
aoqi@0 143 public Content getNavLinkNext() {
aoqi@0 144 Content li;
aoqi@0 145 if (next != null) {
aoqi@0 146 Content nextLink = getLink(new LinkInfoImpl(configuration,
aoqi@0 147 LinkInfoImpl.Kind.CLASS, next)
aoqi@0 148 .label(nextclassLabel).strong(true));
aoqi@0 149 li = HtmlTree.LI(nextLink);
aoqi@0 150 }
aoqi@0 151 else
aoqi@0 152 li = HtmlTree.LI(nextclassLabel);
aoqi@0 153 return li;
aoqi@0 154 }
aoqi@0 155
aoqi@0 156 /**
aoqi@0 157 * {@inheritDoc}
aoqi@0 158 */
aoqi@0 159 public Content getHeader(String header) {
aoqi@0 160 String pkgname = (classDoc.containingPackage() != null)?
aoqi@0 161 classDoc.containingPackage().name(): "";
aoqi@0 162 String clname = classDoc.name();
aoqi@0 163 Content bodyTree = getBody(true, getWindowTitle(clname));
aoqi@0 164 addTop(bodyTree);
aoqi@0 165 addNavLinks(true, bodyTree);
aoqi@0 166 bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA);
aoqi@0 167 HtmlTree div = new HtmlTree(HtmlTag.DIV);
aoqi@0 168 div.addStyle(HtmlStyle.header);
aoqi@0 169 if (configuration.showProfiles) {
aoqi@0 170 String sep = "";
aoqi@0 171 int profile = configuration.profiles.getProfile(getTypeNameForProfile(classDoc));
aoqi@0 172 if (profile > 0) {
aoqi@0 173 Content profNameContent = new StringContent();
aoqi@0 174 for (int i = profile; i < configuration.profiles.getProfileCount(); i++) {
aoqi@0 175 profNameContent.addContent(sep);
aoqi@0 176 profNameContent.addContent(Profile.lookup(i).name);
aoqi@0 177 sep = ", ";
aoqi@0 178 }
aoqi@0 179 Content profileNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, profNameContent);
aoqi@0 180 div.addContent(profileNameDiv);
aoqi@0 181 }
aoqi@0 182 }
aoqi@0 183 if (pkgname.length() > 0) {
aoqi@0 184 Content pkgNameContent = new StringContent(pkgname);
aoqi@0 185 Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, pkgNameContent);
aoqi@0 186 div.addContent(pkgNameDiv);
aoqi@0 187 }
aoqi@0 188 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
aoqi@0 189 LinkInfoImpl.Kind.CLASS_HEADER, classDoc);
aoqi@0 190 //Let's not link to ourselves in the header.
aoqi@0 191 linkInfo.linkToSelf = false;
aoqi@0 192 Content headerContent = new StringContent(header);
aoqi@0 193 Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING, true,
aoqi@0 194 HtmlStyle.title, headerContent);
aoqi@0 195 heading.addContent(getTypeParameterLinks(linkInfo));
aoqi@0 196 div.addContent(heading);
aoqi@0 197 bodyTree.addContent(div);
aoqi@0 198 return bodyTree;
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 /**
aoqi@0 202 * {@inheritDoc}
aoqi@0 203 */
aoqi@0 204 public Content getClassContentHeader() {
aoqi@0 205 return getContentHeader();
aoqi@0 206 }
aoqi@0 207
aoqi@0 208 /**
aoqi@0 209 * {@inheritDoc}
aoqi@0 210 */
aoqi@0 211 public void addFooter(Content contentTree) {
aoqi@0 212 contentTree.addContent(HtmlConstants.END_OF_CLASS_DATA);
aoqi@0 213 addNavLinks(false, contentTree);
aoqi@0 214 addBottom(contentTree);
aoqi@0 215 }
aoqi@0 216
aoqi@0 217 /**
aoqi@0 218 * {@inheritDoc}
aoqi@0 219 */
aoqi@0 220 public void printDocument(Content contentTree) throws IOException {
aoqi@0 221 printHtmlDocument(configuration.metakeywords.getMetaKeywords(classDoc),
aoqi@0 222 true, contentTree);
aoqi@0 223 }
aoqi@0 224
aoqi@0 225 /**
aoqi@0 226 * {@inheritDoc}
aoqi@0 227 */
aoqi@0 228 public Content getClassInfoTreeHeader() {
aoqi@0 229 return getMemberTreeHeader();
aoqi@0 230 }
aoqi@0 231
aoqi@0 232 /**
aoqi@0 233 * {@inheritDoc}
aoqi@0 234 */
aoqi@0 235 public Content getClassInfo(Content classInfoTree) {
aoqi@0 236 return getMemberTree(HtmlStyle.description, classInfoTree);
aoqi@0 237 }
aoqi@0 238
aoqi@0 239 /**
aoqi@0 240 * {@inheritDoc}
aoqi@0 241 */
aoqi@0 242 public void addClassSignature(String modifiers, Content classInfoTree) {
aoqi@0 243 boolean isInterface = classDoc.isInterface();
aoqi@0 244 classInfoTree.addContent(new HtmlTree(HtmlTag.BR));
aoqi@0 245 Content pre = new HtmlTree(HtmlTag.PRE);
aoqi@0 246 addAnnotationInfo(classDoc, pre);
aoqi@0 247 pre.addContent(modifiers);
aoqi@0 248 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration,
aoqi@0 249 LinkInfoImpl.Kind.CLASS_SIGNATURE, classDoc);
aoqi@0 250 //Let's not link to ourselves in the signature.
aoqi@0 251 linkInfo.linkToSelf = false;
aoqi@0 252 Content className = new StringContent(classDoc.name());
aoqi@0 253 Content parameterLinks = getTypeParameterLinks(linkInfo);
aoqi@0 254 if (configuration.linksource) {
aoqi@0 255 addSrcLink(classDoc, className, pre);
aoqi@0 256 pre.addContent(parameterLinks);
aoqi@0 257 } else {
aoqi@0 258 Content span = HtmlTree.SPAN(HtmlStyle.typeNameLabel, className);
aoqi@0 259 span.addContent(parameterLinks);
aoqi@0 260 pre.addContent(span);
aoqi@0 261 }
aoqi@0 262 if (!isInterface) {
aoqi@0 263 Type superclass = Util.getFirstVisibleSuperClass(classDoc,
aoqi@0 264 configuration);
aoqi@0 265 if (superclass != null) {
aoqi@0 266 pre.addContent(DocletConstants.NL);
aoqi@0 267 pre.addContent("extends ");
aoqi@0 268 Content link = getLink(new LinkInfoImpl(configuration,
aoqi@0 269 LinkInfoImpl.Kind.CLASS_SIGNATURE_PARENT_NAME,
aoqi@0 270 superclass));
aoqi@0 271 pre.addContent(link);
aoqi@0 272 }
aoqi@0 273 }
aoqi@0 274 Type[] implIntfacs = classDoc.interfaceTypes();
aoqi@0 275 if (implIntfacs != null && implIntfacs.length > 0) {
aoqi@0 276 int counter = 0;
aoqi@0 277 for (int i = 0; i < implIntfacs.length; i++) {
aoqi@0 278 ClassDoc classDoc = implIntfacs[i].asClassDoc();
aoqi@0 279 if (! (classDoc.isPublic() ||
aoqi@0 280 Util.isLinkable(classDoc, configuration))) {
aoqi@0 281 continue;
aoqi@0 282 }
aoqi@0 283 if (counter == 0) {
aoqi@0 284 pre.addContent(DocletConstants.NL);
aoqi@0 285 pre.addContent(isInterface? "extends " : "implements ");
aoqi@0 286 } else {
aoqi@0 287 pre.addContent(", ");
aoqi@0 288 }
aoqi@0 289 Content link = getLink(new LinkInfoImpl(configuration,
aoqi@0 290 LinkInfoImpl.Kind.CLASS_SIGNATURE_PARENT_NAME,
aoqi@0 291 implIntfacs[i]));
aoqi@0 292 pre.addContent(link);
aoqi@0 293 counter++;
aoqi@0 294 }
aoqi@0 295 }
aoqi@0 296 classInfoTree.addContent(pre);
aoqi@0 297 }
aoqi@0 298
aoqi@0 299 /**
aoqi@0 300 * {@inheritDoc}
aoqi@0 301 */
aoqi@0 302 public void addClassDescription(Content classInfoTree) {
aoqi@0 303 if(!configuration.nocomment) {
aoqi@0 304 // generate documentation for the class.
aoqi@0 305 if (classDoc.inlineTags().length > 0) {
aoqi@0 306 addInlineComment(classDoc, classInfoTree);
aoqi@0 307 }
aoqi@0 308 }
aoqi@0 309 }
aoqi@0 310
aoqi@0 311 /**
aoqi@0 312 * {@inheritDoc}
aoqi@0 313 */
aoqi@0 314 public void addClassTagInfo(Content classInfoTree) {
aoqi@0 315 if(!configuration.nocomment) {
aoqi@0 316 // Print Information about all the tags here
aoqi@0 317 addTagsInfo(classDoc, classInfoTree);
aoqi@0 318 }
aoqi@0 319 }
aoqi@0 320
aoqi@0 321 /**
aoqi@0 322 * Get the class hierarchy tree for the given class.
aoqi@0 323 *
aoqi@0 324 * @param type the class to print the hierarchy for
aoqi@0 325 * @return a content tree for class inheritence
aoqi@0 326 */
aoqi@0 327 private Content getClassInheritenceTree(Type type) {
aoqi@0 328 Type sup;
aoqi@0 329 HtmlTree classTreeUl = new HtmlTree(HtmlTag.UL);
aoqi@0 330 classTreeUl.addStyle(HtmlStyle.inheritance);
aoqi@0 331 Content liTree = null;
aoqi@0 332 do {
aoqi@0 333 sup = Util.getFirstVisibleSuperClass(
aoqi@0 334 type instanceof ClassDoc ? (ClassDoc) type : type.asClassDoc(),
aoqi@0 335 configuration);
aoqi@0 336 if (sup != null) {
aoqi@0 337 HtmlTree ul = new HtmlTree(HtmlTag.UL);
aoqi@0 338 ul.addStyle(HtmlStyle.inheritance);
aoqi@0 339 ul.addContent(getTreeForClassHelper(type));
aoqi@0 340 if (liTree != null)
aoqi@0 341 ul.addContent(liTree);
aoqi@0 342 Content li = HtmlTree.LI(ul);
aoqi@0 343 liTree = li;
aoqi@0 344 type = sup;
aoqi@0 345 }
aoqi@0 346 else
aoqi@0 347 classTreeUl.addContent(getTreeForClassHelper(type));
aoqi@0 348 }
aoqi@0 349 while (sup != null);
aoqi@0 350 if (liTree != null)
aoqi@0 351 classTreeUl.addContent(liTree);
aoqi@0 352 return classTreeUl;
aoqi@0 353 }
aoqi@0 354
aoqi@0 355 /**
aoqi@0 356 * Get the class helper tree for the given class.
aoqi@0 357 *
aoqi@0 358 * @param type the class to print the helper for
aoqi@0 359 * @return a content tree for class helper
aoqi@0 360 */
aoqi@0 361 private Content getTreeForClassHelper(Type type) {
aoqi@0 362 Content li = new HtmlTree(HtmlTag.LI);
aoqi@0 363 if (type.equals(classDoc)) {
aoqi@0 364 Content typeParameters = getTypeParameterLinks(
aoqi@0 365 new LinkInfoImpl(configuration, LinkInfoImpl.Kind.TREE,
aoqi@0 366 classDoc));
aoqi@0 367 if (configuration.shouldExcludeQualifier(
aoqi@0 368 classDoc.containingPackage().name())) {
aoqi@0 369 li.addContent(type.asClassDoc().name());
aoqi@0 370 li.addContent(typeParameters);
aoqi@0 371 } else {
aoqi@0 372 li.addContent(type.asClassDoc().qualifiedName());
aoqi@0 373 li.addContent(typeParameters);
aoqi@0 374 }
aoqi@0 375 } else {
aoqi@0 376 Content link = getLink(new LinkInfoImpl(configuration,
aoqi@0 377 LinkInfoImpl.Kind.CLASS_TREE_PARENT, type)
aoqi@0 378 .label(configuration.getClassName(type.asClassDoc())));
aoqi@0 379 li.addContent(link);
aoqi@0 380 }
aoqi@0 381 return li;
aoqi@0 382 }
aoqi@0 383
aoqi@0 384 /**
aoqi@0 385 * {@inheritDoc}
aoqi@0 386 */
aoqi@0 387 public void addClassTree(Content classContentTree) {
aoqi@0 388 if (!classDoc.isClass()) {
aoqi@0 389 return;
aoqi@0 390 }
aoqi@0 391 classContentTree.addContent(getClassInheritenceTree(classDoc));
aoqi@0 392 }
aoqi@0 393
aoqi@0 394 /**
aoqi@0 395 * {@inheritDoc}
aoqi@0 396 */
aoqi@0 397 public void addTypeParamInfo(Content classInfoTree) {
aoqi@0 398 if (classDoc.typeParamTags().length > 0) {
aoqi@0 399 Content typeParam = (new ParamTaglet()).getTagletOutput(classDoc,
aoqi@0 400 getTagletWriterInstance(false));
aoqi@0 401 Content dl = HtmlTree.DL(typeParam);
aoqi@0 402 classInfoTree.addContent(dl);
aoqi@0 403 }
aoqi@0 404 }
aoqi@0 405
aoqi@0 406 /**
aoqi@0 407 * {@inheritDoc}
aoqi@0 408 */
aoqi@0 409 public void addSubClassInfo(Content classInfoTree) {
aoqi@0 410 if (classDoc.isClass()) {
aoqi@0 411 if (classDoc.qualifiedName().equals("java.lang.Object") ||
aoqi@0 412 classDoc.qualifiedName().equals("org.omg.CORBA.Object")) {
aoqi@0 413 return; // Don't generate the list, too huge
aoqi@0 414 }
aoqi@0 415 List<ClassDoc> subclasses = classtree.subs(classDoc, false);
aoqi@0 416 if (subclasses.size() > 0) {
aoqi@0 417 Content label = getResource(
aoqi@0 418 "doclet.Subclasses");
aoqi@0 419 Content dt = HtmlTree.DT(label);
aoqi@0 420 Content dl = HtmlTree.DL(dt);
aoqi@0 421 dl.addContent(getClassLinks(LinkInfoImpl.Kind.SUBCLASSES,
aoqi@0 422 subclasses));
aoqi@0 423 classInfoTree.addContent(dl);
aoqi@0 424 }
aoqi@0 425 }
aoqi@0 426 }
aoqi@0 427
aoqi@0 428 /**
aoqi@0 429 * {@inheritDoc}
aoqi@0 430 */
aoqi@0 431 public void addSubInterfacesInfo(Content classInfoTree) {
aoqi@0 432 if (classDoc.isInterface()) {
aoqi@0 433 List<ClassDoc> subInterfaces = classtree.allSubs(classDoc, false);
aoqi@0 434 if (subInterfaces.size() > 0) {
aoqi@0 435 Content label = getResource(
aoqi@0 436 "doclet.Subinterfaces");
aoqi@0 437 Content dt = HtmlTree.DT(label);
aoqi@0 438 Content dl = HtmlTree.DL(dt);
aoqi@0 439 dl.addContent(getClassLinks(LinkInfoImpl.Kind.SUBINTERFACES,
aoqi@0 440 subInterfaces));
aoqi@0 441 classInfoTree.addContent(dl);
aoqi@0 442 }
aoqi@0 443 }
aoqi@0 444 }
aoqi@0 445
aoqi@0 446 /**
aoqi@0 447 * {@inheritDoc}
aoqi@0 448 */
aoqi@0 449 public void addInterfaceUsageInfo (Content classInfoTree) {
aoqi@0 450 if (! classDoc.isInterface()) {
aoqi@0 451 return;
aoqi@0 452 }
aoqi@0 453 if (classDoc.qualifiedName().equals("java.lang.Cloneable") ||
aoqi@0 454 classDoc.qualifiedName().equals("java.io.Serializable")) {
aoqi@0 455 return; // Don't generate the list, too big
aoqi@0 456 }
aoqi@0 457 List<ClassDoc> implcl = classtree.implementingclasses(classDoc);
aoqi@0 458 if (implcl.size() > 0) {
aoqi@0 459 Content label = getResource(
aoqi@0 460 "doclet.Implementing_Classes");
aoqi@0 461 Content dt = HtmlTree.DT(label);
aoqi@0 462 Content dl = HtmlTree.DL(dt);
aoqi@0 463 dl.addContent(getClassLinks(LinkInfoImpl.Kind.IMPLEMENTED_CLASSES,
aoqi@0 464 implcl));
aoqi@0 465 classInfoTree.addContent(dl);
aoqi@0 466 }
aoqi@0 467 }
aoqi@0 468
aoqi@0 469 /**
aoqi@0 470 * {@inheritDoc}
aoqi@0 471 */
aoqi@0 472 public void addImplementedInterfacesInfo(Content classInfoTree) {
aoqi@0 473 //NOTE: we really should be using ClassDoc.interfaceTypes() here, but
aoqi@0 474 // it doesn't walk up the tree like we want it to.
aoqi@0 475 List<Type> interfaceArray = Util.getAllInterfaces(classDoc, configuration);
aoqi@0 476 if (classDoc.isClass() && interfaceArray.size() > 0) {
aoqi@0 477 Content label = getResource(
aoqi@0 478 "doclet.All_Implemented_Interfaces");
aoqi@0 479 Content dt = HtmlTree.DT(label);
aoqi@0 480 Content dl = HtmlTree.DL(dt);
aoqi@0 481 dl.addContent(getClassLinks(LinkInfoImpl.Kind.IMPLEMENTED_INTERFACES,
aoqi@0 482 interfaceArray));
aoqi@0 483 classInfoTree.addContent(dl);
aoqi@0 484 }
aoqi@0 485 }
aoqi@0 486
aoqi@0 487 /**
aoqi@0 488 * {@inheritDoc}
aoqi@0 489 */
aoqi@0 490 public void addSuperInterfacesInfo(Content classInfoTree) {
aoqi@0 491 //NOTE: we really should be using ClassDoc.interfaceTypes() here, but
aoqi@0 492 // it doesn't walk up the tree like we want it to.
aoqi@0 493 List<Type> interfaceArray = Util.getAllInterfaces(classDoc, configuration);
aoqi@0 494 if (classDoc.isInterface() && interfaceArray.size() > 0) {
aoqi@0 495 Content label = getResource(
aoqi@0 496 "doclet.All_Superinterfaces");
aoqi@0 497 Content dt = HtmlTree.DT(label);
aoqi@0 498 Content dl = HtmlTree.DL(dt);
aoqi@0 499 dl.addContent(getClassLinks(LinkInfoImpl.Kind.SUPER_INTERFACES,
aoqi@0 500 interfaceArray));
aoqi@0 501 classInfoTree.addContent(dl);
aoqi@0 502 }
aoqi@0 503 }
aoqi@0 504
aoqi@0 505 /**
aoqi@0 506 * {@inheritDoc}
aoqi@0 507 */
aoqi@0 508 public void addNestedClassInfo(Content classInfoTree) {
aoqi@0 509 ClassDoc outerClass = classDoc.containingClass();
aoqi@0 510 if (outerClass != null) {
aoqi@0 511 Content label;
aoqi@0 512 if (outerClass.isInterface()) {
aoqi@0 513 label = getResource(
aoqi@0 514 "doclet.Enclosing_Interface");
aoqi@0 515 } else {
aoqi@0 516 label = getResource(
aoqi@0 517 "doclet.Enclosing_Class");
aoqi@0 518 }
aoqi@0 519 Content dt = HtmlTree.DT(label);
aoqi@0 520 Content dl = HtmlTree.DL(dt);
aoqi@0 521 Content dd = new HtmlTree(HtmlTag.DD);
aoqi@0 522 dd.addContent(getLink(new LinkInfoImpl(configuration,
aoqi@0 523 LinkInfoImpl.Kind.CLASS, outerClass)));
aoqi@0 524 dl.addContent(dd);
aoqi@0 525 classInfoTree.addContent(dl);
aoqi@0 526 }
aoqi@0 527 }
aoqi@0 528
aoqi@0 529 /**
aoqi@0 530 * {@inheritDoc}
aoqi@0 531 */
aoqi@0 532 public void addFunctionalInterfaceInfo (Content classInfoTree) {
aoqi@0 533 if (isFunctionalInterface()) {
aoqi@0 534 Content dt = HtmlTree.DT(getResource("doclet.Functional_Interface"));
aoqi@0 535 Content dl = HtmlTree.DL(dt);
aoqi@0 536 Content dd = new HtmlTree(HtmlTag.DD);
aoqi@0 537 dd.addContent(getResource("doclet.Functional_Interface_Message"));
aoqi@0 538 dl.addContent(dd);
aoqi@0 539 classInfoTree.addContent(dl);
aoqi@0 540 }
aoqi@0 541 }
aoqi@0 542
aoqi@0 543 public boolean isFunctionalInterface() {
aoqi@0 544 if (configuration.root instanceof RootDocImpl) {
aoqi@0 545 RootDocImpl root = (RootDocImpl) configuration.root;
aoqi@0 546 AnnotationDesc[] annotationDescList = classDoc.annotations();
aoqi@0 547 for (AnnotationDesc annoDesc : annotationDescList) {
aoqi@0 548 if (root.isFunctionalInterface(annoDesc)) {
aoqi@0 549 return true;
aoqi@0 550 }
aoqi@0 551 }
aoqi@0 552 }
aoqi@0 553 return false;
aoqi@0 554 }
aoqi@0 555
aoqi@0 556 /**
aoqi@0 557 * {@inheritDoc}
aoqi@0 558 */
aoqi@0 559 public void addClassDeprecationInfo(Content classInfoTree) {
aoqi@0 560 Content hr = new HtmlTree(HtmlTag.HR);
aoqi@0 561 classInfoTree.addContent(hr);
aoqi@0 562 Tag[] deprs = classDoc.tags("deprecated");
aoqi@0 563 if (Util.isDeprecated(classDoc)) {
aoqi@0 564 Content deprLabel = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase);
aoqi@0 565 Content div = HtmlTree.DIV(HtmlStyle.block, deprLabel);
aoqi@0 566 if (deprs.length > 0) {
aoqi@0 567 Tag[] commentTags = deprs[0].inlineTags();
aoqi@0 568 if (commentTags.length > 0) {
aoqi@0 569 div.addContent(getSpace());
aoqi@0 570 addInlineDeprecatedComment(classDoc, deprs[0], div);
aoqi@0 571 }
aoqi@0 572 }
aoqi@0 573 classInfoTree.addContent(div);
aoqi@0 574 }
aoqi@0 575 }
aoqi@0 576
aoqi@0 577 /**
aoqi@0 578 * Get links to the given classes.
aoqi@0 579 *
aoqi@0 580 * @param context the id of the context where the link will be printed
aoqi@0 581 * @param list the list of classes
aoqi@0 582 * @return a content tree for the class list
aoqi@0 583 */
aoqi@0 584 private Content getClassLinks(LinkInfoImpl.Kind context, List<?> list) {
aoqi@0 585 Object[] typeList = list.toArray();
aoqi@0 586 Content dd = new HtmlTree(HtmlTag.DD);
aoqi@0 587 for (int i = 0; i < list.size(); i++) {
aoqi@0 588 if (i > 0) {
aoqi@0 589 Content separator = new StringContent(", ");
aoqi@0 590 dd.addContent(separator);
aoqi@0 591 }
aoqi@0 592 if (typeList[i] instanceof ClassDoc) {
aoqi@0 593 Content link = getLink(
aoqi@0 594 new LinkInfoImpl(configuration, context, (ClassDoc)(typeList[i])));
aoqi@0 595 dd.addContent(link);
aoqi@0 596 } else {
aoqi@0 597 Content link = getLink(
aoqi@0 598 new LinkInfoImpl(configuration, context, (Type)(typeList[i])));
aoqi@0 599 dd.addContent(link);
aoqi@0 600 }
aoqi@0 601 }
aoqi@0 602 return dd;
aoqi@0 603 }
aoqi@0 604
aoqi@0 605 /**
aoqi@0 606 * {@inheritDoc}
aoqi@0 607 */
aoqi@0 608 protected Content getNavLinkTree() {
aoqi@0 609 Content treeLinkContent = getHyperLink(DocPaths.PACKAGE_TREE,
aoqi@0 610 treeLabel, "", "");
aoqi@0 611 Content li = HtmlTree.LI(treeLinkContent);
aoqi@0 612 return li;
aoqi@0 613 }
aoqi@0 614
aoqi@0 615 /**
aoqi@0 616 * Add summary details to the navigation bar.
aoqi@0 617 *
aoqi@0 618 * @param subDiv the content tree to which the summary detail links will be added
aoqi@0 619 */
aoqi@0 620 protected void addSummaryDetailLinks(Content subDiv) {
aoqi@0 621 try {
aoqi@0 622 Content div = HtmlTree.DIV(getNavSummaryLinks());
aoqi@0 623 div.addContent(getNavDetailLinks());
aoqi@0 624 subDiv.addContent(div);
aoqi@0 625 } catch (Exception e) {
aoqi@0 626 e.printStackTrace();
aoqi@0 627 throw new DocletAbortException(e);
aoqi@0 628 }
aoqi@0 629 }
aoqi@0 630
aoqi@0 631 /**
aoqi@0 632 * Get summary links for navigation bar.
aoqi@0 633 *
aoqi@0 634 * @return the content tree for the navigation summary links
aoqi@0 635 */
aoqi@0 636 protected Content getNavSummaryLinks() throws Exception {
aoqi@0 637 Content li = HtmlTree.LI(summaryLabel);
aoqi@0 638 li.addContent(getSpace());
aoqi@0 639 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
aoqi@0 640 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
aoqi@0 641 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
aoqi@0 642 String[] navLinkLabels = new String[] {
aoqi@0 643 "doclet.navNested", "doclet.navEnum", "doclet.navField", "doclet.navConstructor",
aoqi@0 644 "doclet.navMethod"
aoqi@0 645 };
aoqi@0 646 for (int i = 0; i < navLinkLabels.length; i++ ) {
aoqi@0 647 Content liNav = new HtmlTree(HtmlTag.LI);
aoqi@0 648 if (i == VisibleMemberMap.ENUM_CONSTANTS && ! classDoc.isEnum()) {
aoqi@0 649 continue;
aoqi@0 650 }
aoqi@0 651 if (i == VisibleMemberMap.CONSTRUCTORS && classDoc.isEnum()) {
aoqi@0 652 continue;
aoqi@0 653 }
aoqi@0 654 AbstractMemberWriter writer =
aoqi@0 655 ((AbstractMemberWriter) memberSummaryBuilder.
aoqi@0 656 getMemberSummaryWriter(i));
aoqi@0 657 if (writer == null) {
aoqi@0 658 liNav.addContent(getResource(navLinkLabels[i]));
aoqi@0 659 } else {
aoqi@0 660 writer.addNavSummaryLink(
aoqi@0 661 memberSummaryBuilder.members(i),
aoqi@0 662 memberSummaryBuilder.getVisibleMemberMap(i), liNav);
aoqi@0 663 }
aoqi@0 664 if (i < navLinkLabels.length-1) {
aoqi@0 665 addNavGap(liNav);
aoqi@0 666 }
aoqi@0 667 ulNav.addContent(liNav);
aoqi@0 668 }
aoqi@0 669 return ulNav;
aoqi@0 670 }
aoqi@0 671
aoqi@0 672 /**
aoqi@0 673 * Get detail links for the navigation bar.
aoqi@0 674 *
aoqi@0 675 * @return the content tree for the detail links
aoqi@0 676 */
aoqi@0 677 protected Content getNavDetailLinks() throws Exception {
aoqi@0 678 Content li = HtmlTree.LI(detailLabel);
aoqi@0 679 li.addContent(getSpace());
aoqi@0 680 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li);
aoqi@0 681 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder)
aoqi@0 682 configuration.getBuilderFactory().getMemberSummaryBuilder(this);
aoqi@0 683 String[] navLinkLabels = new String[] {
aoqi@0 684 "doclet.navNested", "doclet.navEnum", "doclet.navField", "doclet.navConstructor",
aoqi@0 685 "doclet.navMethod"
aoqi@0 686 };
aoqi@0 687 for (int i = 1; i < navLinkLabels.length; i++ ) {
aoqi@0 688 Content liNav = new HtmlTree(HtmlTag.LI);
aoqi@0 689 AbstractMemberWriter writer =
aoqi@0 690 ((AbstractMemberWriter) memberSummaryBuilder.
aoqi@0 691 getMemberSummaryWriter(i));
aoqi@0 692 if (i == VisibleMemberMap.ENUM_CONSTANTS && ! classDoc.isEnum()) {
aoqi@0 693 continue;
aoqi@0 694 }
aoqi@0 695 if (i == VisibleMemberMap.CONSTRUCTORS && classDoc.isEnum()) {
aoqi@0 696 continue;
aoqi@0 697 }
aoqi@0 698 if (writer == null) {
aoqi@0 699 liNav.addContent(getResource(navLinkLabels[i]));
aoqi@0 700 } else {
aoqi@0 701 writer.addNavDetailLink(memberSummaryBuilder.members(i), liNav);
aoqi@0 702 }
aoqi@0 703 if (i < navLinkLabels.length - 1) {
aoqi@0 704 addNavGap(liNav);
aoqi@0 705 }
aoqi@0 706 ulNav.addContent(liNav);
aoqi@0 707 }
aoqi@0 708 return ulNav;
aoqi@0 709 }
aoqi@0 710
aoqi@0 711 /**
aoqi@0 712 * Add gap between navigation bar elements.
aoqi@0 713 *
aoqi@0 714 * @param liNav the content tree to which the gap will be added
aoqi@0 715 */
aoqi@0 716 protected void addNavGap(Content liNav) {
aoqi@0 717 liNav.addContent(getSpace());
aoqi@0 718 liNav.addContent("|");
aoqi@0 719 liNav.addContent(getSpace());
aoqi@0 720 }
aoqi@0 721
aoqi@0 722 /**
aoqi@0 723 * Return the classDoc being documented.
aoqi@0 724 *
aoqi@0 725 * @return the classDoc being documented.
aoqi@0 726 */
aoqi@0 727 public ClassDoc getClassDoc() {
aoqi@0 728 return classDoc;
aoqi@0 729 }
aoqi@0 730 }

mercurial