src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/AnnotationTypeRequiredMemberWriterImpl.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2015, 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 com.sun.tools.doclets.formats.html;
  27 
  28 import java.io.*;


  29 
  30 import com.sun.javadoc.*;
  31 import com.sun.tools.doclets.formats.html.markup.*;
  32 import com.sun.tools.doclets.internal.toolkit.*;

  33 










  34 /**
  35  * Writes annotation type required member documentation in HTML format.
  36  *
  37  *  <p><b>This is NOT part of any supported API.
  38  *  If you write code that depends on this, you do so at your own risk.
  39  *  This code and its internal interfaces are subject to change or
  40  *  deletion without notice.</b>
  41  *
  42  * @author Jamie Ho
  43  * @author Bhavesh Patel (Modified)
  44  */
  45 public class AnnotationTypeRequiredMemberWriterImpl extends AbstractMemberWriter
  46     implements AnnotationTypeRequiredMemberWriter, MemberSummaryWriter {
  47 
  48     /**
  49      * Construct a new AnnotationTypeRequiredMemberWriterImpl.
  50      *
  51      * @param writer         the writer that will write the output.
  52      * @param annotationType the AnnotationType that holds this member.
  53      */
  54     public AnnotationTypeRequiredMemberWriterImpl(SubWriterHolderWriter writer,
  55             AnnotationTypeDoc annotationType) {
  56         super(writer, annotationType);
  57     }
  58 
  59     /**
  60      * {@inheritDoc}
  61      */
  62     public Content getMemberSummaryHeader(ClassDoc classDoc,
  63             Content memberSummaryTree) {
  64         memberSummaryTree.addContent(
  65                 HtmlConstants.START_OF_ANNOTATION_TYPE_REQUIRED_MEMBER_SUMMARY);
  66         Content memberTree = writer.getMemberTreeHeader();
  67         writer.addSummaryHeader(this, classDoc, memberTree);
  68         return memberTree;
  69     }
  70 
  71     /**
  72      * {@inheritDoc}
  73      */
  74     public Content getMemberTreeHeader() {
  75         return writer.getMemberTreeHeader();
  76     }
  77 
  78     /**
  79      * {@inheritDoc}
  80      */
  81     public void addMemberTree(Content memberSummaryTree, Content memberTree) {
  82         writer.addMemberTree(memberSummaryTree, memberTree);
  83     }
  84 
  85     /**
  86      * {@inheritDoc}
  87      */
  88     public void addAnnotationDetailsMarker(Content memberDetails) {
  89         memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_DETAILS);
  90     }
  91 
  92     /**
  93      * {@inheritDoc}
  94      */
  95     public void addAnnotationDetailsTreeHeader(ClassDoc classDoc,
  96             Content memberDetailsTree) {
  97         if (!writer.printedAnnotationHeading) {
  98             memberDetailsTree.addContent(writer.getMarkerAnchor(
  99                     SectionName.ANNOTATION_TYPE_ELEMENT_DETAIL));
 100             Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
 101                     writer.annotationTypeDetailsLabel);
 102             memberDetailsTree.addContent(heading);
 103             writer.printedAnnotationHeading = true;
 104         }
 105     }
 106 
 107     /**
 108      * {@inheritDoc}
 109      */
 110     public Content getAnnotationDocTreeHeader(MemberDoc member,
 111             Content annotationDetailsTree) {
 112         annotationDetailsTree.addContent(
 113                 writer.getMarkerAnchor(member.name() +
 114                 ((ExecutableMemberDoc) member).signature()));
 115         Content annotationDocTree = writer.getMemberTreeHeader();
 116         Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
 117         heading.addContent(member.name());
 118         annotationDocTree.addContent(heading);
 119         return annotationDocTree;
 120     }
 121 
 122     /**
 123      * {@inheritDoc}
 124      */
 125     public Content getSignature(MemberDoc member) {
 126         Content pre = new HtmlTree(HtmlTag.PRE);
 127         writer.addAnnotationInfo(member, pre);
 128         addModifiers(member, pre);
 129         Content link =
 130                 writer.getLink(new LinkInfoImpl(configuration,
 131                         LinkInfoImpl.Kind.MEMBER, getType(member)));
 132         pre.addContent(link);
 133         pre.addContent(writer.getSpace());
 134         if (configuration.linksource) {
 135             Content memberName = new StringContent(member.name());
 136             writer.addSrcLink(member, memberName, pre);
 137         } else {
 138             addName(member.name(), pre);
 139         }
 140         return pre;
 141     }
 142 
 143     /**
 144      * {@inheritDoc}
 145      */
 146     public void addDeprecated(MemberDoc member, Content annotationDocTree) {
 147         addDeprecatedInfo(member, annotationDocTree);
 148     }
 149 
 150     /**
 151      * {@inheritDoc}
 152      */
 153     public void addComments(MemberDoc member, Content annotationDocTree) {
 154         addComment(member, annotationDocTree);
 155     }
 156 
 157     /**
 158      * {@inheritDoc}
 159      */
 160     public void addTags(MemberDoc member, Content annotationDocTree) {
 161         writer.addTagsInfo(member, annotationDocTree);
 162     }
 163 
 164     /**
 165      * {@inheritDoc}
 166      */
 167     public Content getAnnotationDetails(Content annotationDetailsTree) {
 168         if (configuration.allowTag(HtmlTag.SECTION)) {
 169             HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(annotationDetailsTree));
 170             return htmlTree;
 171         }
 172         return getMemberTree(annotationDetailsTree);
 173     }
 174 
 175     /**
 176      * {@inheritDoc}
 177      */
 178     public Content getAnnotationDoc(Content annotationDocTree,
 179             boolean isLastContent) {
 180         return getMemberTree(annotationDocTree, isLastContent);


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


 211 
 212     /**
 213      * {@inheritDoc}
 214      */
 215     public String getTableSummary() {
 216         return configuration.getText("doclet.Member_Table_Summary",
 217                 configuration.getText("doclet.Annotation_Type_Required_Member_Summary"),
 218                 configuration.getText("doclet.annotation_type_required_members"));
 219     }
 220 
 221     /**
 222      * {@inheritDoc}
 223      */
 224     public Content getCaption() {
 225         return configuration.getResource("doclet.Annotation_Type_Required_Members");
 226     }
 227 
 228     /**
 229      * {@inheritDoc}
 230      */
 231     public List<String> getSummaryTableHeader(Element member) {
 232         List<String> header = Arrays.asList(writer.getModifierTypeHeader(),

 233                 configuration.getText("doclet.0_and_1",
 234                         configuration.getText("doclet.Annotation_Type_Required_Member"),
 235                         configuration.getText("doclet.Description")));

 236         return header;
 237     }
 238 
 239     /**
 240      * {@inheritDoc}
 241      */
 242     public void addSummaryAnchor(TypeElement typeElement, Content memberTree) {
 243         memberTree.addContent(writer.getMarkerAnchor(
 244                 SectionName.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY));
 245     }
 246 
 247     /**
 248      * {@inheritDoc}
 249      */
 250     public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) {
 251     }
 252 
 253     /**
 254      * {@inheritDoc}
 255      */
 256     public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
 257     }
 258 
 259     /**
 260      * {@inheritDoc}
 261      */
 262     protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member,
 263             Content tdSummary) {
 264         Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
 265                 writer.getDocLink(context, member, name(member), false));
 266         Content code = HtmlTree.CODE(memberLink);
 267         tdSummary.addContent(code);
 268     }
 269 
 270     /**
 271      * {@inheritDoc}
 272      */
 273     protected void addInheritedSummaryLink(TypeElement typeElement,
 274             Element member, Content linksTree) {
 275         //Not applicable.
 276     }
 277 
 278     /**
 279      * {@inheritDoc}
 280      */
 281     protected void addSummaryType(Element member, Content tdSummaryType) {
 282         addModifierAndType(member, getType(member), tdSummaryType);

 283     }
 284 
 285     /**
 286      * {@inheritDoc}
 287      */
 288     protected Content getDeprecatedLink(Element member) {
 289         String name = utils.getFullyQualifiedName(member) + "." + member.getSimpleName();
 290         return writer.getDocLink(LinkInfoImpl.Kind.MEMBER, member, name);
 291     }
 292 
 293     /**
 294      * {@inheritDoc}
 295      */
 296     protected Content getNavSummaryLink(TypeElement typeElement, boolean link) {
 297         if (link) {
 298             return writer.getHyperLink(
 299                     SectionName.ANNOTATION_TYPE_REQUIRED_ELEMENT_SUMMARY,
 300                     writer.getResource("doclet.navAnnotationTypeRequiredMember"));
 301         } else {
 302             return writer.getResource("doclet.navAnnotationTypeRequiredMember");
 303         }
 304     }
 305 
 306     /**
 307      * {@inheritDoc}
 308      */
 309     protected void addNavDetailLink(boolean link, Content liNav) {
 310         if (link) {
 311             liNav.addContent(writer.getHyperLink(
 312                     SectionName.ANNOTATION_TYPE_ELEMENT_DETAIL,
 313                     writer.getResource("doclet.navAnnotationTypeMember")));
 314         } else {
 315             liNav.addContent(writer.getResource("doclet.navAnnotationTypeMember"));
 316         }
 317     }
 318 
 319     private TypeMirror getType(Element member) {
 320         return utils.isExecutableElement(member)
 321                 ? utils.getReturnType((ExecutableElement) member)
 322                 : member.asType();

 323     }

 324 }