Tue, 14 May 2013 10:14:54 -0700
8012174: {@literal} and {@code} should use \"new\" Taglet, not old.
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 com.sun.javadoc.*;
29 import com.sun.tools.doclets.formats.html.markup.HtmlAttr;
30 import com.sun.tools.doclets.formats.html.markup.HtmlTag;
31 import com.sun.tools.doclets.formats.html.markup.HtmlTree;
32 import com.sun.tools.doclets.formats.html.markup.StringContent;
33 import com.sun.tools.doclets.internal.toolkit.*;
34 import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder;
35 import com.sun.tools.doclets.internal.toolkit.taglets.*;
36 import com.sun.tools.doclets.internal.toolkit.util.*;
38 /**
39 * The taglet writer that writes HTML.
40 *
41 * <p><b>This is NOT part of any supported API.
42 * If you write code that depends on this, you do so at your own risk.
43 * This code and its internal interfaces are subject to change or
44 * deletion without notice.</b>
45 *
46 * @since 1.5
47 * @author Jamie Ho
48 * @author Bhavesh Patel (Modified)
49 */
51 public class TagletWriterImpl extends TagletWriter {
53 private final HtmlDocletWriter htmlWriter;
54 private final ConfigurationImpl configuration;
56 public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) {
57 super(isFirstSentence);
58 this.htmlWriter = htmlWriter;
59 configuration = htmlWriter.configuration;
60 }
62 /**
63 * {@inheritDoc}
64 */
65 public TagletOutput getOutputInstance() {
66 return new TagletOutputImpl("");
67 }
69 /**
70 * {@inheritDoc}
71 */
72 protected TagletOutput codeTagOutput(Tag tag) {
73 Content result = HtmlTree.CODE(new StringContent(tag.text()));
74 return new TagletOutputImpl(result.toString());
75 }
77 /**
78 * {@inheritDoc}
79 */
80 public TagletOutput getDocRootOutput() {
81 if (configuration.docrootparent.length() > 0)
82 return new TagletOutputImpl(configuration.docrootparent);
83 else if (htmlWriter.pathToRoot.isEmpty())
84 return new TagletOutputImpl(".");
85 else
86 return new TagletOutputImpl(htmlWriter.pathToRoot.getPath());
87 }
89 /**
90 * {@inheritDoc}
91 */
92 public TagletOutput deprecatedTagOutput(Doc doc) {
93 StringBuilder output = new StringBuilder();
94 Tag[] deprs = doc.tags("deprecated");
95 if (doc instanceof ClassDoc) {
96 if (Util.isDeprecated((ProgramElementDoc) doc)) {
97 output.append("<span class=\"strong\">" +
98 configuration.
99 getText("doclet.Deprecated") + "</span> ");
100 if (deprs.length > 0) {
101 Tag[] commentTags = deprs[0].inlineTags();
102 if (commentTags.length > 0) {
104 output.append(commentTagsToOutput(null, doc,
105 deprs[0].inlineTags(), false).toString()
106 );
107 }
108 }
109 }
110 } else {
111 MemberDoc member = (MemberDoc) doc;
112 if (Util.isDeprecated((ProgramElementDoc) doc)) {
113 output.append("<span class=\"strong\">" +
114 configuration.
115 getText("doclet.Deprecated") + "</span> ");
116 if (deprs.length > 0) {
117 output.append("<i>");
118 output.append(commentTagsToOutput(null, doc,
119 deprs[0].inlineTags(), false).toString());
120 output.append("</i>");
121 }
122 } else {
123 if (Util.isDeprecated(member.containingClass())) {
124 output.append("<span class=\"strong\">" +
125 configuration.
126 getText("doclet.Deprecated") + "</span> ");
127 }
128 }
129 }
130 return new TagletOutputImpl(output.toString());
131 }
133 /**
134 * {@inheritDoc}
135 */
136 protected TagletOutput expertTagOutput(Tag tag) {
137 HtmlTree result = new HtmlTree(HtmlTag.SUB, new StringContent(tag.text()));
138 result.addAttr(HtmlAttr.ID, "expert");
139 return new TagletOutputImpl(result.toString());
140 }
142 /**
143 * {@inheritDoc}
144 */
145 protected TagletOutput literalTagOutput(Tag tag) {
146 Content result = new StringContent(tag.text());
147 return new TagletOutputImpl(result.toString());
148 }
150 /**
151 * {@inheritDoc}
152 */
153 public MessageRetriever getMsgRetriever() {
154 return configuration.message;
155 }
157 /**
158 * {@inheritDoc}
159 */
160 public TagletOutput getParamHeader(String header) {
161 StringBuilder result = new StringBuilder();
162 result.append("<dt>");
163 result.append("<span class=\"strong\">").append(header).append("</span></dt>");
164 return new TagletOutputImpl(result.toString());
165 }
167 /**
168 * {@inheritDoc}
169 */
170 public TagletOutput paramTagOutput(ParamTag paramTag, String paramName) {
171 TagletOutput result = new TagletOutputImpl("<dd><code>" + paramName + "</code>"
172 + " - " + htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false) + "</dd>");
173 return result;
174 }
176 /**
177 * {@inheritDoc}
178 */
179 public TagletOutput returnTagOutput(Tag returnTag) {
180 TagletOutput result = new TagletOutputImpl(DocletConstants.NL + "<dt>" +
181 "<span class=\"strong\">" + configuration.getText("doclet.Returns") +
182 "</span>" + "</dt>" + "<dd>" +
183 htmlWriter.commentTagsToString(returnTag, null, returnTag.inlineTags(),
184 false) + "</dd>");
185 return result;
186 }
188 /**
189 * {@inheritDoc}
190 */
191 public TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags) {
192 String result = "";
193 if (seeTags.length > 0) {
194 result = addSeeHeader(result);
195 for (int i = 0; i < seeTags.length; ++i) {
196 if (i > 0) {
197 result += ", " + DocletConstants.NL;
198 }
199 result += htmlWriter.seeTagToString(seeTags[i]);
200 }
201 }
202 if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
203 htmlWriter instanceof ClassWriterImpl) {
204 //Automatically add link to constant values page for constant fields.
205 result = addSeeHeader(result);
206 DocPath constantsPath =
207 htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES);
208 String whichConstant =
209 ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name();
210 DocLink link = constantsPath.fragment(whichConstant);
211 result += htmlWriter.getHyperLinkString(link,
212 configuration.getText("doclet.Constants_Summary"));
213 }
214 if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
215 //Automatically add link to serialized form page for serializable classes.
216 if ((SerializedFormBuilder.serialInclude(holder) &&
217 SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) {
218 result = addSeeHeader(result);
219 DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM);
220 DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName());
221 result += htmlWriter.getHyperLinkString(link,
222 configuration.getText("doclet.Serialized_Form"));
223 }
224 }
225 return result.equals("") ? null : new TagletOutputImpl(result + "</dd>");
226 }
228 private String addSeeHeader(String result) {
229 if (result != null && result.length() > 0) {
230 return result + ", " + DocletConstants.NL;
231 } else {
232 return "<dt><span class=\"strong\">" +
233 configuration.getText("doclet.See_Also") + "</span></dt><dd>";
234 }
235 }
237 /**
238 * {@inheritDoc}
239 */
240 public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) {
241 String result = "<dt><span class=\"strong\">" + header + "</span></dt>" + DocletConstants.NL +
242 " <dd>";
243 for (int i = 0; i < simpleTags.length; i++) {
244 if (i > 0) {
245 result += ", ";
246 }
247 result += htmlWriter.commentTagsToString(simpleTags[i], null, simpleTags[i].inlineTags(), false);
248 }
249 result += "</dd>" + DocletConstants.NL;
250 return new TagletOutputImpl(result);
251 }
253 /**
254 * {@inheritDoc}
255 */
256 public TagletOutput simpleTagOutput(Tag simpleTag, String header) {
257 return new TagletOutputImpl("<dt><span class=\"strong\">" + header + "</span></dt>" + " <dd>"
258 + htmlWriter.commentTagsToString(simpleTag, null, simpleTag.inlineTags(), false)
259 + "</dd>" + DocletConstants.NL);
260 }
262 /**
263 * {@inheritDoc}
264 */
265 public TagletOutput getThrowsHeader() {
266 return new TagletOutputImpl(DocletConstants.NL + "<dt>" + "<span class=\"strong\">" +
267 configuration.getText("doclet.Throws") + "</span></dt>");
268 }
270 /**
271 * {@inheritDoc}
272 */
273 public TagletOutput throwsTagOutput(ThrowsTag throwsTag) {
274 String result = DocletConstants.NL + "<dd>";
275 result += throwsTag.exceptionType() == null ?
276 htmlWriter.codeText(throwsTag.exceptionName()) :
277 htmlWriter.codeText(
278 htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER,
279 throwsTag.exceptionType())).toString());
280 TagletOutput text = new TagletOutputImpl(
281 htmlWriter.commentTagsToString(throwsTag, null,
282 throwsTag.inlineTags(), false));
283 if (text != null && text.toString().length() > 0) {
284 result += " - " + text;
285 }
286 result += "</dd>";
287 return new TagletOutputImpl(result);
288 }
290 /**
291 * {@inheritDoc}
292 */
293 public TagletOutput throwsTagOutput(Type throwsType) {
294 return new TagletOutputImpl(DocletConstants.NL + "<dd>" +
295 htmlWriter.codeText(htmlWriter.getLink(
296 new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType)).toString()) + "</dd>");
297 }
299 /**
300 * {@inheritDoc}
301 */
302 public TagletOutput valueTagOutput(FieldDoc field, String constantVal,
303 boolean includeLink) {
304 return new TagletOutputImpl(includeLink ?
305 htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field,
306 constantVal, false).toString() : constantVal);
307 }
309 /**
310 * {@inheritDoc}
311 */
312 public TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags) {
313 return commentTagsToOutput(holderTag, null, tags, false);
314 }
316 /**
317 * {@inheritDoc}
318 */
319 public TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags) {
320 return commentTagsToOutput(null, holderDoc, tags, false);
321 }
323 /**
324 * {@inheritDoc}
325 */
326 public TagletOutput commentTagsToOutput(Tag holderTag,
327 Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
328 return new TagletOutputImpl(htmlWriter.commentTagsToString(
329 holderTag, holderDoc, tags, isFirstSentence));
330 }
332 /**
333 * {@inheritDoc}
334 */
335 public Configuration configuration() {
336 return configuration;
337 }
339 /**
340 * Return an instance of a TagletWriter that knows how to write HTML.
341 *
342 * @return an instance of a TagletWriter that knows how to write HTML.
343 */
344 public TagletOutput getTagletOutputInstance() {
345 return new TagletOutputImpl("");
346 }
347 }