AnnotationTypeFieldWriterImpl.java revision 2571:10fc81ac75b4
1/*
2 * Copyright (c) 2013, 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
26package com.sun.tools.doclets.formats.html;
27
28import java.io.*;
29
30import com.sun.javadoc.*;
31import com.sun.tools.doclets.formats.html.markup.*;
32import com.sun.tools.doclets.internal.toolkit.*;
33
34/**
35 * Writes annotation type field 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 Bhavesh Patel
43 */
44public class AnnotationTypeFieldWriterImpl extends AbstractMemberWriter
45    implements AnnotationTypeFieldWriter, MemberSummaryWriter {
46
47    /**
48     * Construct a new AnnotationTypeFieldWriterImpl.
49     *
50     * @param writer         the writer that will write the output.
51     * @param annotationType the AnnotationType that holds this member.
52     */
53    public AnnotationTypeFieldWriterImpl(SubWriterHolderWriter writer,
54            AnnotationTypeDoc annotationType) {
55        super(writer, annotationType);
56    }
57
58    /**
59     * {@inheritDoc}
60     */
61    public Content getMemberSummaryHeader(ClassDoc classDoc,
62            Content memberSummaryTree) {
63        memberSummaryTree.addContent(
64                HtmlConstants.START_OF_ANNOTATION_TYPE_FIELD_SUMMARY);
65        Content memberTree = writer.getMemberTreeHeader();
66        writer.addSummaryHeader(this, classDoc, memberTree);
67        return memberTree;
68    }
69
70    /**
71     * {@inheritDoc}
72     */
73    public Content getMemberTreeHeader() {
74        return writer.getMemberTreeHeader();
75    }
76
77    /**
78     * {@inheritDoc}
79     */
80    public void addAnnotationFieldDetailsMarker(Content memberDetails) {
81        memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_FIELD_DETAILS);
82    }
83
84    /**
85     * {@inheritDoc}
86     */
87    public void addAnnotationDetailsTreeHeader(ClassDoc classDoc,
88            Content memberDetailsTree) {
89        if (!writer.printedAnnotationFieldHeading) {
90            memberDetailsTree.addContent(writer.getMarkerAnchor(
91                    SectionName.ANNOTATION_TYPE_FIELD_DETAIL));
92            Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
93                    writer.fieldDetailsLabel);
94            memberDetailsTree.addContent(heading);
95            writer.printedAnnotationFieldHeading = true;
96        }
97    }
98
99    /**
100     * {@inheritDoc}
101     */
102    public Content getAnnotationDocTreeHeader(MemberDoc member,
103            Content annotationDetailsTree) {
104        annotationDetailsTree.addContent(
105                writer.getMarkerAnchor(member.name()));
106        Content annotationDocTree = writer.getMemberTreeHeader();
107        Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
108        heading.addContent(member.name());
109        annotationDocTree.addContent(heading);
110        return annotationDocTree;
111    }
112
113    /**
114     * {@inheritDoc}
115     */
116    public Content getSignature(MemberDoc member) {
117        Content pre = new HtmlTree(HtmlTag.PRE);
118        writer.addAnnotationInfo(member, pre);
119        addModifiers(member, pre);
120        Content link =
121                writer.getLink(new LinkInfoImpl(configuration,
122                        LinkInfoImpl.Kind.MEMBER, getType(member)));
123        pre.addContent(link);
124        pre.addContent(writer.getSpace());
125        if (configuration.linksource) {
126            Content memberName = new StringContent(member.name());
127            writer.addSrcLink(member, memberName, pre);
128        } else {
129            addName(member.name(), pre);
130        }
131        return pre;
132    }
133
134    /**
135     * {@inheritDoc}
136     */
137    public void addDeprecated(MemberDoc member, Content annotationDocTree) {
138        addDeprecatedInfo(member, annotationDocTree);
139    }
140
141    /**
142     * {@inheritDoc}
143     */
144    public void addComments(MemberDoc member, Content annotationDocTree) {
145        addComment(member, annotationDocTree);
146    }
147
148    /**
149     * {@inheritDoc}
150     */
151    public void addTags(MemberDoc member, Content annotationDocTree) {
152        writer.addTagsInfo(member, annotationDocTree);
153    }
154
155    /**
156     * {@inheritDoc}
157     */
158    public Content getAnnotationDetails(Content annotationDetailsTree) {
159        return getMemberTree(annotationDetailsTree);
160    }
161
162    /**
163     * {@inheritDoc}
164     */
165    public Content getAnnotationDoc(Content annotationDocTree,
166            boolean isLastContent) {
167        return getMemberTree(annotationDocTree, isLastContent);
168    }
169
170    /**
171     * Close the writer.
172     */
173    public void close() throws IOException {
174        writer.close();
175    }
176
177    /**
178     * {@inheritDoc}
179     */
180    public void addSummaryLabel(Content memberTree) {
181        Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
182                writer.getResource("doclet.Field_Summary"));
183        memberTree.addContent(label);
184    }
185
186    /**
187     * {@inheritDoc}
188     */
189    public String getTableSummary() {
190        return configuration.getText("doclet.Member_Table_Summary",
191                configuration.getText("doclet.Field_Summary"),
192                configuration.getText("doclet.fields"));
193    }
194
195    /**
196     * {@inheritDoc}
197     */
198    public Content getCaption() {
199        return configuration.getResource("doclet.Fields");
200    }
201
202    /**
203     * {@inheritDoc}
204     */
205    public String[] getSummaryTableHeader(ProgramElementDoc member) {
206        String[] header = new String[] {
207            writer.getModifierTypeHeader(),
208            configuration.getText("doclet.0_and_1",
209                    configuration.getText("doclet.Fields"),
210                    configuration.getText("doclet.Description"))
211        };
212        return header;
213    }
214
215    /**
216     * {@inheritDoc}
217     */
218    public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
219        memberTree.addContent(writer.getMarkerAnchor(
220                SectionName.ANNOTATION_TYPE_FIELD_SUMMARY));
221    }
222
223    /**
224     * {@inheritDoc}
225     */
226    public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
227    }
228
229    /**
230     * {@inheritDoc}
231     */
232    public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
233    }
234
235    /**
236     * {@inheritDoc}
237     */
238    protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,
239            Content tdSummary) {
240        Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
241                writer.getDocLink(context, (MemberDoc) member, member.name(), false));
242        Content code = HtmlTree.CODE(memberLink);
243        tdSummary.addContent(code);
244    }
245
246    /**
247     * {@inheritDoc}
248     */
249    protected void addInheritedSummaryLink(ClassDoc cd,
250            ProgramElementDoc member, Content linksTree) {
251        //Not applicable.
252    }
253
254    /**
255     * {@inheritDoc}
256     */
257    protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
258        MemberDoc m = (MemberDoc)member;
259        addModifierAndType(m, getType(m), tdSummaryType);
260    }
261
262    /**
263     * {@inheritDoc}
264     */
265    protected Content getDeprecatedLink(ProgramElementDoc member) {
266        return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
267                (MemberDoc) member, ((MemberDoc)member).qualifiedName());
268    }
269
270    /**
271     * {@inheritDoc}
272     */
273    protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
274        if (link) {
275            return writer.getHyperLink(
276                    SectionName.ANNOTATION_TYPE_FIELD_SUMMARY,
277                    writer.getResource("doclet.navField"));
278        } else {
279            return writer.getResource("doclet.navField");
280        }
281    }
282
283    /**
284     * {@inheritDoc}
285     */
286    protected void addNavDetailLink(boolean link, Content liNav) {
287        if (link) {
288            liNav.addContent(writer.getHyperLink(
289                    SectionName.ANNOTATION_TYPE_FIELD_DETAIL,
290                    writer.getResource("doclet.navField")));
291        } else {
292            liNav.addContent(writer.getResource("doclet.navField"));
293        }
294    }
295
296    private Type getType(MemberDoc member) {
297        if (member instanceof FieldDoc) {
298            return ((FieldDoc) member).type();
299        } else {
300            return ((MethodDoc) member).returnType();
301        }
302    }
303}
304