Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
1 /*
2 * Copyright (c) 1997, 2010, 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.*;
33 import com.sun.tools.doclets.internal.toolkit.util.*;
35 /**
36 * Writes field documentation in HTML format.
37 *
38 * @author Robert Field
39 * @author Atul M Dambalkar
40 * @author Jamie Ho (rewrite)
41 * @author Bhavesh Patel (Modified)
42 */
43 public class FieldWriterImpl extends AbstractMemberWriter
44 implements FieldWriter, MemberSummaryWriter {
46 public FieldWriterImpl(SubWriterHolderWriter writer, ClassDoc classdoc) {
47 super(writer, classdoc);
48 }
50 public FieldWriterImpl(SubWriterHolderWriter writer) {
51 super(writer);
52 }
54 /**
55 * {@inheritDoc}
56 */
57 public Content getMemberSummaryHeader(ClassDoc classDoc,
58 Content memberSummaryTree) {
59 memberSummaryTree.addContent(HtmlConstants.START_OF_FIELD_SUMMARY);
60 Content memberTree = writer.getMemberTreeHeader();
61 writer.addSummaryHeader(this, classDoc, memberTree);
62 return memberTree;
63 }
65 /**
66 * {@inheritDoc}
67 */
68 public Content getFieldDetailsTreeHeader(ClassDoc classDoc,
69 Content memberDetailsTree) {
70 memberDetailsTree.addContent(HtmlConstants.START_OF_FIELD_DETAILS);
71 Content fieldDetailsTree = writer.getMemberTreeHeader();
72 fieldDetailsTree.addContent(writer.getMarkerAnchor("field_detail"));
73 Content heading = HtmlTree.HEADING(HtmlConstants.DETAILS_HEADING,
74 writer.fieldDetailsLabel);
75 fieldDetailsTree.addContent(heading);
76 return fieldDetailsTree;
77 }
79 /**
80 * {@inheritDoc}
81 */
82 public Content getFieldDocTreeHeader(FieldDoc field,
83 Content fieldDetailsTree) {
84 fieldDetailsTree.addContent(
85 writer.getMarkerAnchor(field.name()));
86 Content fieldDocTree = writer.getMemberTreeHeader();
87 Content heading = new HtmlTree(HtmlConstants.MEMBER_HEADING);
88 heading.addContent(field.name());
89 fieldDocTree.addContent(heading);
90 return fieldDocTree;
91 }
93 /**
94 * {@inheritDoc}
95 */
96 public Content getSignature(FieldDoc field) {
97 Content pre = new HtmlTree(HtmlTag.PRE);
98 writer.addAnnotationInfo(field, pre);
99 addModifiers(field, pre);
100 Content fieldlink = new RawHtml(writer.getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER,
101 field.type())));
102 pre.addContent(fieldlink);
103 pre.addContent(" ");
104 if (configuration().linksource) {
105 Content fieldName = new StringContent(field.name());
106 writer.addSrcLink(field, fieldName, pre);
107 } else {
108 addName(field.name(), pre);
109 }
110 return pre;
111 }
113 /**
114 * {@inheritDoc}
115 */
116 public void addDeprecated(FieldDoc field, Content fieldDocTree) {
117 addDeprecatedInfo(field, fieldDocTree);
118 }
120 /**
121 * {@inheritDoc}
122 */
123 public void addComments(FieldDoc field, Content fieldDocTree) {
124 ClassDoc holder = field.containingClass();
125 if (field.inlineTags().length > 0) {
126 if (holder.equals(classdoc) ||
127 (! (holder.isPublic() || Util.isLinkable(holder, configuration())))) {
128 writer.addInlineComment(field, fieldDocTree);
129 } else {
130 Content link = new RawHtml(
131 writer.getDocLink(LinkInfoImpl.CONTEXT_FIELD_DOC_COPY,
132 holder, field,
133 holder.isIncluded() ?
134 holder.typeName() : holder.qualifiedTypeName(),
135 false));
136 Content codeLink = HtmlTree.CODE(link);
137 Content strong = HtmlTree.STRONG(holder.isClass()?
138 writer.descfrmClassLabel : writer.descfrmInterfaceLabel);
139 strong.addContent(writer.getSpace());
140 strong.addContent(codeLink);
141 fieldDocTree.addContent(HtmlTree.DIV(HtmlStyle.block, strong));
142 writer.addInlineComment(field, fieldDocTree);
143 }
144 }
145 }
147 /**
148 * {@inheritDoc}
149 */
150 public void addTags(FieldDoc field, Content fieldDocTree) {
151 writer.addTagsInfo(field, fieldDocTree);
152 }
154 /**
155 * {@inheritDoc}
156 */
157 public Content getFieldDetails(Content fieldDetailsTree) {
158 return getMemberTree(fieldDetailsTree);
159 }
161 /**
162 * {@inheritDoc}
163 */
164 public Content getFieldDoc(Content fieldDocTree,
165 boolean isLastContent) {
166 return getMemberTree(fieldDocTree, isLastContent);
167 }
169 /**
170 * Close the writer.
171 */
172 public void close() throws IOException {
173 writer.close();
174 }
176 public int getMemberKind() {
177 return VisibleMemberMap.FIELDS;
178 }
180 /**
181 * {@inheritDoc}
182 */
183 public void addSummaryLabel(Content memberTree) {
184 Content label = HtmlTree.HEADING(HtmlConstants.SUMMARY_HEADING,
185 writer.getResource("doclet.Field_Summary"));
186 memberTree.addContent(label);
187 }
189 /**
190 * {@inheritDoc}
191 */
192 public String getTableSummary() {
193 return configuration().getText("doclet.Member_Table_Summary",
194 configuration().getText("doclet.Field_Summary"),
195 configuration().getText("doclet.fields"));
196 }
198 /**
199 * {@inheritDoc}
200 */
201 public String getCaption() {
202 return configuration().getText("doclet.Fields");
203 }
205 /**
206 * {@inheritDoc}
207 */
208 public String[] getSummaryTableHeader(ProgramElementDoc member) {
209 String[] header = new String[] {
210 writer.getModifierTypeHeader(),
211 configuration().getText("doclet.0_and_1",
212 configuration().getText("doclet.Field"),
213 configuration().getText("doclet.Description"))
214 };
215 return header;
216 }
218 /**
219 * {@inheritDoc}
220 */
221 public void addSummaryAnchor(ClassDoc cd, Content memberTree) {
222 memberTree.addContent(writer.getMarkerAnchor("field_summary"));
223 }
225 /**
226 * {@inheritDoc}
227 */
228 public void addInheritedSummaryAnchor(ClassDoc cd, Content inheritedTree) {
229 inheritedTree.addContent(writer.getMarkerAnchor(
230 "fields_inherited_from_class_" + configuration().getClassName(cd)));
231 }
233 /**
234 * {@inheritDoc}
235 */
236 public void addInheritedSummaryLabel(ClassDoc cd, Content inheritedTree) {
237 Content classLink = new RawHtml(writer.getPreQualifiedClassLink(
238 LinkInfoImpl.CONTEXT_MEMBER, cd, false));
239 Content label = new StringContent(cd.isClass() ?
240 configuration().getText("doclet.Fields_Inherited_From_Class") :
241 configuration().getText("doclet.Fields_Inherited_From_Interface"));
242 Content labelHeading = HtmlTree.HEADING(HtmlConstants.INHERITED_SUMMARY_HEADING,
243 label);
244 labelHeading.addContent(writer.getSpace());
245 labelHeading.addContent(classLink);
246 inheritedTree.addContent(labelHeading);
247 }
249 /**
250 * {@inheritDoc}
251 */
252 protected void addSummaryLink(int context, ClassDoc cd, ProgramElementDoc member,
253 Content tdSummary) {
254 Content strong = HtmlTree.STRONG(new RawHtml(
255 writer.getDocLink(context, cd , (MemberDoc) member, member.name(), false)));
256 Content code = HtmlTree.CODE(strong);
257 tdSummary.addContent(code);
258 }
260 /**
261 * {@inheritDoc}
262 */
263 protected void addInheritedSummaryLink(ClassDoc cd,
264 ProgramElementDoc member, Content linksTree) {
265 linksTree.addContent(new RawHtml(
266 writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER, cd, (MemberDoc)member,
267 member.name(), false)));
268 }
270 /**
271 * {@inheritDoc}
272 */
273 protected void addSummaryType(ProgramElementDoc member, Content tdSummaryType) {
274 FieldDoc field = (FieldDoc)member;
275 addModifierAndType(field, field.type(), tdSummaryType);
276 }
278 /**
279 * {@inheritDoc}
280 */
281 protected Content getDeprecatedLink(ProgramElementDoc member) {
282 return writer.getDocLink(LinkInfoImpl.CONTEXT_MEMBER,
283 (MemberDoc) member, ((FieldDoc)member).qualifiedName());
284 }
286 /**
287 * {@inheritDoc}
288 */
289 protected Content getNavSummaryLink(ClassDoc cd, boolean link) {
290 if (link) {
291 return writer.getHyperLink("", (cd == null)?
292 "field_summary":
293 "fields_inherited_from_class_" +
294 configuration().getClassName(cd),
295 writer.getResource("doclet.navField"));
296 } else {
297 return writer.getResource("doclet.navField");
298 }
299 }
301 /**
302 * {@inheritDoc}
303 */
304 protected void addNavDetailLink(boolean link, Content liNav) {
305 if (link) {
306 liNav.addContent(writer.getHyperLink("", "field_detail",
307 writer.getResource("doclet.navField")));
308 } else {
309 liNav.addContent(writer.getResource("doclet.navField"));
310 }
311 }
312 }