1 /*
   2  * Copyright (c) 2003, 2016, 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 jdk.javadoc.internal.doclets.formats.html;
  27 
  28 import java.util.Arrays;
  29 import java.util.List;
  30 
  31 import javax.lang.model.element.Element;
  32 import javax.lang.model.element.ExecutableElement;
  33 import javax.lang.model.element.TypeElement;
  34 import javax.lang.model.type.TypeMirror;
  35 
  36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
  37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
  38 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
  39 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
  40 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
  41 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter;
  42 import jdk.javadoc.internal.doclets.toolkit.Content;
  43 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
  44 
  45 
  46 /**
  47  * Writes annotation type required member documentation in HTML format.
  48  *
  49  *  <p><b>This is NOT part of any supported API.
  50  *  If you write code that depends on this, you do so at your own risk.
  51  *  This code and its internal interfaces are subject to change or
  52  *  deletion without notice.</b>
  53  *
  54  * @author Jamie Ho
  55  * @author Bhavesh Patel (Modified)
  56  */
  57 public class AnnotationTypeRequiredMemberWriterImpl extends AbstractMemberWriter
  58     implements AnnotationTypeRequiredMemberWriter, MemberSummaryWriter {
  59 
  60     /**
  61      * Construct a new AnnotationTypeRequiredMemberWriterImpl.
  62      *
  63      * @param writer         the writer that will write the output.
  64      * @param annotationType the AnnotationType that holds this member.
  65      */
  66     public AnnotationTypeRequiredMemberWriterImpl(SubWriterHolderWriter writer,
  67             TypeElement annotationType) {
  68         super(writer, annotationType);
  69     }
  70 
  71     /**
  72      * {@inheritDoc}
  73      */
  74     public Content getMemberSummaryHeader(TypeElement typeElement,
  75             Content memberSummaryTree) {
  76         memberSummaryTree.addContent(
  77                 HtmlConstants.START_OF_ANNOTATION_TYPE_REQUIRED_MEMBER_SUMMARY);
  78         Content memberTree = writer.getMemberTreeHeader();
  79         writer.addSummaryHeader(this, typeElement, memberTree);
  80         return memberTree;
  81     }
  82 
  83     /**
  84      * {@inheritDoc}
  85      */
  86     public Content getMemberTreeHeader() {
  87         return writer.getMemberTreeHeader();
  88     }
  89 
  90     /**
  91      * {@inheritDoc}
  92      */
  93     public void addMemberTree(Content memberSummaryTree, Content memberTree) {
  94         writer.addMemberTree(memberSummaryTree, memberTree);
  95     }
  96 
  97     /**
  98      * {@inheritDoc}
  99      */
 100     public void addAnnotationDetailsMarker(Content memberDetails) {
 101         memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_DETAILS);
 102     }
 103 
 104     /**
 105      * {@inheritDoc}
 106      */
 107     public void addAnnotationDetailsTreeHeader(TypeElement te,
 108             Content memberDetailsTree) {
 109         if (!writer.printedAnnotationHeading) {
 110             memberDetailsTree.addContent(writer.getMarkerAnchor(
 111                     SectionName.ANNOTATION_TYPE_ELEMENT_DETAIL));
 112             Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
 113                     contents.annotationTypeDetailsLabel);
 114             memberDetailsTree.addContent(heading);
 115             writer.printedAnnotationHeading = true;
 116         }
 117     }
 118 
 119     /**
 120      * {@inheritDoc}
 121      */
 122     public Content getAnnotationDocTreeHeader(Element member,
 123             Content annotationDetailsTree) {
 124         String simpleName = name(member);
 125         annotationDetailsTree.addContent(writer.getMarkerAnchor(simpleName +
 126                 utils.signature((ExecutableElement) member)));
 127         Content annotationDocTree = writer.getMemberTreeHeader();
 128         Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
 129         heading.addContent(simpleName);
 130         annotationDocTree.addContent(heading);
 131         return annotationDocTree;
 132     }
 133 
 134     /**
 135      * {@inheritDoc}
 136      */
 137     public Content getSignature(Element member) {
 138         Content pre = new HtmlTree(HtmlTag.PRE);
 139         writer.addAnnotationInfo(member, pre);
 140         addModifiers(member, pre);
 141         Content link =
 142                 writer.getLink(new LinkInfoImpl(configuration,
 143                         LinkInfoImpl.Kind.MEMBER, getType(member)));
 144         pre.addContent(link);
 145         pre.addContent(Contents.SPACE);
 146         if (configuration.linksource) {
 147             Content memberName = new StringContent(name(member));
 148             writer.addSrcLink(member, memberName, pre);
 149         } else {
 150             addName(name(member), pre);
 151         }
 152         return pre;
 153     }
 154 
 155     /**
 156      * {@inheritDoc}
 157      */
 158     public void addDeprecated(Element member, Content annotationDocTree) {
 159         addDeprecatedInfo(member, annotationDocTree);
 160     }
 161 
 162     /**
 163      * {@inheritDoc}
 164      */
 165     public void addComments(Element member, Content annotationDocTree) {
 166         addComment(member, annotationDocTree);
 167     }
 168 
 169     /**
 170      * {@inheritDoc}
 171      */
 172     public void addTags(Element member, Content annotationDocTree) {
 173         writer.addTagsInfo(member, annotationDocTree);
 174     }
 175 
 176     /**
 177      * {@inheritDoc}
 178      */
 179     public Content getAnnotationDetails(Content annotationDetailsTree) {
 180         if (configuration.allowTag(HtmlTag.SECTION)) {
 181             HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(annotationDetailsTree));
 182             return htmlTree;
 183         }
 184         return getMemberTree(annotationDetailsTree);
 185     }
 186 
 187     /**
 188      * {@inheritDoc}
 189      */
 190     public Content getAnnotationDoc(Content annotationDocTree,
 191             boolean isLastContent) {
 192         return getMemberTree(annotationDocTree, isLastContent);
 193     }
 194 
 195     /**
 196      * {@inheritDoc}
 197      */
 198     public void addSummaryLabel(Content memberTree) {
 199         Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
 200                 contents.annotateTypeRequiredMemberSummaryLabel);
 201         memberTree.addContent(label);
 202     }
 203 
 204     /**
 205      * {@inheritDoc}
 206      */
 207     public String getTableSummary() {
 208         return configuration.getText("doclet.Member_Table_Summary",
 209                 configuration.getText("doclet.Annotation_Type_Required_Member_Summary"),
 210                 configuration.getText("doclet.annotation_type_required_members"));
 211     }
 212 
 213     /**
 214      * {@inheritDoc}
 215      */
 216     public Content getCaption() {
 217         return configuration.getContent("doclet.Annotation_Type_Required_Members");
 218     }
 219 
 220     /**
 221      * {@inheritDoc}
 222      */
 223     public List<String> getSummaryTableHeader(Element member) {
 224         List<String> header = Arrays.asList(writer.getModifierTypeHeader(),
 225                 resources.getText("doclet.Annotation_Type_Required_Member"), resources.getText("doclet.Description"));
 226         return header;
 227     }
 228 
 229     /**
 230      * {@inheritDoc}
 231      */
 232     public void addSummaryAnchor(TypeElement typeElement, Content memberTree) {
 233         memberTree.addContent(writer.getMarkerAnchor(
 234                 SectionName.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY));
 235     }
 236 
 237     /**
 238      * {@inheritDoc}
 239      */
 240     public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) {
 241     }
 242 
 243     /**
 244      * {@inheritDoc}
 245      */
 246     public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
 247     }
 248 
 249     /**
 250      * {@inheritDoc}
 251      */
 252     protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member,
 253             Content tdSummary) {
 254         Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
 255                 writer.getDocLink(context, member, name(member), false));
 256         Content code = HtmlTree.CODE(memberLink);
 257         tdSummary.addContent(code);
 258     }
 259 
 260     /**
 261      * {@inheritDoc}
 262      */
 263     protected void addInheritedSummaryLink(TypeElement typeElement,
 264             Element member, Content linksTree) {
 265         //Not applicable.
 266     }
 267 
 268     /**
 269      * {@inheritDoc}
 270      */
 271     protected void addSummaryType(Element member, Content tdSummaryType) {
 272         addModifierAndType(member, getType(member), tdSummaryType);
 273     }
 274 
 275     /**
 276      * {@inheritDoc}
 277      */
 278     protected Content getDeprecatedLink(Element member) {
 279         String name = utils.getFullyQualifiedName(member) + "." + member.getSimpleName();
 280         return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, member, name);
 281     }
 282 
 283     /**
 284      * {@inheritDoc}
 285      */
 286     protected Content getNavSummaryLink(TypeElement typeElement, boolean link) {
 287         if (link) {
 288             return writer.getHyperLink(
 289                     SectionName.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY,
 290                     contents.navAnnotationTypeRequiredMember);
 291         } else {
 292             return contents.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                     contents.navAnnotationTypeMember));
 304         } else {
 305             liNav.addContent(contents.navAnnotationTypeMember);
 306         }
 307     }
 308 
 309     private TypeMirror getType(Element member) {
 310         return utils.isExecutableElement(member)
 311                 ? utils.getReturnType((ExecutableElement) member)
 312                 : member.asType();
 313     }
 314 }