1 /*
   2  * Copyright (c) 2013, 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.AnnotationTypeFieldWriter;
  40 import jdk.javadoc.internal.doclets.toolkit.Content;
  41 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
  42 
  43 /**
  44  * Writes annotation type field 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 public class AnnotationTypeFieldWriterImpl extends AbstractMemberWriter
  52     implements AnnotationTypeFieldWriter, MemberSummaryWriter {
  53 
  54     /**
  55      * Construct a new AnnotationTypeFieldWriterImpl.
  56      *
  57      * @param writer         the writer that will write the output.
  58      * @param annotationType the AnnotationType that holds this member.
  59      */
  60     public AnnotationTypeFieldWriterImpl(SubWriterHolderWriter writer,
  61             TypeElement annotationType) {
  62         super(writer, annotationType);
  63     }
  64 
  65     /**
  66      * {@inheritDoc}
  67      */
  68     public Content getMemberSummaryHeader(TypeElement typeElement,
  69             Content memberSummaryTree) {
  70         memberSummaryTree.add(
  71                 MarkerComments.START_OF_ANNOTATION_TYPE_FIELD_SUMMARY);
  72         Content memberTree = new ContentBuilder();
  73         writer.addSummaryHeader(this, memberTree);
  74         return memberTree;
  75     }
  76 
  77     /**
  78      * {@inheritDoc}
  79      */
  80     public Content getMemberTreeHeader() {
  81         return writer.getMemberTreeHeader();
  82     }
  83 
  84     /**
  85      * {@inheritDoc}
  86      */
  87     public void addMemberTree(Content memberSummaryTree, Content memberTree) {
  88         writer.addMemberTree(HtmlStyle.fieldSummary,
  89                 SectionName.ANNOTATION_TYPE_FIELD_SUMMARY, memberSummaryTree, memberTree);
  90     }
  91 
  92     /**
  93      * {@inheritDoc}
  94      */
  95     public void addAnnotationFieldDetailsMarker(Content memberDetails) {
  96         memberDetails.add(MarkerComments.START_OF_ANNOTATION_TYPE_FIELD_DETAILS);
  97     }
  98 
  99     /**
 100      * {@inheritDoc}
 101      */
 102     public Content getAnnotationDetailsTreeHeader() {
 103         Content memberDetailsTree = new ContentBuilder();
 104         if (!writer.printedAnnotationFieldHeading) {
 105             Content heading = HtmlTree.HEADING(Headings.TypeDeclaration.DETAILS_HEADING,
 106                     contents.fieldDetailsLabel);
 107             memberDetailsTree.add(heading);
 108             writer.printedAnnotationFieldHeading = true;
 109         }
 110         return memberDetailsTree;
 111     }
 112 
 113     /**
 114      * {@inheritDoc}
 115      */
 116     public Content getAnnotationDocTreeHeader(Element member) {
 117         Content annotationDocTree = new ContentBuilder();
 118         Content heading = new HtmlTree(Headings.TypeDeclaration.MEMBER_HEADING,
 119                 new StringContent(name(member)));
 120         annotationDocTree.add(heading);
 121         return HtmlTree.SECTION(HtmlStyle.detail, annotationDocTree).setId(name(member));
 122     }
 123 
 124     /**
 125      * {@inheritDoc}
 126      */
 127     public Content getSignature(Element member) {
 128         return new MemberSignature(member)
 129                 .addType(getType(member))
 130                 .toContent();
 131     }
 132 
 133     /**
 134      * {@inheritDoc}
 135      */
 136     public void addDeprecated(Element member, Content annotationDocTree) {
 137         addDeprecatedInfo(member, annotationDocTree);
 138     }
 139 
 140     /**
 141      * {@inheritDoc}
 142      */
 143     public void addComments(Element member, Content annotationDocTree) {
 144         addComment(member, annotationDocTree);
 145     }
 146 
 147     /**
 148      * {@inheritDoc}
 149      */
 150     public void addTags(Element member, Content annotationDocTree) {
 151         writer.addTagsInfo(member, annotationDocTree);
 152     }
 153 
 154     /**
 155      * {@inheritDoc}
 156      */
 157     public Content getAnnotationDetails(Content annotationDetailsTreeHeader, Content annotationDetailsTree) {
 158         Content annotationDetails = new ContentBuilder();
 159         annotationDetails.add(annotationDetailsTreeHeader);
 160         annotationDetails.add(annotationDetailsTree);
 161         return getMemberTree(HtmlTree.SECTION(HtmlStyle.fieldDetails, annotationDetails)
 162                 .setId(SectionName.ANNOTATION_TYPE_FIELD_DETAIL.getName()));
 163     }
 164 
 165     /**
 166      * {@inheritDoc}
 167      */
 168     public Content getAnnotationDoc(Content annotationDocTree) {
 169         return getMemberTree(annotationDocTree);
 170     }
 171 
 172     /**
 173      * {@inheritDoc}
 174      */
 175     public void addSummaryLabel(Content memberTree) {
 176         HtmlTree label = HtmlTree.HEADING(Headings.TypeDeclaration.SUMMARY_HEADING,
 177                 contents.fieldSummaryLabel);
 178         memberTree.add(label);
 179     }
 180 
 181     /**
 182      * {@inheritDoc}
 183      */
 184     @Override
 185     public TableHeader getSummaryTableHeader(Element member) {
 186         return new TableHeader(contents.modifierAndTypeLabel, contents.fields,
 187                 contents.descriptionLabel);
 188     }
 189 
 190     @Override
 191     protected Table createSummaryTable() {
 192         Content caption = contents.getContent("doclet.Fields");
 193 
 194         TableHeader header = new TableHeader(contents.modifierAndTypeLabel, contents.fields,
 195             contents.descriptionLabel);
 196 
 197         return new Table(HtmlStyle.memberSummary)
 198                 .setCaption(caption)
 199                 .setHeader(header)
 200                 .setRowScopeColumn(1)
 201                 .setColumnStyles(HtmlStyle.colFirst, HtmlStyle.colSecond, HtmlStyle.colLast);
 202     }
 203 
 204     /**
 205      * {@inheritDoc}
 206      */
 207     @Override
 208     public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
 209     }
 210 
 211     /**
 212      * {@inheritDoc}
 213      */
 214     @Override
 215     protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member,
 216             Content tdSummary) {
 217         Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
 218                 writer.getDocLink(context, member, name(member), false));
 219         Content code = HtmlTree.CODE(memberLink);
 220         tdSummary.add(code);
 221     }
 222 
 223     /**
 224      * {@inheritDoc}
 225      */
 226     protected void addInheritedSummaryLink(TypeElement typeElement,
 227             Element member, Content linksTree) {
 228         //Not applicable.
 229     }
 230 
 231     /**
 232      * {@inheritDoc}
 233      */
 234     protected void addSummaryType(Element member, Content tdSummaryType) {
 235         addModifierAndType(member, getType(member), tdSummaryType);
 236     }
 237 
 238     /**
 239      * {@inheritDoc}
 240      */
 241     protected Content getDeprecatedLink(Element member) {
 242         return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
 243                 member, utils.getFullyQualifiedName(member));
 244     }
 245 
 246     private TypeMirror getType(Element member) {
 247         if (utils.isConstructor(member))
 248             return null;
 249         if (utils.isExecutableElement(member))
 250             return utils.getReturnType((ExecutableElement)member);
 251         return member.asType();
 252     }
 253 }