duke@1: /* bpatel@943: * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.formats.html; duke@1: bpatel@233: import com.sun.javadoc.*; duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: import com.sun.tools.doclets.internal.toolkit.builders.*; bpatel@766: import com.sun.tools.doclets.formats.html.markup.*; duke@1: duke@1: /** duke@1: * Generate the Class Information Page. duke@1: * @see com.sun.javadoc.ClassDoc duke@1: * @see java.util.Collections duke@1: * @see java.util.List duke@1: * @see java.util.ArrayList duke@1: * @see java.util.HashMap duke@1: * duke@1: * @author Atul M Dambalkar duke@1: * @author Robert Field bpatel@766: * @author Bhavesh Patel (Modified) duke@1: */ duke@1: public class AnnotationTypeWriterImpl extends SubWriterHolderWriter duke@1: implements AnnotationTypeWriter { duke@1: duke@1: protected AnnotationTypeDoc annotationType; duke@1: duke@1: protected Type prev; duke@1: duke@1: protected Type next; duke@1: duke@1: /** duke@1: * @param annotationType the annotation type being documented. duke@1: * @param prevType the previous class that was documented. duke@1: * @param nextType the next class being documented. duke@1: */ duke@1: public AnnotationTypeWriterImpl (AnnotationTypeDoc annotationType, duke@1: Type prevType, Type nextType) duke@1: throws Exception { duke@1: super(ConfigurationImpl.getInstance(), duke@1: DirectoryManager.getDirectoryPath(annotationType.containingPackage()), duke@1: annotationType.name() + ".html", duke@1: DirectoryManager.getRelativePath(annotationType.containingPackage().name())); duke@1: this.annotationType = annotationType; duke@1: configuration.currentcd = annotationType.asClassDoc(); duke@1: this.prev = prevType; duke@1: this.next = nextType; duke@1: } duke@1: duke@1: /** bpatel@766: * Get this package link. bpatel@766: * bpatel@766: * @return a content tree for the package link duke@1: */ bpatel@766: protected Content getNavLinkPackage() { bpatel@766: Content linkContent = getHyperLink("package-summary.html", "", bpatel@766: packageLabel); bpatel@766: Content li = HtmlTree.LI(linkContent); bpatel@766: return li; duke@1: } duke@1: duke@1: /** bpatel@766: * Get the class link. bpatel@766: * bpatel@766: * @return a content tree for the class link duke@1: */ bpatel@766: protected Content getNavLinkClass() { bpatel@766: Content li = HtmlTree.LI(HtmlStyle.navBarCell1Rev, classLabel); bpatel@766: return li; duke@1: } duke@1: duke@1: /** bpatel@766: * Get the class use link. bpatel@766: * bpatel@766: * @return a content tree for the class use link duke@1: */ bpatel@766: protected Content getNavLinkClassUse() { bpatel@766: Content linkContent = getHyperLink("class-use/" + filename, "", useLabel); bpatel@766: Content li = HtmlTree.LI(linkContent); bpatel@766: return li; duke@1: } duke@1: duke@1: /** bpatel@766: * Get link to previous class. bpatel@766: * bpatel@766: * @return a content tree for the previous class link duke@1: */ bpatel@766: public Content getNavLinkPrevious() { bpatel@766: Content li; bpatel@766: if (prev != null) { bpatel@766: Content prevLink = new RawHtml(getLink(new LinkInfoImpl( bpatel@766: LinkInfoImpl.CONTEXT_CLASS, prev.asClassDoc(), "", bpatel@766: configuration.getText("doclet.Prev_Class"), true))); bpatel@766: li = HtmlTree.LI(prevLink); duke@1: } bpatel@766: else bpatel@766: li = HtmlTree.LI(prevclassLabel); bpatel@766: return li; duke@1: } duke@1: duke@1: /** bpatel@766: * Get link to next class. bpatel@766: * bpatel@766: * @return a content tree for the next class link duke@1: */ bpatel@766: public Content getNavLinkNext() { bpatel@766: Content li; bpatel@766: if (next != null) { bpatel@766: Content nextLink = new RawHtml(getLink(new LinkInfoImpl( bpatel@766: LinkInfoImpl.CONTEXT_CLASS, next.asClassDoc(), "", bpatel@766: configuration.getText("doclet.Next_Class"), true))); bpatel@766: li = HtmlTree.LI(nextLink); duke@1: } bpatel@766: else bpatel@766: li = HtmlTree.LI(nextclassLabel); bpatel@766: return li; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public Content getHeader(String header) { duke@1: String pkgname = (annotationType.containingPackage() != null)? duke@1: annotationType.containingPackage().name(): ""; duke@1: String clname = annotationType.name(); bpatel@766: Content bodyTree = getBody(true, getWindowTitle(clname)); bpatel@766: addTop(bodyTree); bpatel@766: addNavLinks(true, bodyTree); bpatel@766: bodyTree.addContent(HtmlConstants.START_OF_CLASS_DATA); bpatel@766: HtmlTree div = new HtmlTree(HtmlTag.DIV); bpatel@766: div.addStyle(HtmlStyle.header); duke@1: if (pkgname.length() > 0) { bpatel@766: Content pkgNameContent = new StringContent(pkgname); bpatel@943: Content pkgNameDiv = HtmlTree.DIV(HtmlStyle.subTitle, pkgNameContent); bpatel@943: div.addContent(pkgNameDiv); duke@1: } bpatel@766: LinkInfoImpl linkInfo = new LinkInfoImpl( bpatel@766: LinkInfoImpl.CONTEXT_CLASS_HEADER, annotationType, false); bpatel@766: Content headerContent = new StringContent(header); bpatel@766: Content heading = HtmlTree.HEADING(HtmlConstants.CLASS_PAGE_HEADING, true, bpatel@766: HtmlStyle.title, headerContent); bpatel@766: heading.addContent(new RawHtml(getTypeParameterLinks(linkInfo))); bpatel@766: div.addContent(heading); bpatel@766: bodyTree.addContent(div); bpatel@766: return bodyTree; duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public Content getAnnotationContentHeader() { bpatel@766: return getContentHeader(); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void addFooter(Content contentTree) { bpatel@766: contentTree.addContent(HtmlConstants.END_OF_CLASS_DATA); bpatel@766: addNavLinks(false, contentTree); bpatel@766: addBottom(contentTree); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void printDocument(Content contentTree) { bpatel@766: printHtmlDocument(configuration.metakeywords.getMetaKeywords(annotationType), bpatel@766: true, contentTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: public Content getAnnotationInfoTreeHeader() { bpatel@766: return getMemberTreeHeader(); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: public Content getAnnotationInfo(Content annotationInfoTree) { bpatel@766: return getMemberTree(HtmlStyle.description, annotationInfoTree); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: public void addAnnotationTypeSignature(String modifiers, Content annotationInfoTree) { bpatel@766: annotationInfoTree.addContent(new HtmlTree(HtmlTag.BR)); bpatel@766: Content pre = new HtmlTree(HtmlTag.PRE); bpatel@766: addAnnotationInfo(annotationType, pre); bpatel@766: pre.addContent(modifiers); bpatel@766: LinkInfoImpl linkInfo = new LinkInfoImpl( bpatel@766: LinkInfoImpl.CONTEXT_CLASS_SIGNATURE, annotationType, false); bpatel@766: Content name = new RawHtml (annotationType.name() + bpatel@766: getTypeParameterLinks(linkInfo)); bpatel@766: if (configuration().linksource) { bpatel@766: addSrcLink(annotationType, name, pre); bpatel@766: } else { bpatel@766: pre.addContent(HtmlTree.STRONG(name)); bpatel@766: } bpatel@766: annotationInfoTree.addContent(pre); bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: public void addAnnotationTypeDescription(Content annotationInfoTree) { duke@1: if(!configuration.nocomment) { duke@1: if (annotationType.inlineTags().length > 0) { bpatel@766: addInlineComment(annotationType, annotationInfoTree); duke@1: } duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void addAnnotationTypeTagInfo(Content annotationInfoTree) { duke@1: if(!configuration.nocomment) { bpatel@766: addTagsInfo(annotationType, annotationInfoTree); duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ bpatel@766: public void addAnnotationTypeDeprecationInfo(Content annotationInfoTree) { bpatel@766: Content hr = new HtmlTree(HtmlTag.HR); bpatel@766: annotationInfoTree.addContent(hr); duke@1: Tag[] deprs = annotationType.tags("deprecated"); duke@1: if (Util.isDeprecated(annotationType)) { bpatel@766: Content strong = HtmlTree.STRONG(deprecatedPhrase); bpatel@766: Content div = HtmlTree.DIV(HtmlStyle.block, strong); duke@1: if (deprs.length > 0) { duke@1: Tag[] commentTags = deprs[0].inlineTags(); duke@1: if (commentTags.length > 0) { bpatel@766: div.addContent(getSpace()); bpatel@766: addInlineDeprecatedComment(annotationType, deprs[0], div); duke@1: } duke@1: } bpatel@766: annotationInfoTree.addContent(div); duke@1: } duke@1: } duke@1: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: public void addAnnotationDetailsMarker(Content memberDetails) { bpatel@766: memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_DETAILS); duke@1: } duke@1: bpatel@766: /** bpatel@766: * {@inheritDoc} bpatel@766: */ bpatel@766: protected Content getNavLinkTree() { bpatel@766: Content treeLinkContent = getHyperLink("package-tree.html", bpatel@766: "", treeLabel, "", ""); bpatel@766: Content li = HtmlTree.LI(treeLinkContent); bpatel@766: return li; bpatel@766: } bpatel@766: bpatel@766: /** bpatel@766: * Add summary details to the navigation bar. bpatel@766: * bpatel@766: * @param subDiv the content tree to which the summary detail links will be added bpatel@766: */ bpatel@766: protected void addSummaryDetailLinks(Content subDiv) { duke@1: try { bpatel@766: Content div = HtmlTree.DIV(getNavSummaryLinks()); bpatel@766: div.addContent(getNavDetailLinks()); bpatel@766: subDiv.addContent(div); duke@1: } catch (Exception e) { duke@1: e.printStackTrace(); duke@1: throw new DocletAbortException(); duke@1: } duke@1: } duke@1: bpatel@766: /** bpatel@766: * Get summary links for navigation bar. bpatel@766: * bpatel@766: * @return the content tree for the navigation summary links bpatel@766: */ bpatel@766: protected Content getNavSummaryLinks() throws Exception { bpatel@766: Content li = HtmlTree.LI(summaryLabel); bpatel@766: li.addContent(getSpace()); bpatel@766: Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li); duke@1: MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder) bpatel@766: configuration.getBuilderFactory().getMemberSummaryBuilder(this); bpatel@766: Content liNavReq = new HtmlTree(HtmlTag.LI); bpatel@766: addNavSummaryLink(memberSummaryBuilder, bpatel@766: "doclet.navAnnotationTypeRequiredMember", bpatel@766: VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED, liNavReq); bpatel@766: addNavGap(liNavReq); bpatel@766: ulNav.addContent(liNavReq); bpatel@766: Content liNavOpt = new HtmlTree(HtmlTag.LI); bpatel@766: addNavSummaryLink(memberSummaryBuilder, bpatel@766: "doclet.navAnnotationTypeOptionalMember", bpatel@766: VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL, liNavOpt); bpatel@766: ulNav.addContent(liNavOpt); bpatel@766: return ulNav; duke@1: } duke@1: bpatel@766: /** bpatel@766: * Add the navigation summary link. bpatel@766: * bpatel@766: * @param builder builder for the member to be documented bpatel@766: * @param label the label for the navigation bpatel@766: * @param type type to be documented bpatel@766: * @param liNav the content tree to which the navigation summary link will be added bpatel@766: */ bpatel@766: protected void addNavSummaryLink(MemberSummaryBuilder builder, bpatel@766: String label, int type, Content liNav) { duke@1: AbstractMemberWriter writer = ((AbstractMemberWriter) builder. bpatel@766: getMemberSummaryWriter(type)); duke@1: if (writer == null) { bpatel@766: liNav.addContent(getResource(label)); duke@1: } else { bpatel@766: liNav.addContent(writer.getNavSummaryLink(null, bpatel@766: ! builder.getVisibleMemberMap(type).noVisibleMembers())); duke@1: } duke@1: } duke@1: duke@1: /** bpatel@766: * Get detail links for the navigation bar. duke@1: * bpatel@766: * @return the content tree for the detail links duke@1: */ bpatel@766: protected Content getNavDetailLinks() throws Exception { bpatel@766: Content li = HtmlTree.LI(detailLabel); bpatel@766: li.addContent(getSpace()); bpatel@766: Content ulNav = HtmlTree.UL(HtmlStyle.subNavList, li); duke@1: MemberSummaryBuilder memberSummaryBuilder = (MemberSummaryBuilder) bpatel@766: configuration.getBuilderFactory().getMemberSummaryBuilder(this); duke@1: AbstractMemberWriter writerOptional = bpatel@766: ((AbstractMemberWriter) memberSummaryBuilder. duke@1: getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_OPTIONAL)); duke@1: AbstractMemberWriter writerRequired = bpatel@766: ((AbstractMemberWriter) memberSummaryBuilder. duke@1: getMemberSummaryWriter(VisibleMemberMap.ANNOTATION_TYPE_MEMBER_REQUIRED)); duke@1: if (writerOptional != null){ bpatel@766: Content liNavOpt = new HtmlTree(HtmlTag.LI); bpatel@766: writerOptional.addNavDetailLink(annotationType.elements().length > 0, liNavOpt); bpatel@766: ulNav.addContent(liNavOpt); duke@1: } else if (writerRequired != null){ bpatel@766: Content liNavReq = new HtmlTree(HtmlTag.LI); bpatel@766: writerRequired.addNavDetailLink(annotationType.elements().length > 0, liNavReq); bpatel@766: ulNav.addContent(liNavReq); duke@1: } else { bpatel@766: Content liNav = HtmlTree.LI(getResource("doclet.navAnnotationTypeMember")); bpatel@766: ulNav.addContent(liNav); duke@1: } bpatel@766: return ulNav; duke@1: } duke@1: duke@1: /** bpatel@766: * Add gap between navigation bar elements. bpatel@766: * bpatel@766: * @param liNav the content tree to which the gap will be added duke@1: */ bpatel@766: protected void addNavGap(Content liNav) { bpatel@766: liNav.addContent(getSpace()); bpatel@766: liNav.addContent("|"); bpatel@766: liNav.addContent(getSpace()); duke@1: } duke@1: duke@1: /** duke@1: * {@inheritDoc} duke@1: */ duke@1: public AnnotationTypeDoc getAnnotationTypeDoc() { duke@1: return annotationType; duke@1: } duke@1: }