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