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

Wed, 10 Oct 2012 18:44:21 -0700

author
jjg
date
Wed, 10 Oct 2012 18:44:21 -0700
changeset 1362
c46e0c9940d6
parent 1359
25e14ad23cef
child 1372
78962d89f283
permissions
-rw-r--r--

8000310: Clean up use of StringBuffer in langtools
Reviewed-by: bpatel

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

mercurial