Tue, 14 May 2013 10:14:54 -0700
8012176: reduce use of TagletOutputImpl.toString
Reviewed-by: darcy
1 /*
2 * Copyright (c) 2003, 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 */
26 package com.sun.tools.doclets.formats.html;
28 import java.io.*;
30 import com.sun.javadoc.*;
31 import com.sun.tools.doclets.formats.html.markup.*;
32 import com.sun.tools.doclets.internal.toolkit.*;
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 {
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 }
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 }
71 /**
72 * {@inheritDoc}
73 */
74 public void addAnnotationDetailsTreeHeader(ClassDoc classDoc,
75 Content memberDetailsTree) {
76 if (!writer.printedAnnotationHeading) {
77 memberDetailsTree.addContent(writer.getMarkerAnchor(
78 "annotation_type_element_detail"));
79 Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
80 writer.annotationTypeDetailsLabel);
81 memberDetailsTree.addContent(heading);
82 writer.printedAnnotationHeading = true;
83 }
84 }
86 /**
87 * {@inheritDoc}
88 */
89 public Content getAnnotationDocTreeHeader(MemberDoc member,
90 Content annotationDetailsTree) {
91 annotationDetailsTree.addContent(
92 writer.getMarkerAnchor(member.name() +
93 ((ExecutableMemberDoc) member).signature()));
94 Content annotationDocTree = writer.getMemberTreeHeader();
95 Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
96 heading.addContent(member.name());
97 annotationDocTree.addContent(heading);
98 return annotationDocTree;
99 }
101 /**
102 * {@inheritDoc}
103 */
104 public Content getSignature(MemberDoc member) {
105 Content pre = new HtmlTree(HtmlTag.PRE);
106 writer.addAnnotationInfo(member, pre);
107 addModifiers(member, pre);
108 Content link =
109 writer.getLink(new LinkInfoImpl(configuration,
110 LinkInfoImpl.Kind.MEMBER, getType(member)));
111 pre.addContent(link);
112 pre.addContent(writer.getSpace());
113 if (configuration.linksource) {
114 Content memberName = new StringContent(member.name());
115 writer.addSrcLink(member, memberName, pre);
116 } else {
117 addName(member.name(), pre);
118 }
119 return pre;
120 }
122 /**
123 * {@inheritDoc}
124 */
125 public void addDeprecated(MemberDoc member, Content annotationDocTree) {
126 addDeprecatedInfo(member, annotationDocTree);
127 }
129 /**
130 * {@inheritDoc}
131 */
132 public void addComments(MemberDoc member, Content annotationDocTree) {
133 addComment(member, annotationDocTree);
134 }
136 /**
137 * {@inheritDoc}
138 */
139 public void addTags(MemberDoc member, Content annotationDocTree) {
140 writer.addTagsInfo(member, annotationDocTree);
141 }
143 /**
144 * {@inheritDoc}
145 */
146 public Content getAnnotationDetails(Content annotationDetailsTree) {
147 return getMemberTree(annotationDetailsTree);
148 }
150 /**
151 * {@inheritDoc}
152 */
153 public Content getAnnotationDoc(Content annotationDocTree,
154 boolean isLastContent) {
155 return getMemberTree(annotationDocTree, isLastContent);
156 }
158 /**
159 * Close the writer.
160 */
161 public void close() throws IOException {
162 writer.close();
163 }
165 /**
166 * {@inheritDoc}
167 */
168 public void addSummaryLabel(Content memberTree) {
169 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
170 writer.getResource("doclet.Annotation_Type_Required_Member_Summary"));
171 memberTree.addContent(label);
172 }
174 /**
175 * {@inheritDoc}
176 */
177 public String getTableSummary() {
178 return configuration.getText("doclet.Member_Table_Summary",
179 configuration.getText("doclet.Annotation_Type_Required_Member_Summary"),
180 configuration.getText("doclet.annotation_type_required_members"));
181 }
183 /**
184 * {@inheritDoc}
185 */
186 public String getCaption() {
187 return configuration.getText("doclet.Annotation_Type_Required_Members");
188 }
190 /**
191 * {@inheritDoc}
192 */
193 public String[] getSummaryTableHeader(ProgramElementDoc member) {
194 String[] header = new String[] {
195 writer.getModifierTypeHeader(),
196 configuration.getText("doclet.0_and_1",
197 configuration.getText("doclet.Annotation_Type_Required_Member"),
198 configuration.getText("doclet.Description"))
199 };
200 return header;
201 }
203 /**
204 * {@inheritDoc}
205 */
206 public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
207 memberTree.addContent(writer.getMarkerAnchor(
208 "annotation_type_required_element_summary"));
209 }
211 /**
212 * {@inheritDoc}
213 */
214 public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
215 }
217 /**
218 * {@inheritDoc}
219 */
220 public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
221 }
223 /**
224 * {@inheritDoc}
225 */
226 protected void addSummaryLink(LinkInfoImpl.Kind context, ClassDoc cd, ProgramElementDoc member,
227 Content tdSummary) {
228 Content strong = HtmlTree.STRONG(
229 writer.getDocLink(context, (MemberDoc) member, member.name(), false));
230 Content code = HtmlTree.CODE(strong);
231 tdSummary.addContent(code);
232 }
234 /**
235 * {@inheritDoc}
236 */
237 protected void addInheritedSummaryLink(ClassDoc cd,
238 ProgramElementDoc member, Content linksTree) {
239 //Not applicable.
240 }
242 /**
243 * {@inheritDoc}
244 */
245 protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
246 MemberDoc m = (MemberDoc)member;
247 addModifierAndType(m, getType(m), tdSummaryType);
248 }
250 /**
251 * {@inheritDoc}
252 */
253 protected Content getDeprecatedLink(ProgramElementDoc member) {
254 return writer.getDocLink(LinkInfoImpl.Kind.MEMBER,
255 (MemberDoc) member, ((MemberDoc)member).qualifiedName());
256 }
258 /**
259 * {@inheritDoc}
260 */
261 protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
262 if (link) {
263 return writer.getHyperLink("annotation_type_required_element_summary",
264 writer.getResource("doclet.navAnnotationTypeRequiredMember"));
265 } else {
266 return writer.getResource("doclet.navAnnotationTypeRequiredMember");
267 }
268 }
270 /**
271 * {@inheritDoc}
272 */
273 protected void addNavDetailLink(boolean link, Content liNav) {
274 if (link) {
275 liNav.addContent(writer.getHyperLink("annotation_type_element_detail",
276 writer.getResource("doclet.navAnnotationTypeMember")));
277 } else {
278 liNav.addContent(writer.getResource("doclet.navAnnotationTypeMember"));
279 }
280 }
282 private Type getType(MemberDoc member) {
283 if (member instanceof FieldDoc) {
284 return ((FieldDoc) member).type();
285 } else {
286 return ((MethodDoc) member).returnType();
287 }
288 }
289 }