Thu, 13 Jan 2011 21:28:38 -0800
7010528: javadoc performance regression
Reviewed-by: jjg
1 /*
2 * Copyright (c) 2003, 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 com.sun.javadoc.*;
29 import com.sun.tools.doclets.internal.toolkit.*;
30 import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder;
31 import com.sun.tools.doclets.internal.toolkit.taglets.*;
32 import com.sun.tools.doclets.internal.toolkit.util.*;
34 /**
35 * The taglet writer that writes HTML.
36 *
37 * @since 1.5
38 * @author Jamie Ho
39 * @author Bhavesh Patel (Modified)
40 */
42 public class TagletWriterImpl extends TagletWriter {
44 private HtmlDocletWriter htmlWriter;
46 public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) {
47 this.htmlWriter = htmlWriter;
48 this.isFirstSentence = isFirstSentence;
49 }
51 /**
52 * {@inheritDoc}
53 */
54 public TagletOutput getOutputInstance() {
55 return new TagletOutputImpl("");
56 }
58 /**
59 * {@inheritDoc}
60 */
61 public TagletOutput getDocRootOutput() {
62 return new TagletOutputImpl(htmlWriter.relativepathNoSlash);
63 }
65 /**
66 * {@inheritDoc}
67 */
68 public TagletOutput deprecatedTagOutput(Doc doc) {
69 StringBuffer output = new StringBuffer();
70 Tag[] deprs = doc.tags("deprecated");
71 if (doc instanceof ClassDoc) {
72 if (Util.isDeprecated((ProgramElementDoc) doc)) {
73 output.append("<span class=\"strong\">" +
74 ConfigurationImpl.getInstance().
75 getText("doclet.Deprecated") + "</span> ");
76 if (deprs.length > 0) {
77 Tag[] commentTags = deprs[0].inlineTags();
78 if (commentTags.length > 0) {
80 output.append(commentTagsToOutput(null, doc,
81 deprs[0].inlineTags(), false).toString()
82 );
83 }
84 }
85 }
86 } else {
87 MemberDoc member = (MemberDoc) doc;
88 if (Util.isDeprecated((ProgramElementDoc) doc)) {
89 output.append("<span class=\"strong\">" +
90 ConfigurationImpl.getInstance().
91 getText("doclet.Deprecated") + "</span> ");
92 if (deprs.length > 0) {
93 output.append("<i>");
94 output.append(commentTagsToOutput(null, doc,
95 deprs[0].inlineTags(), false).toString());
96 output.append("</i>");
97 }
98 } else {
99 if (Util.isDeprecated(member.containingClass())) {
100 output.append("<span class=\"strong\">" +
101 ConfigurationImpl.getInstance().
102 getText("doclet.Deprecated") + "</span> ");
103 }
104 }
105 }
106 return new TagletOutputImpl(output.toString());
107 }
109 /**
110 * {@inheritDoc}
111 */
112 public MessageRetriever getMsgRetriever() {
113 return htmlWriter.configuration.message;
114 }
116 /**
117 * {@inheritDoc}
118 */
119 public TagletOutput getParamHeader(String header) {
120 StringBuffer result = new StringBuffer();
121 result.append("<dt>");
122 result.append("<span class=\"strong\">" + header + "</span></dt>");
123 return new TagletOutputImpl(result.toString());
124 }
126 /**
127 * {@inheritDoc}
128 */
129 public TagletOutput paramTagOutput(ParamTag paramTag, String paramName) {
130 TagletOutput result = new TagletOutputImpl("<dd><code>" + paramName + "</code>"
131 + " - " + htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false) + "</dd>");
132 return result;
133 }
135 /**
136 * {@inheritDoc}
137 */
138 public TagletOutput returnTagOutput(Tag returnTag) {
139 TagletOutput result = new TagletOutputImpl(DocletConstants.NL + "<dt>" +
140 "<span class=\"strong\">" + htmlWriter.configuration.getText("doclet.Returns") +
141 "</span>" + "</dt>" + "<dd>" +
142 htmlWriter.commentTagsToString(returnTag, null, returnTag.inlineTags(),
143 false) + "</dd>");
144 return result;
145 }
147 /**
148 * {@inheritDoc}
149 */
150 public TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags) {
151 String result = "";
152 if (seeTags.length > 0) {
153 result = addSeeHeader(result);
154 for (int i = 0; i < seeTags.length; ++i) {
155 if (i > 0) {
156 result += ", " + DocletConstants.NL;
157 }
158 result += htmlWriter.seeTagToString(seeTags[i]);
159 }
160 }
161 if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
162 htmlWriter instanceof ClassWriterImpl) {
163 //Automatically add link to constant values page for constant fields.
164 result = addSeeHeader(result);
165 result += htmlWriter.getHyperLinkString(htmlWriter.relativePath +
166 ConfigurationImpl.CONSTANTS_FILE_NAME
167 + "#" + ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName()
168 + "." + ((FieldDoc) holder).name(),
169 htmlWriter.configuration.getText("doclet.Constants_Summary"));
170 }
171 if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
172 //Automatically add link to serialized form page for serializable classes.
173 if ((SerializedFormBuilder.serialInclude(holder) &&
174 SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) {
175 result = addSeeHeader(result);
176 result += htmlWriter.getHyperLinkString(htmlWriter.relativePath + "serialized-form.html",
177 ((ClassDoc)holder).qualifiedName(), htmlWriter.configuration.getText("doclet.Serialized_Form"), false);
178 }
179 }
180 return result.equals("") ? null : new TagletOutputImpl(result + "</dd>");
181 }
183 private String addSeeHeader(String result) {
184 if (result != null && result.length() > 0) {
185 return result + ", " + DocletConstants.NL;
186 } else {
187 return "<dt><span class=\"strong\">" +
188 htmlWriter.configuration().getText("doclet.See_Also") + "</span></dt><dd>";
189 }
190 }
192 /**
193 * {@inheritDoc}
194 */
195 public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) {
196 String result = "<dt><span class=\"strong\">" + header + "</span></dt>" + DocletConstants.NL +
197 " <dd>";
198 for (int i = 0; i < simpleTags.length; i++) {
199 if (i > 0) {
200 result += ", ";
201 }
202 result += htmlWriter.commentTagsToString(simpleTags[i], null, simpleTags[i].inlineTags(), false);
203 }
204 result += "</dd>" + DocletConstants.NL;
205 return new TagletOutputImpl(result);
206 }
208 /**
209 * {@inheritDoc}
210 */
211 public TagletOutput simpleTagOutput(Tag simpleTag, String header) {
212 return new TagletOutputImpl("<dt><span class=\"strong\">" + header + "</span></dt>" + " <dd>"
213 + htmlWriter.commentTagsToString(simpleTag, null, simpleTag.inlineTags(), false)
214 + "</dd>" + DocletConstants.NL);
215 }
217 /**
218 * {@inheritDoc}
219 */
220 public TagletOutput getThrowsHeader() {
221 return new TagletOutputImpl(DocletConstants.NL + "<dt>" + "<span class=\"strong\">" +
222 htmlWriter.configuration().getText("doclet.Throws") + "</span></dt>");
223 }
225 /**
226 * {@inheritDoc}
227 */
228 public TagletOutput throwsTagOutput(ThrowsTag throwsTag) {
229 String result = DocletConstants.NL + "<dd>";
230 result += throwsTag.exceptionType() == null ?
231 htmlWriter.codeText(throwsTag.exceptionName()) :
232 htmlWriter.codeText(
233 htmlWriter.getLink(new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER,
234 throwsTag.exceptionType())));
235 TagletOutput text = new TagletOutputImpl(
236 htmlWriter.commentTagsToString(throwsTag, null,
237 throwsTag.inlineTags(), false));
238 if (text != null && text.toString().length() > 0) {
239 result += " - " + text;
240 }
241 result += "</dd>";
242 return new TagletOutputImpl(result);
243 }
245 /**
246 * {@inheritDoc}
247 */
248 public TagletOutput throwsTagOutput(Type throwsType) {
249 return new TagletOutputImpl(DocletConstants.NL + "<dd>" +
250 htmlWriter.codeText(htmlWriter.getLink(
251 new LinkInfoImpl(LinkInfoImpl.CONTEXT_MEMBER, throwsType))) + "</dd>");
252 }
254 /**
255 * {@inheritDoc}
256 */
257 public TagletOutput valueTagOutput(FieldDoc field, String constantVal,
258 boolean includeLink) {
259 return new TagletOutputImpl(includeLink ?
260 htmlWriter.getDocLink(LinkInfoImpl.CONTEXT_VALUE_TAG, field,
261 constantVal, false) : constantVal);
262 }
264 /**
265 * {@inheritDoc}
266 */
267 public TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags) {
268 return commentTagsToOutput(holderTag, null, tags, false);
269 }
271 /**
272 * {@inheritDoc}
273 */
274 public TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags) {
275 return commentTagsToOutput(null, holderDoc, tags, false);
276 }
278 /**
279 * {@inheritDoc}
280 */
281 public TagletOutput commentTagsToOutput(Tag holderTag,
282 Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
283 return new TagletOutputImpl(htmlWriter.commentTagsToString(
284 holderTag, holderDoc, tags, isFirstSentence));
285 }
287 /**
288 * {@inheritDoc}
289 */
290 public Configuration configuration() {
291 return htmlWriter.configuration();
292 }
294 /**
295 * Return an instance of a TagletWriter that knows how to write HTML.
296 *
297 * @return an instance of a TagletWriter that knows how to write HTML.
298 */
299 public TagletOutput getTagletOutputInstance() {
300 return new TagletOutputImpl("");
301 }
302 }