1 /*
   2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.doclets.formats.html;
  27 
  28 import java.io.*;
  29 
  30 import com.sun.javadoc.*;
  31 import com.sun.tools.doclets.formats.html.markup.*;
  32 import com.sun.tools.doclets.internal.toolkit.*;
  33 
  34 /**
  35  * Writes annotation type required member documentation in HTML format.
  36  *
  37  *  <p><b>This is NOT part of any supported API.
  38  *  If you write code that depends on this, you do so at your own risk.
  39  *  This code and its internal interfaces are subject to change or
  40  *  deletion without notice.</b>
  41  *
  42  * @author Jamie Ho
  43  * @author Bhavesh Patel (Modified)
  44  */
  45 public class AnnotationTypeRequiredMemberWriterImpl extends AbstractMemberWriter
  46     implements AnnotationTypeRequiredMemberWriter, MemberSummaryWriter {
  47 
  48     /**
  49      * Construct a new AnnotationTypeRequiredMemberWriterImpl.
  50      *
  51      * @param writer         the writer that will write the output.
  52      * @param annotationType the AnnotationType that holds this member.
  53      */
  54     public AnnotationTypeRequiredMemberWriterImpl(SubWriterHolderWriter writer,
  55             AnnotationTypeDoc annotationType) {
  56         super(writer, annotationType);
  57     }
  58 
  59     /**
  60      * {@inheritDoc}
  61      */
  62     public Content getMemberSummaryHeader(ClassDoc classDoc,
  63             Content memberSummaryTree) {
  64         memberSummaryTree.addContent(
  65                 HtmlConstants.START_OF_ANNOTATION_TYPE_REQUIRED_MEMBER_SUMMARY);
  66         Content memberTree = writer.getMemberTreeHeader();
  67         writer.addSummaryHeader(this, classDoc, memberTree);
  68         return memberTree;
  69     }
  70 
  71     /**
  72      * {@inheritDoc}
  73      */
  74     public Content getMemberTreeHeader() {
  75         return writer.getMemberTreeHeader();
  76     }
  77 
  78     /**
  79      * {@inheritDoc}
  80      */
  81     public void addMemberTree(Content memberSummaryTree, Content memberTree) {
  82         writer.addMemberTree(memberSummaryTree, memberTree);
  83     }
  84 
  85     /**
  86      * {@inheritDoc}
  87      */
  88     public void addAnnotationDetailsMarker(Content memberDetails) {
  89         memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_DETAILS);
  90     }
  91 
  92     /**
  93      * {@inheritDoc}
  94      */
  95     public void addAnnotationDetailsTreeHeader(ClassDoc classDoc,
  96             Content memberDetailsTree) {
  97         if (!writer.printedAnnotationHeading) {
  98             memberDetailsTree.addContent(writer.getMarkerAnchor(
  99                     SectionName.ANNOTATION_TYPE_ELEMENT_DETAIL));
 100             Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
 101                     writer.annotationTypeDetailsLabel);
 102             memberDetailsTree.addContent(heading);
 103             writer.printedAnnotationHeading = true;
 104         }
 105     }
 106 
 107     /**
 108      * {@inheritDoc}
 109      */
 110     public Content getAnnotationDocTreeHeader(MemberDoc member,
 111             Content annotationDetailsTree) {
 112         annotationDetailsTree.addContent(
 113                 writer.getMarkerAnchor(member.name() +
 114                 ((ExecutableMemberDoc) member).signature()));
 115         Content annotationDocTree = writer.getMemberTreeHeader();
 116         Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
 117         heading.addContent(member.name());
 118         annotationDocTree.addContent(heading);
 119         return annotationDocTree;
 120     }
 121 
 122     /**
 123      * {@inheritDoc}
 124      */
 125     public Content getSignature(MemberDoc member) {
 126         Content pre = new HtmlTree(HtmlTag.PRE);
 127         writer.addAnnotationInfo(member, pre);
 128         addModifiers(member, pre);
 129         Content link =
 130                 writer.getLink(new LinkInfoImpl(configuration,
 131                         LinkInfoImpl.Kind.MEMBER, getType(member)));
 132         pre.addContent(link);
 133         pre.addContent(writer.getSpace());
 134         if (configuration.linksource) {
 135             Content memberName = new StringContent(member.name());
 136             writer.addSrcLink(member, memberName, pre);
 137         } else {
 138             addName(member.name(), pre);
 139         }
 140         return pre;
 141     }
 142 
 143     /**
 144      * {@inheritDoc}
 145      */
 146     public void addDeprecated(MemberDoc member, Content annotationDocTree) {
 147         addDeprecatedInfo(member, annotationDocTree);
 148     }
 149 
 150     /**
 151      * {@inheritDoc}
 152      */
 153     public void addComments(MemberDoc member, Content annotationDocTree) {
 154         addComment(member, annotationDocTree);
 155     }
 156 
 157     /**
 158      * {@inheritDoc}
 159      */
 160     public void addTags(MemberDoc member, Content annotationDocTree) {
 161         writer.addTagsInfo(member, annotationDocTree);
 162     }
 163 
 164     /**
 165      * {@inheritDoc}
 166      */
 167     public Content getAnnotationDetails(Content annotationDetailsTree) {
 168         if (configuration.allowTag(HtmlTag.SECTION)) {
 169             HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(annotationDetailsTree));
 170             return htmlTree;
 171         }
 172         return getMemberTree(annotationDetailsTree);
 173     }
 174 
 175     /**
 176      * {@inheritDoc}
 177      */
 178     public Content getAnnotationDoc(Content annotationDocTree,
 179             boolean isLastContent) {
 180         return getMemberTree(annotationDocTree, isLastContent);
 181     }
 182 
 183     /**
 184      * Close the writer.
 185      */
 186     public void close() throws IOException {
 187         writer.close();
 188     }
 189 
 190     /**
 191      * {@inheritDoc}
 192      */
 193     public void addSummaryLabel(Content memberTree) {
 194         Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
 195                 writer.getResource("doclet.Annotation_Type_Required_Member_Summary"));
 196         memberTree.addContent(label);
 197     }
 198 
 199     /**
 200      * {@inheritDoc}
 201      */
 202     public String getTableSummary() {
 203         return configuration.getText("doclet.Member_Table_Summary",
 204                 configuration.getText("doclet.Annotation_Type_Required_Member_Summary"),
 205                 configuration.getText("doclet.annotation_type_required_members"));
 206     }
 207 
 208     /**
 209      * {@inheritDoc}
 210      */
 211     public Content getCaption() {
 212         return configuration.getResource("doclet.Annotation_Type_Required_Members");
 213     }
 214 
 215     /**
 216      * {@inheritDoc}
 217      */
 218     public String[] getSummaryTableHeader(ProgramElementDoc member) {
 219         String[] header = new String[] {
 220             writer.getModifierTypeHeader(),
 221             configuration.getText("doclet.0_and_1",
 222                     configuration.getText("doclet.Annotation_Type_Required_Member"),
 223                     configuration.getText("doclet.Description"))
 224         };
 225         return header;
 226     }
 227 
 228     /**
 229      * {@inheritDoc}
 230      */
 231     public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
 232         memberTree.addContent(writer.getMarkerAnchor(
 233                 SectionName.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY));
 234     }
 235 
 236     /**
 237      * {@inheritDoc}
 238      */
 239     public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
 240     }
 241 
 242     /**
 243      * {@inheritDoc}
 244      */
 245     public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
 246     }
 247 
 248     /**
 249      * {@inheritDoc}
 250      */
 251     protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,
 252             Content tdSummary) {
 253         Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
 254                 writer.getDocLink(context, (MemberDoc) member, member.name(), false));
 255         Content code = HtmlTree.CODE(memberLink);
 256         tdSummary.addContent(code);
 257     }
 258 
 259     /**
 260      * {@inheritDoc}
 261      */
 262     protected void addInheritedSummaryLink(ClassDoc cd,
 263             ProgramElementDoc member, Content linksTree) {
 264         //Not applicable.
 265     }
 266 
 267     /**
 268      * {@inheritDoc}
 269      */
 270     protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
 271         MemberDoc m = (MemberDoc)member;
 272         addModifierAndType(m, getType(m), tdSummaryType);
 273     }
 274 
 275     /**
 276      * {@inheritDoc}
 277      */
 278     protected Content getDeprecatedLink(ProgramElementDoc member) {
 279         return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
 280                 (MemberDoc) member, ((MemberDoc)member).qualifiedName());
 281     }
 282 
 283     /**
 284      * {@inheritDoc}
 285      */
 286     protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
 287         if (link) {
 288             return writer.getHyperLink(
 289                     SectionName.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY,
 290                     writer.getResource("doclet.navAnnotationTypeRequiredMember"));
 291         } else {
 292             return writer.getResource("doclet.navAnnotationTypeRequiredMember");
 293         }
 294     }
 295 
 296     /**
 297      * {@inheritDoc}
 298      */
 299     protected void addNavDetailLink(boolean link, Content liNav) {
 300         if (link) {
 301             liNav.addContent(writer.getHyperLink(
 302                     SectionName.ANNOTATION_TYPE_ELEMENT_DETAIL,
 303                     writer.getResource("doclet.navAnnotationTypeMember")));
 304         } else {
 305             liNav.addContent(writer.getResource("doclet.navAnnotationTypeMember"));
 306         }
 307     }
 308 
 309     private Type getType(MemberDoc member) {
 310         if (member instanceof FieldDoc) {
 311             return ((FieldDoc) member).type();
 312         } else {
 313             return ((MethodDoc) member).returnType();
 314         }
 315     }
 316 }