AnnotationTypeFieldWriterImpl.java revision 3233:b5d08bc0d224
175584Sru/*
275584Sru * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
375584Sru * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
475584Sru *
5114402Sru * This code is free software; you can redistribute it and/or modify it
675584Sru * under the terms of the GNU General Public License version 2 only, as
775584Sru * published by the Free Software Foundation.  Oracle designates this
875584Sru * particular file as subject to the "Classpath" exception as provided
975584Sru * by Oracle in the LICENSE file that accompanied this code.
1075584Sru *
1175584Sru * This code is distributed in the hope that it will be useful, but WITHOUT
1275584Sru * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1375584Sru * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1475584Sru * version 2 for more details (a copy is included in the LICENSE file that
1575584Sru * accompanied this code).
16104862Sru *
17104862Sru * You should have received a copy of the GNU General Public License version
18114402Sru * 2 along with this work; if not, write to the Free Software Foundation,
19114402Sru * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20114402Sru *
21114402Sru * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22114402Sru * or visit www.oracle.com if you need additional information or have any
23114402Sru * questions.
24114402Sru */
25114402Sru
26114402Srupackage jdk.javadoc.internal.doclets.formats.html;
27114402Sru
28114402Sruimport java.io.*;
29114402Sru
30114402Sruimport java.util.Arrays;
31114402Sruimport java.util.List;
32114402Sru
33114402Sruimport javax.lang.model.element.Element;
34114402Sruimport javax.lang.model.element.ExecutableElement;
35114402Sruimport javax.lang.model.element.TypeElement;
36114402Sruimport javax.lang.model.type.TypeMirror;
37114402Sru
38114402Sruimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlConstants;
39114402Sruimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle;
40114402Sruimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlTag;
41114402Sruimport jdk.javadoc.internal.doclets.formats.html.markup.HtmlTree;
42114402Sruimport jdk.javadoc.internal.doclets.formats.html.markup.StringContent;
43114402Sruimport jdk.javadoc.internal.doclets.toolkit.AnnotationTypeFieldWriter;
44114402Sruimport jdk.javadoc.internal.doclets.toolkit.Content;
45114402Sruimport jdk.javadoc.internal.doclets.toolkit.MemberSummaryWriter;
46114402Sru
47114402Sru
48114402Sru/**
49114402Sru * Writes annotation type field documentation in HTML format.
50114402Sru *
51114402Sru *  <p><b>This is NOT part of any supported API.
52114402Sru *  If you write code that depends on this, you do so at your own risk.
53114402Sru *  This code and its internal interfaces are subject to change or
54114402Sru *  deletion without notice.</b>
55114402Sru *
56114402Sru * @author Bhavesh Patel
57114402Sru */
58114402Srupublic class AnnotationTypeFieldWriterImpl extends AbstractMemberWriter
59114402Sru    implements AnnotationTypeFieldWriter, MemberSummaryWriter {
60151497Sru
61151497Sru    /**
62151497Sru     * Construct a new AnnotationTypeFieldWriterImpl.
63151497Sru     *
64151497Sru     * @param writer         the writer that will write the output.
65151497Sru     * @param annotationType the AnnotationType that holds this member.
66151497Sru     */
67151497Sru    public AnnotationTypeFieldWriterImpl(SubWriterHolderWriter writer,
68151497Sru            TypeElement annotationType) {
69151497Sru        super(writer, annotationType);
70151497Sru    }
71151497Sru
72151497Sru    /**
73151497Sru     * {@inheritDoc}
74151497Sru     */
75151497Sru    public Content getMemberSummaryHeader(TypeElement typeElement,
76151497Sru            Content memberSummaryTree) {
77151497Sru        memberSummaryTree.addContent(
78151497Sru                HtmlConstants.START_OF_ANNOTATION_TYPE_FIELD_SUMMARY);
79151497Sru        Content memberTree = writer.getMemberTreeHeader();
80151497Sru        writer.addSummaryHeader(this, typeElement, memberTree);
81151497Sru        return memberTree;
82151497Sru    }
83151497Sru
84151497Sru    /**
85151497Sru     * {@inheritDoc}
86114402Sru     */
87151497Sru    public Content getMemberTreeHeader() {
88151497Sru        return writer.getMemberTreeHeader();
89151497Sru    }
90151497Sru
91151497Sru    /**
9275584Sru     * {@inheritDoc}
93104862Sru     */
94104862Sru    public void addMemberTree(Content memberSummaryTree, Content memberTree) {
95        writer.addMemberTree(memberSummaryTree, memberTree);
96    }
97
98    /**
99     * {@inheritDoc}
100     */
101    public void addAnnotationFieldDetailsMarker(Content memberDetails) {
102        memberDetails.addContent(HtmlConstants.START_OF_ANNOTATION_TYPE_FIELD_DETAILS);
103    }
104
105    /**
106     * {@inheritDoc}
107     */
108    public void addAnnotationDetailsTreeHeader(TypeElement typeElement,
109            Content memberDetailsTree) {
110        if (!writer.printedAnnotationFieldHeading) {
111            memberDetailsTree.addContent(writer.getMarkerAnchor(
112                    SectionName.ANNOTATION_TYPE_FIELD_DETAIL));
113            Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
114                    writer.fieldDetailsLabel);
115            memberDetailsTree.addContent(heading);
116            writer.printedAnnotationFieldHeading = true;
117        }
118    }
119
120    /**
121     * {@inheritDoc}
122     */
123    public Content getAnnotationDocTreeHeader(Element member,
124            Content annotationDetailsTree) {
125        annotationDetailsTree.addContent(
126                writer.getMarkerAnchor(name(member)));
127        Content annotationDocTree = writer.getMemberTreeHeader();
128        Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
129        heading.addContent(name(member));
130        annotationDocTree.addContent(heading);
131        return annotationDocTree;
132    }
133
134    /**
135     * {@inheritDoc}
136     */
137    public Content getSignature(Element member) {
138        Content pre = new HtmlTree(HtmlTag.PRE);
139        writer.addAnnotationInfo(member, pre);
140        addModifiers(member, pre);
141        Content link =
142                writer.getLink(new LinkInfoImpl(configuration,
143                        LinkInfoImpl.Kind.MEMBER, getType(member)));
144        pre.addContent(link);
145        pre.addContent(writer.getSpace());
146        if (configuration.linksource) {
147            Content memberName = new StringContent(name(member));
148            writer.addSrcLink(member, memberName, pre);
149        } else {
150            addName(name(member), pre);
151        }
152        return pre;
153    }
154
155    /**
156     * {@inheritDoc}
157     */
158    public void addDeprecated(Element member, Content annotationDocTree) {
159        addDeprecatedInfo(member, annotationDocTree);
160    }
161
162    /**
163     * {@inheritDoc}
164     */
165    public void addComments(Element member, Content annotationDocTree) {
166        addComment(member, annotationDocTree);
167    }
168
169    /**
170     * {@inheritDoc}
171     */
172    public void addTags(Element member, Content annotationDocTree) {
173        writer.addTagsInfo(member, annotationDocTree);
174    }
175
176    /**
177     * {@inheritDoc}
178     */
179    public Content getAnnotationDetails(Content annotationDetailsTree) {
180        if (configuration.allowTag(HtmlTag.SECTION)) {
181            HtmlTree htmlTree = HtmlTree.SECTION(getMemberTree(annotationDetailsTree));
182            return htmlTree;
183        }
184        return getMemberTree(annotationDetailsTree);
185    }
186
187    /**
188     * {@inheritDoc}
189     */
190    public Content getAnnotationDoc(Content annotationDocTree,
191            boolean isLastContent) {
192        return getMemberTree(annotationDocTree, isLastContent);
193    }
194
195    /**
196     * Close the writer.
197     */
198    public void close() throws IOException {
199        writer.close();
200    }
201
202    /**
203     * {@inheritDoc}
204     */
205    public void addSummaryLabel(Content memberTree) {
206        Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
207                writer.getResource("doclet.Field_Summary"));
208        memberTree.addContent(label);
209    }
210
211    /**
212     * {@inheritDoc}
213     */
214    public String getTableSummary() {
215        return configuration.getText("doclet.Member_Table_Summary",
216                configuration.getText("doclet.Field_Summary"),
217                configuration.getText("doclet.fields"));
218    }
219
220    /**
221     * {@inheritDoc}
222     */
223    public Content getCaption() {
224        return configuration.getResource("doclet.Fields");
225    }
226
227    /**
228     * {@inheritDoc}
229     */
230    public List<String> getSummaryTableHeader(Element member) {
231        List<String> header = Arrays.asList(writer.getModifierTypeHeader(),
232                configuration.getText("doclet.0_and_1",
233                        configuration.getText("doclet.Fields"),
234                        configuration.getText("doclet.Description")));
235        return header;
236    }
237
238    /**
239     * {@inheritDoc}
240     */
241    public void addSummaryAnchor(TypeElement typeElement, Content memberTree) {
242        memberTree.addContent(writer.getMarkerAnchor(
243                SectionName.ANNOTATION_TYPE_FIELD_SUMMARY));
244    }
245
246    /**
247     * {@inheritDoc}
248     */
249    public void addInheritedSummaryAnchor(TypeElement typeElement, Content inheritedTree) {
250    }
251
252    /**
253     * {@inheritDoc}
254     */
255    public void addInheritedSummaryLabel(TypeElement typeElement, Content inheritedTree) {
256    }
257
258    /**
259     * {@inheritDoc}
260     */
261    protected void addSummaryLink(LinkInfoImpl.Kind context, TypeElement typeElement, Element member,
262            Content tdSummary) {
263        Content memberLink = HtmlTree.SPAN(HtmlStyle.memberNameLink,
264                writer.getDocLink(context, member, name(member), false));
265        Content code = HtmlTree.CODE(memberLink);
266        tdSummary.addContent(code);
267    }
268
269    /**
270     * {@inheritDoc}
271     */
272    protected void addInheritedSummaryLink(TypeElement typeElement,
273            Element member, Content linksTree) {
274        //Not applicable.
275    }
276
277    /**
278     * {@inheritDoc}
279     */
280    protected void addSummaryType(Element member, Content tdSummaryType) {
281        addModifierAndType(member, getType(member), tdSummaryType);
282    }
283
284    /**
285     * {@inheritDoc}
286     */
287    protected Content getDeprecatedLink(Element member) {
288        return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
289                member, utils.getFullyQualifiedName(member));
290    }
291
292    /**
293     * {@inheritDoc}
294     */
295    protected Content getNavSummaryLink(TypeElement typeElement, boolean link) {
296        if (link) {
297            return writer.getHyperLink(
298                    SectionName.ANNOTATION_TYPE_FIELD_SUMMARY,
299                    writer.getResource("doclet.navField"));
300        } else {
301            return writer.getResource("doclet.navField");
302        }
303    }
304
305    /**
306     * {@inheritDoc}
307     */
308    protected void addNavDetailLink(boolean link, Content liNav) {
309        if (link) {
310            liNav.addContent(writer.getHyperLink(
311                    SectionName.ANNOTATION_TYPE_FIELD_DETAIL,
312                    writer.getResource("doclet.navField")));
313        } else {
314            liNav.addContent(writer.getResource("doclet.navField"));
315        }
316    }
317    private TypeMirror getType(Element member) {
318        if (utils.isConstructor(member))
319            return null;
320        if (utils.isExecutableElement(member))
321            return utils.getReturnType((ExecutableElement)member);
322        return member.asType();
323    }
324}
325