src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeOptionalMemberWriterImpl.java
changeset 47216 71c04702a3d5
parent 41157 b235a429089a
child 47427 251676148c62
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     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.AnnotationValue;
       
    32 import javax.lang.model.element.Element;
       
    33 import javax.lang.model.element.ExecutableElement;
       
    34 import javax.lang.model.element.TypeElement;
       
    35 
       
    36 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
       
    37 import jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
       
    38 import jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
       
    39 import jdk.javadoc.internal.doclets.toolkit.AnnotationTypeOptionalMemberWriter;
       
    40 import jdk.javadoc.internal.doclets.toolkit.Content;
       
    41 import jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
       
    42 
       
    43 
       
    44 /**
       
    45  * Writes annotation type optional 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 AnnotationTypeOptionalMemberWriterImpl extends
       
    56         AnnotationTypeRequiredMemberWriterImpl
       
    57     implements AnnotationTypeOptionalMemberWriter, MemberSummaryWriter {
       
    58 
       
    59     /**
       
    60      * Construct a new AnnotationTypeOptionalMemberWriterImpl.
       
    61      *
       
    62      * @param writer         the writer that will write the output.
       
    63      * @param annotationType the AnnotationType that holds this member.
       
    64      */
       
    65     public AnnotationTypeOptionalMemberWriterImpl(SubWriterHolderWriter writer,
       
    66         TypeElement annotationType) {
       
    67         super(writer, annotationType);
       
    68     }
       
    69 
       
    70     /**
       
    71      * {@inheritDoc}
       
    72      */
       
    73     public Content getMemberSummaryHeader(TypeElement typeElement,
       
    74             Content memberSummaryTree) {
       
    75         memberSummaryTree.addContent(
       
    76                 HtmlConstants.START_OF_ANNOTATION_TYPE_OPTIONAL_MEMBER_SUMMARY);
       
    77         Content memberTree = writer.getMemberTreeHeader();
       
    78         writer.addSummaryHeader(this, typeElement, memberTree);
       
    79         return memberTree;
       
    80     }
       
    81 
       
    82     /**
       
    83      * {@inheritDoc}
       
    84      */
       
    85     public void addMemberTree(Content memberSummaryTree, Content memberTree) {
       
    86         writer.addMemberTree(memberSummaryTree, memberTree);
       
    87     }
       
    88 
       
    89     /**
       
    90      * {@inheritDoc}
       
    91      */
       
    92     public void addDefaultValueInfo(Element member, Content annotationDocTree) {
       
    93         if (utils.isAnnotationType(member)) {
       
    94             ExecutableElement ee = (ExecutableElement)member;
       
    95             AnnotationValue value = ee.getDefaultValue();
       
    96             if (value != null) {
       
    97                 Content dt = HtmlTree.DT(contents.default_);
       
    98                 Content dl = HtmlTree.DL(dt);
       
    99                 Content dd = HtmlTree.DD(new StringContent(value.toString()));
       
   100                 dl.addContent(dd);
       
   101                 annotationDocTree.addContent(dl);
       
   102             }
       
   103         }
       
   104     }
       
   105 
       
   106     /**
       
   107      * {@inheritDoc}
       
   108      */
       
   109     public void addSummaryLabel(Content memberTree) {
       
   110         Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
       
   111                 contents.annotateTypeOptionalMemberSummaryLabel);
       
   112         memberTree.addContent(label);
       
   113     }
       
   114 
       
   115     /**
       
   116      * {@inheritDoc}
       
   117      */
       
   118     public String getTableSummary() {
       
   119         return resources.getText("doclet.Member_Table_Summary",
       
   120                 resources.getText("doclet.Annotation_Type_Optional_Member_Summary"),
       
   121                 resources.getText("doclet.annotation_type_optional_members"));
       
   122     }
       
   123 
       
   124     /**
       
   125      * {@inheritDoc}
       
   126      */
       
   127     public Content getCaption() {
       
   128         return configuration.getContent("doclet.Annotation_Type_Optional_Members");
       
   129     }
       
   130 
       
   131     /**
       
   132      * {@inheritDoc}
       
   133      */
       
   134     public List<String> getSummaryTableHeader(Element member) {
       
   135         List<String> header = Arrays.asList(writer.getModifierTypeHeader(),
       
   136                 resources.getText("doclet.Annotation_Type_Optional_Member"),
       
   137                 resources.getText("doclet.Description"));
       
   138         return header;
       
   139     }
       
   140 
       
   141     /**
       
   142      * {@inheritDoc}
       
   143      */
       
   144     public void addSummaryAnchor(TypeElement typeElement, Content memberTree) {
       
   145         memberTree.addContent(writer.getMarkerAnchor(
       
   146                 SectionName.ANNOTATION_TYPE_OPTIONAL_ELEMENT_SUMMARY));
       
   147     }
       
   148 
       
   149     /**
       
   150      * {@inheritDoc}
       
   151      */
       
   152     protected Content getNavSummaryLink(TypeElement typeElement, boolean link) {
       
   153         if (link) {
       
   154             return writer.getHyperLink(
       
   155                     SectionName.ANNOTATION_TYPE_OPTIONAL_ELEMENT_SUMMARY,
       
   156                     contents.navAnnotationTypeOptionalMember);
       
   157         } else {
       
   158             return contents.navAnnotationTypeOptionalMember;
       
   159         }
       
   160     }
       
   161 }