AnnotationTypeRequiredMemberWriterImpl.java revision 3233:b5d08bc0d224
11435Smcimadamore/*
22933Sakulyakh * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
31435Smcimadamore * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41435Smcimadamore *
51435Smcimadamore * This code is free software; you can redistribute it and/or modify it
61435Smcimadamore * under the terms of the GNU General Public License version 2 only, as
71435Smcimadamore * published by the Free Software Foundation.  Oracle designates this
81435Smcimadamore * particular file as subject to the "Classpath" exception as provided
91435Smcimadamore * by Oracle in the LICENSE file that accompanied this code.
101435Smcimadamore *
111435Smcimadamore * This code is distributed in the hope that it will be useful, but WITHOUT
121435Smcimadamore * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131435Smcimadamore * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
141435Smcimadamore * version 2 for more details (a copy is included in the LICENSE file that
151435Smcimadamore * accompanied this code).
161435Smcimadamore *
171435Smcimadamore * You should have received a copy of the GNU General Public License version
181435Smcimadamore * 2 along with this work; if not, write to the Free Software Foundation,
191435Smcimadamore * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
201435Smcimadamore *
211435Smcimadamore * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
221435Smcimadamore * or visit www.oracle.com if you need additional information or have any
231435Smcimadamore * questions.
241435Smcimadamore */
251435Smcimadamore
262049Semcpackage jdk.javadoc.internal.doclets.formats.html;
271435Smcimadamore
281465Sdarcyimport java.io.*;
292933Sakulyakhimport java.util.Arrays;
302933Sakulyakhimport java.util.List;
311435Smcimadamore
323294Salanbimport javax.lang.model.element.Element;
331435Smcimadamoreimport javax.lang.model.element.ExecutableElement;
341435Smcimadamoreimport javax.lang.model.element.TypeElement;
351435Smcimadamoreimport javax.lang.model.type.TypeMirror;
361435Smcimadamore
371435Smcimadamoreimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
381435Smcimadamoreimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
391435Smcimadamoreimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
401435Smcimadamoreimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
411435Smcimadamoreimport jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
421435Smcimadamoreimport jdk.javadoc.internal.doclets.toolkit.AnnotationTypeRequiredMemberWriter;
431435Smcimadamoreimport jdk.javadoc.internal.doclets.toolkit.Content;
441435Smcimadamoreimport jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
451435Smcimadamore
461435Smcimadamore
471435Smcimadamore/**
481435Smcimadamore * Writes annotation type required member documentation in HTML format.
491435Smcimadamore *
501435Smcimadamore *  <p><b>This is NOT part of any supported API.
512049Semc *  If you write code that depends on this, you do so at your own risk.
521435Smcimadamore *  This code and its internal interfaces are subject to change or
531435Smcimadamore *  deletion without notice.</b>
541435Smcimadamore *
55 * @author Jamie Ho
56 * @author Bhavesh Patel (Modified)
57 */
58public 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);
194    }
195
196    /**
197     * Close the writer.
198     */
199    public void close() throws IOException {
200        writer.close();
201    }
202
203    /**
204     * {@inheritDoc}
205     */
206    public void addSummaryLabel(Content memberTree) {
207        Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
208                writer.getResource("doclet.Annotation_Type_Required_Member_Summary"));
209        memberTree.addContent(label);
210    }
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}
325