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

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

author
jjg
date
Tue, 14 May 2013 10:14:52 -0700
changeset 1737
7a9ef837e57f
parent 1736
74cd21f2c2fe
child 1742
7af0fa419a2b
permissions
-rw-r--r--

8011650: reduce use of RawHtml nodes in doclet
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.*;
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
jjg@1410 49 private final HtmlDocletWriter htmlWriter;
jjg@1410 50 private final ConfigurationImpl configuration;
duke@1 51
duke@1 52 public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) {
jjg@1410 53 super(isFirstSentence);
duke@1 54 this.htmlWriter = htmlWriter;
jjg@1410 55 configuration = htmlWriter.configuration;
duke@1 56 }
duke@1 57
duke@1 58 /**
duke@1 59 * {@inheritDoc}
duke@1 60 */
duke@1 61 public TagletOutput getOutputInstance() {
duke@1 62 return new TagletOutputImpl("");
duke@1 63 }
duke@1 64
duke@1 65 /**
duke@1 66 * {@inheritDoc}
duke@1 67 */
duke@1 68 public TagletOutput getDocRootOutput() {
jjg@1410 69 if (configuration.docrootparent.length() > 0)
jjg@1410 70 return new TagletOutputImpl(configuration.docrootparent);
jjg@1372 71 else if (htmlWriter.pathToRoot.isEmpty())
jjg@1372 72 return new TagletOutputImpl(".");
bpatel@997 73 else
jjg@1372 74 return new TagletOutputImpl(htmlWriter.pathToRoot.getPath());
duke@1 75 }
duke@1 76
duke@1 77 /**
duke@1 78 * {@inheritDoc}
duke@1 79 */
duke@1 80 public TagletOutput deprecatedTagOutput(Doc doc) {
jjg@1362 81 StringBuilder output = new StringBuilder();
duke@1 82 Tag[] deprs = doc.tags("deprecated");
duke@1 83 if (doc instanceof ClassDoc) {
duke@1 84 if (Util.isDeprecated((ProgramElementDoc) doc)) {
bpatel@766 85 output.append("<span class=\"strong\">" +
jjg@1410 86 configuration.
bpatel@766 87 getText("doclet.Deprecated") + "</span>&nbsp;");
duke@1 88 if (deprs.length > 0) {
duke@1 89 Tag[] commentTags = deprs[0].inlineTags();
duke@1 90 if (commentTags.length > 0) {
duke@1 91
duke@1 92 output.append(commentTagsToOutput(null, doc,
duke@1 93 deprs[0].inlineTags(), false).toString()
duke@1 94 );
duke@1 95 }
duke@1 96 }
duke@1 97 }
duke@1 98 } else {
duke@1 99 MemberDoc member = (MemberDoc) doc;
duke@1 100 if (Util.isDeprecated((ProgramElementDoc) doc)) {
bpatel@766 101 output.append("<span class=\"strong\">" +
jjg@1410 102 configuration.
bpatel@766 103 getText("doclet.Deprecated") + "</span>&nbsp;");
duke@1 104 if (deprs.length > 0) {
bpatel@766 105 output.append("<i>");
duke@1 106 output.append(commentTagsToOutput(null, doc,
duke@1 107 deprs[0].inlineTags(), false).toString());
bpatel@766 108 output.append("</i>");
duke@1 109 }
duke@1 110 } else {
duke@1 111 if (Util.isDeprecated(member.containingClass())) {
bpatel@766 112 output.append("<span class=\"strong\">" +
jjg@1410 113 configuration.
bpatel@766 114 getText("doclet.Deprecated") + "</span>&nbsp;");
duke@1 115 }
duke@1 116 }
duke@1 117 }
duke@1 118 return new TagletOutputImpl(output.toString());
duke@1 119 }
duke@1 120
duke@1 121 /**
duke@1 122 * {@inheritDoc}
duke@1 123 */
duke@1 124 public MessageRetriever getMsgRetriever() {
jjg@1410 125 return configuration.message;
duke@1 126 }
duke@1 127
duke@1 128 /**
duke@1 129 * {@inheritDoc}
duke@1 130 */
duke@1 131 public TagletOutput getParamHeader(String header) {
jjg@1362 132 StringBuilder result = new StringBuilder();
bpatel@766 133 result.append("<dt>");
jjg@1362 134 result.append("<span class=\"strong\">").append(header).append("</span></dt>");
duke@1 135 return new TagletOutputImpl(result.toString());
duke@1 136 }
duke@1 137
duke@1 138 /**
duke@1 139 * {@inheritDoc}
duke@1 140 */
duke@1 141 public TagletOutput paramTagOutput(ParamTag paramTag, String paramName) {
bpatel@766 142 TagletOutput result = new TagletOutputImpl("<dd><code>" + paramName + "</code>"
bpatel@766 143 + " - " + htmlWriter.commentTagsToString(paramTag, null, paramTag.inlineTags(), false) + "</dd>");
duke@1 144 return result;
duke@1 145 }
duke@1 146
duke@1 147 /**
duke@1 148 * {@inheritDoc}
duke@1 149 */
duke@1 150 public TagletOutput returnTagOutput(Tag returnTag) {
bpatel@766 151 TagletOutput result = new TagletOutputImpl(DocletConstants.NL + "<dt>" +
jjg@1410 152 "<span class=\"strong\">" + configuration.getText("doclet.Returns") +
bpatel@766 153 "</span>" + "</dt>" + "<dd>" +
duke@1 154 htmlWriter.commentTagsToString(returnTag, null, returnTag.inlineTags(),
bpatel@766 155 false) + "</dd>");
duke@1 156 return result;
duke@1 157 }
duke@1 158
duke@1 159 /**
duke@1 160 * {@inheritDoc}
duke@1 161 */
duke@1 162 public TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags) {
duke@1 163 String result = "";
duke@1 164 if (seeTags.length > 0) {
duke@1 165 result = addSeeHeader(result);
duke@1 166 for (int i = 0; i < seeTags.length; ++i) {
duke@1 167 if (i > 0) {
duke@1 168 result += ", " + DocletConstants.NL;
duke@1 169 }
duke@1 170 result += htmlWriter.seeTagToString(seeTags[i]);
duke@1 171 }
duke@1 172 }
duke@1 173 if (holder.isField() && ((FieldDoc)holder).constantValue() != null &&
duke@1 174 htmlWriter instanceof ClassWriterImpl) {
duke@1 175 //Automatically add link to constant values page for constant fields.
duke@1 176 result = addSeeHeader(result);
jjg@1373 177 DocPath constantsPath =
jjg@1373 178 htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES);
jjg@1373 179 String whichConstant =
jjg@1373 180 ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name();
jjg@1373 181 DocLink link = constantsPath.fragment(whichConstant);
jjg@1373 182 result += htmlWriter.getHyperLinkString(link,
jjg@1737 183 configuration.getText("doclet.Constants_Summary"));
duke@1 184 }
duke@1 185 if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
duke@1 186 //Automatically add link to serialized form page for serializable classes.
bpatel@233 187 if ((SerializedFormBuilder.serialInclude(holder) &&
duke@1 188 SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) {
bpatel@233 189 result = addSeeHeader(result);
jjg@1373 190 DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM);
jjg@1373 191 DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName());
jjg@1373 192 result += htmlWriter.getHyperLinkString(link,
jjg@1737 193 configuration.getText("doclet.Serialized_Form"));
duke@1 194 }
duke@1 195 }
bpatel@766 196 return result.equals("") ? null : new TagletOutputImpl(result + "</dd>");
duke@1 197 }
duke@1 198
duke@1 199 private String addSeeHeader(String result) {
duke@1 200 if (result != null && result.length() > 0) {
duke@1 201 return result + ", " + DocletConstants.NL;
duke@1 202 } else {
bpatel@766 203 return "<dt><span class=\"strong\">" +
jjg@1410 204 configuration.getText("doclet.See_Also") + "</span></dt><dd>";
duke@1 205 }
duke@1 206 }
duke@1 207
duke@1 208 /**
duke@1 209 * {@inheritDoc}
duke@1 210 */
duke@1 211 public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) {
bpatel@766 212 String result = "<dt><span class=\"strong\">" + header + "</span></dt>" + DocletConstants.NL +
bpatel@766 213 " <dd>";
duke@1 214 for (int i = 0; i < simpleTags.length; i++) {
duke@1 215 if (i > 0) {
duke@1 216 result += ", ";
duke@1 217 }
duke@1 218 result += htmlWriter.commentTagsToString(simpleTags[i], null, simpleTags[i].inlineTags(), false);
duke@1 219 }
bpatel@766 220 result += "</dd>" + DocletConstants.NL;
bpatel@233 221 return new TagletOutputImpl(result);
duke@1 222 }
duke@1 223
duke@1 224 /**
duke@1 225 * {@inheritDoc}
duke@1 226 */
duke@1 227 public TagletOutput simpleTagOutput(Tag simpleTag, String header) {
bpatel@766 228 return new TagletOutputImpl("<dt><span class=\"strong\">" + header + "</span></dt>" + " <dd>"
duke@1 229 + htmlWriter.commentTagsToString(simpleTag, null, simpleTag.inlineTags(), false)
bpatel@766 230 + "</dd>" + DocletConstants.NL);
duke@1 231 }
duke@1 232
duke@1 233 /**
duke@1 234 * {@inheritDoc}
duke@1 235 */
duke@1 236 public TagletOutput getThrowsHeader() {
bpatel@766 237 return new TagletOutputImpl(DocletConstants.NL + "<dt>" + "<span class=\"strong\">" +
jjg@1410 238 configuration.getText("doclet.Throws") + "</span></dt>");
duke@1 239 }
duke@1 240
duke@1 241 /**
duke@1 242 * {@inheritDoc}
duke@1 243 */
duke@1 244 public TagletOutput throwsTagOutput(ThrowsTag throwsTag) {
bpatel@766 245 String result = DocletConstants.NL + "<dd>";
duke@1 246 result += throwsTag.exceptionType() == null ?
duke@1 247 htmlWriter.codeText(throwsTag.exceptionName()) :
duke@1 248 htmlWriter.codeText(
jjg@1735 249 htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER,
jjg@1736 250 throwsTag.exceptionType())).toString());
duke@1 251 TagletOutput text = new TagletOutputImpl(
duke@1 252 htmlWriter.commentTagsToString(throwsTag, null,
duke@1 253 throwsTag.inlineTags(), false));
duke@1 254 if (text != null && text.toString().length() > 0) {
duke@1 255 result += " - " + text;
duke@1 256 }
bpatel@766 257 result += "</dd>";
duke@1 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 throwsTagOutput(Type throwsType) {
bpatel@766 265 return new TagletOutputImpl(DocletConstants.NL + "<dd>" +
duke@1 266 htmlWriter.codeText(htmlWriter.getLink(
jjg@1736 267 new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType)).toString()) + "</dd>");
duke@1 268 }
duke@1 269
duke@1 270 /**
duke@1 271 * {@inheritDoc}
duke@1 272 */
duke@1 273 public TagletOutput valueTagOutput(FieldDoc field, String constantVal,
duke@1 274 boolean includeLink) {
duke@1 275 return new TagletOutputImpl(includeLink ?
jjg@1735 276 htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field,
jjg@1736 277 constantVal, false).toString() : constantVal);
duke@1 278 }
duke@1 279
duke@1 280 /**
duke@1 281 * {@inheritDoc}
duke@1 282 */
duke@1 283 public TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags) {
duke@1 284 return commentTagsToOutput(holderTag, null, tags, false);
duke@1 285 }
duke@1 286
duke@1 287 /**
duke@1 288 * {@inheritDoc}
duke@1 289 */
duke@1 290 public TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags) {
duke@1 291 return commentTagsToOutput(null, holderDoc, tags, false);
duke@1 292 }
duke@1 293
duke@1 294 /**
duke@1 295 * {@inheritDoc}
duke@1 296 */
duke@1 297 public TagletOutput commentTagsToOutput(Tag holderTag,
duke@1 298 Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
duke@1 299 return new TagletOutputImpl(htmlWriter.commentTagsToString(
duke@1 300 holderTag, holderDoc, tags, isFirstSentence));
duke@1 301 }
duke@1 302
duke@1 303 /**
duke@1 304 * {@inheritDoc}
duke@1 305 */
duke@1 306 public Configuration configuration() {
jjg@1410 307 return configuration;
duke@1 308 }
duke@1 309
duke@1 310 /**
duke@1 311 * Return an instance of a TagletWriter that knows how to write HTML.
duke@1 312 *
duke@1 313 * @return an instance of a TagletWriter that knows how to write HTML.
duke@1 314 */
duke@1 315 public TagletOutput getTagletOutputInstance() {
duke@1 316 return new TagletOutputImpl("");
duke@1 317 }
duke@1 318 }

mercurial