src/share/classes/com/sun/tools/doclets/formats/html/TagletWriterImpl.java

Tue, 14 May 2013 10:14:54 -0700

author
jjg
date
Tue, 14 May 2013 10:14:54 -0700
changeset 1743
6a5288a298fd
parent 1742
7af0fa419a2b
child 1744
76a691e3e961
permissions
-rw-r--r--

8012175: Convert TagletOutputImpl to use ContentBuilder instead of StringBuilder
Reviewed-by: darcy

duke@1 1 /*
jjg@1735 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.doclets.formats.html;
duke@1 27
bpatel@233 28 import com.sun.javadoc.*;
jjg@1743 29 import com.sun.tools.doclets.formats.html.markup.ContentBuilder;
jjg@1742 30 import com.sun.tools.doclets.formats.html.markup.HtmlAttr;
jjg@1743 31 import com.sun.tools.doclets.formats.html.markup.HtmlStyle;
jjg@1742 32 import com.sun.tools.doclets.formats.html.markup.HtmlTag;
jjg@1742 33 import com.sun.tools.doclets.formats.html.markup.HtmlTree;
jjg@1743 34 import com.sun.tools.doclets.formats.html.markup.RawHtml;
jjg@1742 35 import com.sun.tools.doclets.formats.html.markup.StringContent;
duke@1 36 import com.sun.tools.doclets.internal.toolkit.*;
duke@1 37 import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder;
duke@1 38 import com.sun.tools.doclets.internal.toolkit.taglets.*;
duke@1 39 import com.sun.tools.doclets.internal.toolkit.util.*;
duke@1 40
duke@1 41 /**
duke@1 42 * The taglet writer that writes HTML.
duke@1 43 *
jjg@1359 44 * <p><b>This is NOT part of any supported API.
jjg@1359 45 * If you write code that depends on this, you do so at your own risk.
jjg@1359 46 * This code and its internal interfaces are subject to change or
jjg@1359 47 * deletion without notice.</b>
jjg@1359 48 *
duke@1 49 * @since 1.5
duke@1 50 * @author Jamie Ho
bpatel@233 51 * @author Bhavesh Patel (Modified)
duke@1 52 */
duke@1 53
duke@1 54 public class TagletWriterImpl extends TagletWriter {
duke@1 55
jjg@1410 56 private final HtmlDocletWriter htmlWriter;
jjg@1410 57 private final ConfigurationImpl configuration;
duke@1 58
duke@1 59 public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) {
jjg@1410 60 super(isFirstSentence);
duke@1 61 this.htmlWriter = htmlWriter;
jjg@1410 62 configuration = htmlWriter.configuration;
duke@1 63 }
duke@1 64
duke@1 65 /**
duke@1 66 * {@inheritDoc}
duke@1 67 */
duke@1 68 public TagletOutput getOutputInstance() {
jjg@1743 69 return new TagletOutputImpl();
duke@1 70 }
duke@1 71
duke@1 72 /**
duke@1 73 * {@inheritDoc}
duke@1 74 */
jjg@1742 75 protected TagletOutput codeTagOutput(Tag tag) {
jjg@1742 76 Content result = HtmlTree.CODE(new StringContent(tag.text()));
jjg@1743 77 return new TagletOutputImpl(result);
jjg@1742 78 }
jjg@1742 79
jjg@1742 80 /**
jjg@1742 81 * {@inheritDoc}
jjg@1742 82 */
duke@1 83 public TagletOutput getDocRootOutput() {
jjg@1410 84 if (configuration.docrootparent.length() > 0)
jjg@1410 85 return new TagletOutputImpl(configuration.docrootparent);
jjg@1372 86 else if (htmlWriter.pathToRoot.isEmpty())
jjg@1372 87 return new TagletOutputImpl(".");
bpatel@997 88 else
jjg@1372 89 return new TagletOutputImpl(htmlWriter.pathToRoot.getPath());
duke@1 90 }
duke@1 91
duke@1 92 /**
duke@1 93 * {@inheritDoc}
duke@1 94 */
duke@1 95 public TagletOutput deprecatedTagOutput(Doc doc) {
jjg@1743 96 ContentBuilder result = new ContentBuilder();
duke@1 97 Tag[] deprs = doc.tags("deprecated");
duke@1 98 if (doc instanceof ClassDoc) {
duke@1 99 if (Util.isDeprecated((ProgramElementDoc) doc)) {
jjg@1743 100 result.addContent(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 101 new StringContent(configuration.getText("doclet.Deprecated"))));
jjg@1743 102 result.addContent(RawHtml.nbsp);
duke@1 103 if (deprs.length > 0) {
duke@1 104 Tag[] commentTags = deprs[0].inlineTags();
duke@1 105 if (commentTags.length > 0) {
jjg@1743 106 result.addContent(commentTagsToOutput(null, doc,
duke@1 107 deprs[0].inlineTags(), false).toString()
duke@1 108 );
duke@1 109 }
duke@1 110 }
duke@1 111 }
duke@1 112 } else {
duke@1 113 MemberDoc member = (MemberDoc) doc;
duke@1 114 if (Util.isDeprecated((ProgramElementDoc) doc)) {
jjg@1743 115 result.addContent(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 116 new StringContent(configuration.getText("doclet.Deprecated"))));
jjg@1743 117 result.addContent(RawHtml.nbsp);
duke@1 118 if (deprs.length > 0) {
jjg@1743 119 TagletOutput body = commentTagsToOutput(null, doc,
jjg@1743 120 deprs[0].inlineTags(), false);
jjg@1743 121 result.addContent(HtmlTree.I(new RawHtml(body.toString())));
duke@1 122 }
duke@1 123 } else {
duke@1 124 if (Util.isDeprecated(member.containingClass())) {
jjg@1743 125 result.addContent(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 126 new StringContent(configuration.getText("doclet.Deprecated"))));
jjg@1743 127 result.addContent(RawHtml.nbsp);
duke@1 128 }
duke@1 129 }
duke@1 130 }
jjg@1743 131 return new TagletOutputImpl(result);
duke@1 132 }
duke@1 133
duke@1 134 /**
duke@1 135 * {@inheritDoc}
duke@1 136 */
jjg@1742 137 protected TagletOutput expertTagOutput(Tag tag) {
jjg@1742 138 HtmlTree result = new HtmlTree(HtmlTag.SUB, new StringContent(tag.text()));
jjg@1742 139 result.addAttr(HtmlAttr.ID, "expert");
jjg@1743 140 return new TagletOutputImpl(result);
jjg@1742 141 }
jjg@1742 142
jjg@1742 143 /**
jjg@1742 144 * {@inheritDoc}
jjg@1742 145 */
jjg@1742 146 protected TagletOutput literalTagOutput(Tag tag) {
jjg@1742 147 Content result = new StringContent(tag.text());
jjg@1743 148 return new TagletOutputImpl(result);
jjg@1742 149 }
jjg@1742 150
jjg@1742 151 /**
jjg@1742 152 * {@inheritDoc}
jjg@1742 153 */
duke@1 154 public MessageRetriever getMsgRetriever() {
jjg@1410 155 return configuration.message;
duke@1 156 }
duke@1 157
duke@1 158 /**
duke@1 159 * {@inheritDoc}
duke@1 160 */
duke@1 161 public TagletOutput getParamHeader(String header) {
jjg@1743 162 HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 163 new StringContent(header)));
jjg@1743 164 return new TagletOutputImpl(result);
duke@1 165 }
duke@1 166
duke@1 167 /**
duke@1 168 * {@inheritDoc}
duke@1 169 */
duke@1 170 public TagletOutput paramTagOutput(ParamTag paramTag, String paramName) {
jjg@1743 171 ContentBuilder body = new ContentBuilder();
jjg@1743 172 body.addContent(HtmlTree.CODE(new RawHtml(paramName)));
jjg@1743 173 body.addContent(" - ");
jjg@1743 174 body.addContent(new RawHtml(htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false)));
jjg@1743 175 HtmlTree result = HtmlTree.DD(body);
jjg@1743 176 return new TagletOutputImpl(result);
duke@1 177 }
duke@1 178
duke@1 179 /**
duke@1 180 * {@inheritDoc}
duke@1 181 */
duke@1 182 public TagletOutput returnTagOutput(Tag returnTag) {
jjg@1743 183 ContentBuilder result = new ContentBuilder();
jjg@1743 184 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 185 new StringContent(configuration.getText("doclet.Returns")))));
jjg@1743 186 result.addContent(HtmlTree.DD(new RawHtml(htmlWriter.commentTagsToString(
jjg@1743 187 returnTag, null, returnTag.inlineTags(), false))));
jjg@1743 188 return new TagletOutputImpl(result);
duke@1 189 }
duke@1 190
duke@1 191 /**
duke@1 192 * {@inheritDoc}
duke@1 193 */
duke@1 194 public TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags) {
jjg@1743 195 ContentBuilder body = new ContentBuilder();
duke@1 196 if (seeTags.length > 0) {
duke@1 197 for (int i = 0; i < seeTags.length; ++i) {
jjg@1743 198 appendSeparatorIfNotEmpty(body);
jjg@1743 199 body.addContent(new RawHtml(htmlWriter.seeTagToString(seeTags[i])));
duke@1 200 }
duke@1 201 }
duke@1 202 if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
duke@1 203 htmlWriter instanceof ClassWriterImpl) {
duke@1 204 //Automatically add link to constant values page for constant fields.
jjg@1743 205 appendSeparatorIfNotEmpty(body);
jjg@1373 206 DocPath constantsPath =
jjg@1373 207 htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES);
jjg@1373 208 String whichConstant =
jjg@1373 209 ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name();
jjg@1373 210 DocLink link = constantsPath.fragment(whichConstant);
jjg@1743 211 body.addContent(htmlWriter.getHyperLink(link,
jjg@1743 212 new StringContent(configuration.getText("doclet.Constants_Summary"))));
duke@1 213 }
duke@1 214 if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
duke@1 215 //Automatically add link to serialized form page for serializable classes.
bpatel@233 216 if ((SerializedFormBuilder.serialInclude(holder) &&
duke@1 217 SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) {
jjg@1743 218 appendSeparatorIfNotEmpty(body);
jjg@1373 219 DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM);
jjg@1373 220 DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName());
jjg@1743 221 body.addContent(htmlWriter.getHyperLink(link,
jjg@1743 222 new StringContent(configuration.getText("doclet.Serialized_Form"))));
duke@1 223 }
duke@1 224 }
jjg@1743 225 if (body.isEmpty())
jjg@1743 226 return new TagletOutputImpl(body);
jjg@1743 227
jjg@1743 228 ContentBuilder result = new ContentBuilder();
jjg@1743 229 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 230 new StringContent(configuration.getText("doclet.See_Also")))));
jjg@1743 231 result.addContent(HtmlTree.DD(body));
jjg@1743 232 return new TagletOutputImpl(result);
jjg@1743 233
duke@1 234 }
duke@1 235
jjg@1743 236 private void appendSeparatorIfNotEmpty(ContentBuilder body) {
jjg@1743 237 if (!body.isEmpty()) {
jjg@1743 238 body.addContent(", ");
jjg@1743 239 body.addContent(DocletConstants.NL);
duke@1 240 }
jjg@1743 241 }
duke@1 242
duke@1 243 /**
duke@1 244 * {@inheritDoc}
duke@1 245 */
duke@1 246 public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) {
jjg@1743 247 ContentBuilder result = new ContentBuilder();
jjg@1743 248 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header))));
jjg@1743 249 ContentBuilder body = new ContentBuilder();
duke@1 250 for (int i = 0; i < simpleTags.length; i++) {
duke@1 251 if (i > 0) {
jjg@1743 252 body.addContent(", ");
duke@1 253 }
jjg@1743 254 body.addContent(new RawHtml(htmlWriter.commentTagsToString(
jjg@1743 255 simpleTags[i], null, simpleTags[i].inlineTags(), false)));
duke@1 256 }
jjg@1743 257 result.addContent(HtmlTree.DD(body));
bpatel@233 258 return new TagletOutputImpl(result);
duke@1 259 }
duke@1 260
duke@1 261 /**
duke@1 262 * {@inheritDoc}
duke@1 263 */
duke@1 264 public TagletOutput simpleTagOutput(Tag simpleTag, String header) {
jjg@1743 265 ContentBuilder result = new ContentBuilder();
jjg@1743 266 result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong, new RawHtml(header))));
jjg@1743 267 Content body = new RawHtml(htmlWriter.commentTagsToString(
jjg@1743 268 simpleTag, null, simpleTag.inlineTags(), false));
jjg@1743 269 result.addContent(HtmlTree.DD(body));
jjg@1743 270 return new TagletOutputImpl(result);
duke@1 271 }
duke@1 272
duke@1 273 /**
duke@1 274 * {@inheritDoc}
duke@1 275 */
duke@1 276 public TagletOutput getThrowsHeader() {
jjg@1743 277 HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.strong,
jjg@1743 278 new StringContent(configuration.getText("doclet.Throws"))));
jjg@1743 279 return new TagletOutputImpl(result);
duke@1 280 }
duke@1 281
duke@1 282 /**
duke@1 283 * {@inheritDoc}
duke@1 284 */
duke@1 285 public TagletOutput throwsTagOutput(ThrowsTag throwsTag) {
jjg@1743 286 ContentBuilder body = new ContentBuilder();
jjg@1743 287 Content excName = (throwsTag.exceptionType() == null) ?
jjg@1743 288 new RawHtml(throwsTag.exceptionName()) :
jjg@1735 289 htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER,
jjg@1743 290 throwsTag.exceptionType()));
jjg@1743 291 body.addContent(HtmlTree.CODE(excName));
jjg@1743 292 String desc = htmlWriter.commentTagsToString(throwsTag, null,
jjg@1743 293 throwsTag.inlineTags(), false);
jjg@1743 294 if (desc != null && !desc.isEmpty()) {
jjg@1743 295 body.addContent(" - ");
jjg@1743 296 body.addContent(new RawHtml(desc));
duke@1 297 }
jjg@1743 298 HtmlTree res2 = HtmlTree.DD(body);
jjg@1743 299 return new TagletOutputImpl(res2);
duke@1 300 }
duke@1 301
duke@1 302 /**
duke@1 303 * {@inheritDoc}
duke@1 304 */
duke@1 305 public TagletOutput throwsTagOutput(Type throwsType) {
jjg@1743 306 HtmlTree result = HtmlTree.DD(HtmlTree.CODE(htmlWriter.getLink(
jjg@1743 307 new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType))));
jjg@1743 308 return new TagletOutputImpl(result);
duke@1 309 }
duke@1 310
duke@1 311 /**
duke@1 312 * {@inheritDoc}
duke@1 313 */
duke@1 314 public TagletOutput valueTagOutput(FieldDoc field, String constantVal,
duke@1 315 boolean includeLink) {
duke@1 316 return new TagletOutputImpl(includeLink ?
jjg@1735 317 htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field,
jjg@1743 318 constantVal, false) : new RawHtml(constantVal));
duke@1 319 }
duke@1 320
duke@1 321 /**
duke@1 322 * {@inheritDoc}
duke@1 323 */
duke@1 324 public TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags) {
duke@1 325 return commentTagsToOutput(holderTag, null, tags, false);
duke@1 326 }
duke@1 327
duke@1 328 /**
duke@1 329 * {@inheritDoc}
duke@1 330 */
duke@1 331 public TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags) {
duke@1 332 return commentTagsToOutput(null, holderDoc, tags, false);
duke@1 333 }
duke@1 334
duke@1 335 /**
duke@1 336 * {@inheritDoc}
duke@1 337 */
duke@1 338 public TagletOutput commentTagsToOutput(Tag holderTag,
duke@1 339 Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
jjg@1743 340 return new TagletOutputImpl(new RawHtml(htmlWriter.commentTagsToString(
jjg@1743 341 holderTag, holderDoc, tags, isFirstSentence)));
duke@1 342 }
duke@1 343
duke@1 344 /**
duke@1 345 * {@inheritDoc}
duke@1 346 */
duke@1 347 public Configuration configuration() {
jjg@1410 348 return configuration;
duke@1 349 }
duke@1 350 }

mercurial