AnnotationTypeWriterImpl.java revision 3233:b5d08bc0d224
1260684Skaiw/* 2260684Skaiw * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. 3260684Skaiw * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4260684Skaiw * 5260684Skaiw * This code is free software; you can redistribute it and/or modify it 6260684Skaiw * under the terms of the GNU General Public License version 2 only, as 7260684Skaiw * published by the Free Software Foundation. Oracle designates this 8260684Skaiw * particular file as subject to the "Classpath" exception as provided 9260684Skaiw * by Oracle in the LICENSE file that accompanied this code. 10260684Skaiw * 11260684Skaiw * This code is distributed in the hope that it will be useful, but WITHOUT 12260684Skaiw * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13260684Skaiw * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14260684Skaiw * version 2 for more details (a copy is included in the LICENSE file that 15260684Skaiw * accompanied this code). 16260684Skaiw * 17260684Skaiw * You should have received a copy of the GNU General Public License version 18260684Skaiw * 2 along with this work; if not, write to the Free Software Foundation, 19260684Skaiw * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20260684Skaiw * 21260684Skaiw * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22260684Skaiw * or visit www.oracle.com if you need additional information or have any 23260684Skaiw * questions. 24260684Skaiw */ 25367466Sdim 26260684Skaiwpackage jdk.javadoc.internal.doclets.formats.html; 27260684Skaiw 28367466Sdimimport java.io.IOException; 29260684Skaiwimport java.util.List; 30260684Skaiw 31260684Skaiwimport javax.lang.model.element.PackageElement; 32260684Skaiwimport javax.lang.model.element.TypeElement; 33260684Skaiwimport javax.lang.model.type.TypeMirror; 34260684Skaiw 35260684Skaiwimport com.sun.source.doctree.DocTree; 36260684Skaiwimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants; 37260684Skaiwimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle; 38260684Skaiwimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag; 39260684Skaiwimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree; 40260684Skaiwimport jdk.javadoc.internal.doclets.formats.html.markup.StringContent; 41260684Skaiwimport jdk.javadoc.internal.doclets.toolkit.AnnotationTypeWriter; 42260684Skaiwimport jdk.javadoc.internal.doclets.toolkit.Content; 43260684Skaiwimport jdk.javadoc.internal.doclets.toolkit.builders.MemberSummaryBuilder; 44260684Skaiwimport jdk.javadoc.internal.doclets.toolkit.util.CommentHelper; 45260684Skaiwimport jdk.javadoc.internal.doclets.toolkit.util.DocPath; 46260684Skaiwimport jdk.javadoc.internal.doclets.toolkit.util.DocPaths; 47260684Skaiwimport jdk.javadoc.internal.doclets.toolkit.util.DocletAbortException; 48260684Skaiwimport jdk.javadoc.internal.doclets.toolkit.util.VisibleMemberMap; 49260684Skaiw 50260684Skaiw/** 51260684Skaiw * Generate the Class Information Page. 52260684Skaiw * 53260684Skaiw * <p><b>This is NOT part of any supported API. 54260684Skaiw * If you write code that depends on this, you do so at your own risk. 55260684Skaiw * This code and its internal interfaces are subject to change or 56260684Skaiw * deletion without notice.</b> 57260684Skaiw * 58260684Skaiw * @see java.util.Collections 59260684Skaiw * @see java.util.List 60260684Skaiw * @see java.util.ArrayList 61260684Skaiw * @see java.util.HashMap 62260684Skaiw * 63260684Skaiw * @author Atul M Dambalkar 64260684Skaiw * @author Robert Field 65260684Skaiw * @author Bhavesh Patel (Modified) 66260684Skaiw */ 67260684Skaiwpublic class AnnotationTypeWriterImpl extends SubWriterHolderWriter 68260684Skaiw implements AnnotationTypeWriter { 69260684Skaiw 70260684Skaiw protected TypeElement annotationType; 71260684Skaiw 72260684Skaiw protected TypeMirror prev; 73260684Skaiw 74260684Skaiw protected TypeMirror next; 75260684Skaiw 76260684Skaiw /** 77260684Skaiw * @param configuration the configuration 78260684Skaiw * @param annotationType the annotation type being documented. 79260684Skaiw * @param prevType the previous class that was documented. 80260684Skaiw * @param nextType the next class being documented. 81260684Skaiw * @throws java.lang.Exception 82260684Skaiw */ 83260684Skaiw public AnnotationTypeWriterImpl(ConfigurationImpl configuration, 84260684Skaiw TypeElement annotationType, TypeMirror prevType, TypeMirror nextType) 85260684Skaiw throws Exception { 86260684Skaiw super(configuration, DocPath.forClass(configuration.utils, annotationType)); 87260684Skaiw this.annotationType = annotationType; 88260684Skaiw configuration.currentTypeElement = annotationType; 89260684Skaiw this.prev = prevType; 90260684Skaiw this.next = nextType; 91260684Skaiw } 92260684Skaiw 93260684Skaiw /** 94260684Skaiw * Get this package link. 95260684Skaiw * 96260684Skaiw * @return a content tree for the package link 97260684Skaiw */ 98260684Skaiw @Override 99260684Skaiw protected Content getNavLinkPackage() { 100260684Skaiw Content linkContent = getHyperLink(DocPaths.PACKAGE_SUMMARY, 101260684Skaiw packageLabel); 102260684Skaiw Content li = HtmlTree.LI(linkContent); 103260684Skaiw return li; 104260684Skaiw } 105260684Skaiw 106260684Skaiw /** 107260684Skaiw * Get the class link. 108260684Skaiw * 109260684Skaiw * @return a content tree for the class link 110260684Skaiw */ 111260684Skaiw @Override 112260684Skaiw protected Content getNavLinkClass() { 113260684Skaiw Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, classLabel); 114260684Skaiw return li; 115260684Skaiw } 116260684Skaiw 117260684Skaiw /** 118260684Skaiw * Get the class use link. 119260684Skaiw * 120260684Skaiw * @return a content tree for the class use link 121260684Skaiw */ 122260684Skaiw @Override 123260684Skaiw protected Content getNavLinkClassUse() { 124260684Skaiw Content linkContent = getHyperLink(DocPaths.CLASS_USE.resolve(filename), useLabel); 125260684Skaiw Content li = HtmlTree.LI(linkContent); 126260684Skaiw return li; 127260684Skaiw } 128260684Skaiw 129260684Skaiw /** 130260684Skaiw * Get link to previous class. 131260684Skaiw * 132260684Skaiw * @return a content tree for the previous class link 133260684Skaiw */ 134260684Skaiw @Override 135260684Skaiw public Content getNavLinkPrevious() { 136260684Skaiw Content li; 137260684Skaiw if (prev != null) { 138260684Skaiw Content prevLink = getLink(new LinkInfoImpl(configuration, 139260684Skaiw LinkInfoImpl.Kind.CLASS, utils.asTypeElement(prev)) 140282918Semaste .label(prevclassLabel).strong(true)); 141260684Skaiw li = HtmlTree.LI(prevLink); 142260684Skaiw } 143260684Skaiw else 144260684Skaiw li = HtmlTree.LI(prevclassLabel); 145260684Skaiw return li; 146260684Skaiw } 147260684Skaiw 148260684Skaiw /** 149260684Skaiw * Get link to next class. 150260684Skaiw * 151260684Skaiw * @return a content tree for the next class link 152260684Skaiw */ 153260684Skaiw @Override 154260684Skaiw public Content getNavLinkNext() { 155260684Skaiw Content li; 156260684Skaiw if (next != null) { 157260684Skaiw Content nextLink = getLink(new LinkInfoImpl(configuration, 158260684Skaiw LinkInfoImpl.Kind.CLASS, utils.asTypeElement(next)) 159260684Skaiw .label(nextclassLabel).strong(true)); 160260684Skaiw li = HtmlTree.LI(nextLink); 161260684Skaiw } 162260684Skaiw else 163260684Skaiw li = HtmlTree.LI(nextclassLabel); 164260684Skaiw return li; 165260684Skaiw } 166260684Skaiw 167260684Skaiw /** 168260684Skaiw * {@inheritDoc} 169260684Skaiw */ 170260684Skaiw @Override 171260684Skaiw public Content getHeader(String header) { 172260684Skaiw HtmlTree bodyTree = getBody(true, getWindowTitle(utils.getSimpleName(annotationType))); 173260684Skaiw HtmlTree htmlTree = (configuration.allowTag(HtmlTag.HEADER)) 174260684Skaiw ? HtmlTree.HEADER() 175367466Sdim : bodyTree; 176260684Skaiw addTop(htmlTree); 177260684Skaiw addNavLinks(true, htmlTree); 178260684Skaiw if (configuration.allowTag(HtmlTag.HEADER)) { 179260684Skaiw bodyTree.addContent(htmlTree); 180260684Skaiw } 181260684Skaiw bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA); 182260684Skaiw HtmlTree div = new HtmlTree(HtmlTag.DIV); 183260684Skaiw div.addStyle(HtmlStyle.header); 184260684Skaiw PackageElement pkg = utils.containingPackage(annotationType); 185260684Skaiw if (!pkg.isUnnamed()) { 186260684Skaiw Content pkgNameContent = new StringContent(utils.getPackageName(pkg)); 187260684Skaiw Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, pkgNameContent); 188260684Skaiw div.addContent(pkgNameDiv); 189260684Skaiw } 190260684Skaiw LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, 191260684Skaiw LinkInfoImpl.Kind.CLASS_HEADER, annotationType); 192260684Skaiw Content headerContent = new StringContent(header); 193260684Skaiw Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING, true, 194260684Skaiw HtmlStyle.title, headerContent); 195260684Skaiw heading.addContent(getTypeParameterLinks(linkInfo)); 196260684Skaiw div.addContent(heading); 197260684Skaiw if (configuration.allowTag(HtmlTag.MAIN)) { 198260684Skaiw mainTree.addContent(div); 199260684Skaiw } else { 200260684Skaiw bodyTree.addContent(div); 201260684Skaiw } 202260684Skaiw return bodyTree; 203260684Skaiw } 204260684Skaiw 205260684Skaiw /** 206260684Skaiw * {@inheritDoc} 207260684Skaiw */ 208260684Skaiw @Override 209260684Skaiw public Content getAnnotationContentHeader() { 210260684Skaiw return getContentHeader(); 211260684Skaiw } 212260684Skaiw 213260684Skaiw /** 214260684Skaiw * {@inheritDoc} 215260684Skaiw */ 216260684Skaiw @Override 217260684Skaiw public void addFooter(Content contentTree) { 218260684Skaiw contentTree.addContent(HtmlConstants.END_OF_CLASS_DATA); 219260684Skaiw Content htmlTree = (configuration.allowTag(HtmlTag.FOOTER)) 220260684Skaiw ? HtmlTree.FOOTER() 221260684Skaiw : contentTree; 222260684Skaiw addNavLinks(false, htmlTree); 223260684Skaiw addBottom(htmlTree); 224260684Skaiw if (configuration.allowTag(HtmlTag.FOOTER)) { 225367466Sdim contentTree.addContent(htmlTree); 226367466Sdim } 227367466Sdim } 228367466Sdim 229367466Sdim /** 230367466Sdim * {@inheritDoc} 231367466Sdim */ 232367466Sdim @Override 233367466Sdim public void printDocument(Content contentTree) throws IOException { 234367466Sdim printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType), 235367466Sdim true, contentTree); 236367466Sdim } 237367466Sdim 238367466Sdim /** 239367466Sdim * {@inheritDoc} 240367466Sdim */ 241367466Sdim @Override 242367466Sdim public Content getAnnotationInfoTreeHeader() { 243367466Sdim return getMemberTreeHeader(); 244367466Sdim } 245367466Sdim 246367466Sdim /** 247367466Sdim * {@inheritDoc} 248367466Sdim */ 249367466Sdim @Override 250367466Sdim public Content getAnnotationInfo(Content annotationInfoTree) { 251367466Sdim return getMemberTree(HtmlStyle.description, annotationInfoTree); 252367466Sdim } 253367466Sdim 254367466Sdim /** 255367466Sdim * {@inheritDoc} 256260684Skaiw */ 257260684Skaiw @Override 258260684Skaiw public void addAnnotationTypeSignature(String modifiers, Content annotationInfoTree) { 259 annotationInfoTree.addContent(new HtmlTree(HtmlTag.BR)); 260 Content pre = new HtmlTree(HtmlTag.PRE); 261 addAnnotationInfo(annotationType, pre); 262 pre.addContent(modifiers); 263 LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, 264 LinkInfoImpl.Kind.CLASS_SIGNATURE, annotationType); 265 Content annotationName = new StringContent(utils.getSimpleName(annotationType)); 266 Content parameterLinks = getTypeParameterLinks(linkInfo); 267 if (configuration.linksource) { 268 addSrcLink(annotationType, annotationName, pre); 269 pre.addContent(parameterLinks); 270 } else { 271 Content span = HtmlTree.SPAN(HtmlStyle.memberNameLabel, annotationName); 272 span.addContent(parameterLinks); 273 pre.addContent(span); 274 } 275 annotationInfoTree.addContent(pre); 276 } 277 278 /** 279 * {@inheritDoc} 280 */ 281 @Override 282 public void addAnnotationTypeDescription(Content annotationInfoTree) { 283 if(!configuration.nocomment) { 284 if (!utils.getBody(annotationType).isEmpty()) { 285 addInlineComment(annotationType, annotationInfoTree); 286 } 287 } 288 } 289 290 /** 291 * {@inheritDoc} 292 */ 293 @Override 294 public void addAnnotationTypeTagInfo(Content annotationInfoTree) { 295 if(!configuration.nocomment) { 296 addTagsInfo(annotationType, annotationInfoTree); 297 } 298 } 299 300 /** 301 * {@inheritDoc} 302 */ 303 @Override 304 public void addAnnotationTypeDeprecationInfo(Content annotationInfoTree) { 305 Content hr = new HtmlTree(HtmlTag.HR); 306 annotationInfoTree.addContent(hr); 307 List<? extends DocTree> deprs = utils.getBlockTags(annotationType, DocTree.Kind.DEPRECATED); 308 if (utils.isDeprecated(annotationType)) { 309 CommentHelper ch = utils.getCommentHelper(annotationType); 310 Content deprLabel = HtmlTree.SPAN(HtmlStyle.deprecatedLabel, deprecatedPhrase); 311 Content div = HtmlTree.DIV(HtmlStyle.block, deprLabel); 312 if (!deprs.isEmpty()) { 313 314 List<? extends DocTree> commentTags = ch.getDescription(configuration, deprs.get(0)); 315 if (!commentTags.isEmpty()) { 316 div.addContent(getSpace()); 317 addInlineDeprecatedComment(annotationType, deprs.get(0), div); 318 } 319 } 320 annotationInfoTree.addContent(div); 321 } 322 } 323 324 /** 325 * {@inheritDoc} 326 */ 327 @Override 328 protected Content getNavLinkTree() { 329 Content treeLinkContent = getHyperLink(DocPaths.PACKAGE_TREE, 330 treeLabel, "", ""); 331 Content li = HtmlTree.LI(treeLinkContent); 332 return li; 333 } 334 335 /** 336 * Add summary details to the navigation bar. 337 * 338 * @param subDiv the content tree to which the summary detail links will be added 339 */ 340 @Override 341 protected void addSummaryDetailLinks(Content subDiv) { 342 try { 343 Content div = HtmlTree.DIV(getNavSummaryLinks()); 344 div.addContent(getNavDetailLinks()); 345 subDiv.addContent(div); 346 } catch (Exception e) { 347 throw new DocletAbortException(e); 348 } 349 } 350 351 /** 352 * Get summary links for navigation bar. 353 * 354 * @return the content tree for the navigation summary links 355 * @throws java.lang.Exception 356 */ 357 protected Content getNavSummaryLinks() throws Exception { 358 Content li = HtmlTree.LI(summaryLabel); 359 li.addContent(getSpace()); 360 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li); 361 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder) 362 configuration.getBuilderFactory().getMemberSummaryBuilder(this); 363 Content liNavField = new HtmlTree(HtmlTag.LI); 364 addNavSummaryLink(memberSummaryBuilder, 365 "doclet.navField", 366 VisibleMemberMap.Kind.ANNOTATION_TYPE_FIELDS, liNavField); 367 addNavGap(liNavField); 368 ulNav.addContent(liNavField); 369 Content liNavReq = new HtmlTree(HtmlTag.LI); 370 addNavSummaryLink(memberSummaryBuilder, 371 "doclet.navAnnotationTypeRequiredMember", 372 VisibleMemberMap.Kind.ANNOTATION_TYPE_MEMBER_REQUIRED, liNavReq); 373 addNavGap(liNavReq); 374 ulNav.addContent(liNavReq); 375 Content liNavOpt = new HtmlTree(HtmlTag.LI); 376 addNavSummaryLink(memberSummaryBuilder, 377 "doclet.navAnnotationTypeOptionalMember", 378 VisibleMemberMap.Kind.ANNOTATION_TYPE_MEMBER_OPTIONAL, liNavOpt); 379 ulNav.addContent(liNavOpt); 380 return ulNav; 381 } 382 383 /** 384 * Add the navigation summary link. 385 * 386 * @param builder builder for the member to be documented 387 * @param label the label for the navigation 388 * @param type type to be documented 389 * @param liNav the content tree to which the navigation summary link will be added 390 */ 391 protected void addNavSummaryLink(MemberSummaryBuilder builder, 392 String label, VisibleMemberMap.Kind type, Content liNav) { 393 AbstractMemberWriter writer = ((AbstractMemberWriter) builder. 394 getMemberSummaryWriter(type)); 395 if (writer == null) { 396 liNav.addContent(getResource(label)); 397 } else { 398 liNav.addContent(writer.getNavSummaryLink(null, 399 ! builder.getVisibleMemberMap(type).noVisibleMembers())); 400 } 401 } 402 403 /** 404 * Get detail links for the navigation bar. 405 * 406 * @return the content tree for the detail links 407 * @throws java.lang.Exception 408 */ 409 protected Content getNavDetailLinks() throws Exception { 410 Content li = HtmlTree.LI(detailLabel); 411 li.addContent(getSpace()); 412 Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li); 413 MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder) 414 configuration.getBuilderFactory().getMemberSummaryBuilder(this); 415 AbstractMemberWriter writerField = 416 ((AbstractMemberWriter) memberSummaryBuilder. 417 getMemberSummaryWriter(VisibleMemberMap.Kind.ANNOTATION_TYPE_FIELDS)); 418 AbstractMemberWriter writerOptional = 419 ((AbstractMemberWriter) memberSummaryBuilder. 420 getMemberSummaryWriter(VisibleMemberMap.Kind.ANNOTATION_TYPE_MEMBER_OPTIONAL)); 421 AbstractMemberWriter writerRequired = 422 ((AbstractMemberWriter) memberSummaryBuilder. 423 getMemberSummaryWriter(VisibleMemberMap.Kind.ANNOTATION_TYPE_MEMBER_REQUIRED)); 424 Content liNavField = new HtmlTree(HtmlTag.LI); 425 if (writerField != null) { 426 writerField.addNavDetailLink(!utils.getAnnotationFields(annotationType).isEmpty(), liNavField); 427 } else { 428 liNavField.addContent(getResource("doclet.navField")); 429 } 430 addNavGap(liNavField); 431 ulNav.addContent(liNavField); 432 if (writerOptional != null){ 433 Content liNavOpt = new HtmlTree(HtmlTag.LI); 434 writerOptional.addNavDetailLink(!annotationType.getAnnotationMirrors().isEmpty(), liNavOpt); 435 ulNav.addContent(liNavOpt); 436 } else if (writerRequired != null){ 437 Content liNavReq = new HtmlTree(HtmlTag.LI); 438 writerRequired.addNavDetailLink(!annotationType.getAnnotationMirrors().isEmpty(), liNavReq); 439 ulNav.addContent(liNavReq); 440 } else { 441 Content liNav = HtmlTree.LI(getResource("doclet.navAnnotationTypeMember")); 442 ulNav.addContent(liNav); 443 } 444 return ulNav; 445 } 446 447 /** 448 * Add gap between navigation bar elements. 449 * 450 * @param liNav the content tree to which the gap will be added 451 */ 452 protected void addNavGap(Content liNav) { 453 liNav.addContent(getSpace()); 454 liNav.addContent("|"); 455 liNav.addContent(getSpace()); 456 } 457 458 /** 459 * {@inheritDoc} 460 */ 461 @Override 462 public TypeElement getAnnotationTypeElement() { 463 return annotationType; 464 } 465} 466