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.Table;
  37 import jdk.javadoc.internal.doclets.formats.html.markup.TableHeader;
  38 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter;
  39 import jdk.javadoc.internal.doclets.toolkit.Content;
  40 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
  41 
  42 
  43 /**
  44  * Writes annotation type required member documentation in HTML format.
  45  *
  46  *  <p><b>This is NOT part of any supported API.
  47  *  If you write code that depends on this, you do so at your own risk.
  48  *  This code and its internal interfaces are subject to change or
  49  *  deletion without notice.</b>
  50  *
  51  * @author Jamie Ho
  52  * @author Bhavesh Patel (Modified)
  53  */
  54 public class AnnotationTypeRequiredMemberWriterImpl extends AbstractMemberWriter
  55     implements AnnotationTypeRequiredMemberWriter, MemberSummaryWriter {
  56 
  57     /**
  58      * Construct a new AnnotationTypeRequiredMemberWriterImpl.
  59      *
  60      * @param writer         the writer that will write the output.
  61      * @param annotationType the AnnotationType that holds this member.
  62      */
  63     public AnnotationTypeRequiredMemberWriterImpl(SubWriterHolderWriter writer,
  64             TypeElement annotationType) {
  65         super(writer, annotationType);
  66     }
  67 
  68     /**
  69      * {@inheritDoc}
  70      */
  71     public Content getMemberSummaryHeader(TypeElement typeElement,
  72             Content memberSummaryTree) {
  73         memberSummaryTree.add(
  74                 MarkerComments.START_OF_ANNOTATION_TYPE_REQUIRED_MEMBER_SUMMARY);
  75         Content memberTree = new ContentBuilder();
  76         writer.addSummaryHeader(this, typeElement, memberTree);
  77         return memberTree;
  78     }
  79 
  80     /**
  81      * {@inheritDoc}
  82      */
  83     public Content getMemberTreeHeader() {
  84         return writer.getMemberTreeHeader();
  85     }
  86 
  87     /**
  88      * {@inheritDoc}
  89      */
  90     public void addMemberTree(Content memberSummaryTree, Content memberTree) {
  91         writer.addMemberTree(HtmlStyle.memberSummary, memberSummaryTree, memberTree);
  92     }
  93 
  94     /**
  95      * {@inheritDoc}
  96      */
  97     public void addAnnotationDetailsMarker(Content memberDetails) {
  98         memberDetails.add(MarkerComments.START_OF_ANNOTATION_TYPE_DETAILS);
  99     }
 100 
 101     /**
 102      * {@inheritDoc}
 103      */
 104     public Content getAnnotationDetailsTreeHeader(TypeElement te) {
 105         Content memberDetailsTree = new ContentBuilder();
 106         if (!writer.printedAnnotationHeading) {
 107             Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING,
 108                     contents.annotationTypeDetailsLabel);
 109             memberDetailsTree.add(heading);
 110             memberDetailsTree.add(links.createAnchor(
 111                     SectionName.ANNOTATION_TYPE_ELEMENT_DETAIL));
 112             writer.printedAnnotationHeading = true;
 113         }
 114         return memberDetailsTree;
 115     }
 116 
 117     /**
 118      * {@inheritDoc}
 119      */
 120     @Override
 121     public Content getAnnotationDocTreeHeader(Element member, Content annotationDetailsTree) {
 122         String simpleName = name(member);
 123         Content annotationDocTree = new ContentBuilder();
 124         Content heading = new HtmlTree(Headings.TypeDeclaration.MEMBER_HEADING);
 125         heading.add(simpleName);
 126         annotationDocTree.add(heading);
 127         annotationDocTree.add(links.createAnchor(
 128                 simpleName + utils.signature((ExecutableElement) member)));
 129         return HtmlTree.SECTION(HtmlStyle.detail, annotationDocTree);
 130     }
 131 
 132     /**
 133      * {@inheritDoc}
 134      */
 135     public Content getSignature(Element member) {
 136         MemberSignature sig = new MemberSignature(member);
 137         sig.addType(getType(member));
 138         sig.addName(member);
 139         return sig.toContent();











 140     }
 141 
 142     /**
 143      * {@inheritDoc}
 144      */
 145     public void addDeprecated(Element member, Content annotationDocTree) {
 146         addDeprecatedInfo(member, annotationDocTree);
 147     }
 148 
 149     /**
 150      * {@inheritDoc}
 151      */
 152     public void addComments(Element member, Content annotationDocTree) {
 153         addComment(member, annotationDocTree);
 154     }
 155 
 156     /**
 157      * {@inheritDoc}
 158      */
 159     public void addTags(Element member, Content annotationDocTree) {
 160         writer.addTagsInfo(member, annotationDocTree);
 161     }
 162 
 163     /**
 164      * {@inheritDoc}
 165      */
 166     public Content getAnnotationDetails(Content annotationDetailsTreeHeader, Content annotationDetailsTree) {
 167         Content annotationDetails = new ContentBuilder(annotationDetailsTreeHeader, annotationDetailsTree);
 168         return getMemberTree(HtmlTree.SECTION(HtmlStyle.memberDetails, annotationDetails));
 169     }
 170 
 171     /**
 172      * {@inheritDoc}
 173      */
 174     public Content getAnnotationDoc(Content annotationDocTree,
 175             boolean isLastContent) {
 176         return getMemberTree(annotationDocTree, isLastContent);
 177     }
 178 
 179     /**
 180      * {@inheritDoc}
 181      */
 182     public void addSummaryLabel(Content memberTree) {
 183         Content label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING,
 184                 contents.annotateTypeRequiredMemberSummaryLabel);
 185         memberTree.add(label);
 186     }
 187 
 188     /**
 189      * Get the caption for the summary table.
 190      * @return the caption
 191      */
 192     // Overridden by AnnotationTypeOptionalMemberWriterImpl
 193     protected Content getCaption() {
 194         return contents.getContent("doclet.Annotation_Type_Required_Members");
 195     }
 196 
 197     /**
 198      * {@inheritDoc}
 199      */
 200     @Override
 201     public TableHeader getSummaryTableHeader(Element member) {
 202         return new TableHeader(contents.modifierAndTypeLabel,
 203                 contents.annotationTypeRequiredMemberLabel, contents.descriptionLabel);
 204     }
 205 
 206     /**
 207      * {@inheritDoc}
 208      */
 209     @Override
 210     protected Table createSummaryTable() {
 211         return new Table(HtmlStyle.memberSummary)
 212                 .setCaption(getCaption())
 213                 .setHeader(getSummaryTableHeader(typeElement))
 214                 .setRowScopeColumn(1)
 215                 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast);
 216     }
 217 
 218     /**
 219      * {@inheritDoc}
 220      */
 221     public void addSummaryAnchor(TypeElement typeElement, Content memberTree) {
 222         memberTree.add(links.createAnchor(
 223                 SectionName.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY));
 224     }
 225 
 226     /**
 227      * {@inheritDoc}
 228      */
 229     public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) {
 230     }
 231 
 232     /**
 233      * {@inheritDoc}
 234      */
 235     public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
 236     }
 237 
 238     /**
 239      * {@inheritDoc}
 240      */
 241     protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member,
 242             Content tdSummary) {
 243         Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
 244                 writer.getDocLink(context, member, name(member), false));
 245         Content code = HtmlTree.CODE(memberLink);
 246         tdSummary.add(code);
 247     }
 248 
 249     /**
 250      * {@inheritDoc}
 251      */
 252     protected void addInheritedSummaryLink(TypeElement typeElement,
 253             Element member, Content linksTree) {
 254         //Not applicable.
 255     }
 256 
 257     /**
 258      * {@inheritDoc}
 259      */
 260     protected void addSummaryType(Element member, Content tdSummaryType) {
 261         addModifierAndType(member, getType(member), tdSummaryType);
 262     }
 263 
 264     /**
 265      * {@inheritDoc}
 266      */
 267     protected Content getDeprecatedLink(Element member) {
 268         String name = utils.getFullyQualifiedName(member) + "." + member.getSimpleName();
 269         return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, member, name);
 270     }
 271 
 272     private TypeMirror getType(Element member) {
 273         return utils.isExecutableElement(member)
 274                 ? utils.getReturnType((ExecutableElement) member)
 275                 : member.asType();
 276     }
 277 }
--- EOF ---