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