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

Thu, 15 Nov 2012 09:18:36 -0800

author
jjg
date
Thu, 15 Nov 2012 09:18:36 -0800
changeset 1410
bfec2a1cc869
parent 1373
4a1c57a1c410
child 1735
8ea30d59ac41
permissions
-rw-r--r--

8000800: javadoc uses static non-final fields
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
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@1410 183 configuration.getText("doclet.Constants_Summary"),
jjg@1373 184 false);
duke@1 185 }
duke@1 186 if (holder.isClass() && ((ClassDoc)holder).isSerializable()) {
duke@1 187 //Automatically add link to serialized form page for serializable classes.
bpatel@233 188 if ((SerializedFormBuilder.serialInclude(holder) &&
duke@1 189 SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) {
bpatel@233 190 result = addSeeHeader(result);
jjg@1373 191 DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM);
jjg@1373 192 DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName());
jjg@1373 193 result += htmlWriter.getHyperLinkString(link,
jjg@1410 194 configuration.getText("doclet.Serialized_Form"), false);
duke@1 195 }
duke@1 196 }
bpatel@766 197 return result.equals("") ? null : new TagletOutputImpl(result + "</dd>");
duke@1 198 }
duke@1 199
duke@1 200 private String addSeeHeader(String result) {
duke@1 201 if (result != null && result.length() > 0) {
duke@1 202 return result + ", " + DocletConstants.NL;
duke@1 203 } else {
bpatel@766 204 return "<dt><span class=\"strong\">" +
jjg@1410 205 configuration.getText("doclet.See_Also") + "</span></dt><dd>";
duke@1 206 }
duke@1 207 }
duke@1 208
duke@1 209 /**
duke@1 210 * {@inheritDoc}
duke@1 211 */
duke@1 212 public TagletOutput simpleTagOutput(Tag[] simpleTags, String header) {
bpatel@766 213 String result = "<dt><span class=\"strong\">" + header + "</span></dt>" + DocletConstants.NL +
bpatel@766 214 " <dd>";
duke@1 215 for (int i = 0; i < simpleTags.length; i++) {
duke@1 216 if (i > 0) {
duke@1 217 result += ", ";
duke@1 218 }
duke@1 219 result += htmlWriter.commentTagsToString(simpleTags[i], null, simpleTags[i].inlineTags(), false);
duke@1 220 }
bpatel@766 221 result += "</dd>" + DocletConstants.NL;
bpatel@233 222 return new TagletOutputImpl(result);
duke@1 223 }
duke@1 224
duke@1 225 /**
duke@1 226 * {@inheritDoc}
duke@1 227 */
duke@1 228 public TagletOutput simpleTagOutput(Tag simpleTag, String header) {
bpatel@766 229 return new TagletOutputImpl("<dt><span class=\"strong\">" + header + "</span></dt>" + " <dd>"
duke@1 230 + htmlWriter.commentTagsToString(simpleTag, null, simpleTag.inlineTags(), false)
bpatel@766 231 + "</dd>" + DocletConstants.NL);
duke@1 232 }
duke@1 233
duke@1 234 /**
duke@1 235 * {@inheritDoc}
duke@1 236 */
duke@1 237 public TagletOutput getThrowsHeader() {
bpatel@766 238 return new TagletOutputImpl(DocletConstants.NL + "<dt>" + "<span class=\"strong\">" +
jjg@1410 239 configuration.getText("doclet.Throws") + "</span></dt>");
duke@1 240 }
duke@1 241
duke@1 242 /**
duke@1 243 * {@inheritDoc}
duke@1 244 */
duke@1 245 public TagletOutput throwsTagOutput(ThrowsTag throwsTag) {
bpatel@766 246 String result = DocletConstants.NL + "<dd>";
duke@1 247 result += throwsTag.exceptionType() == null ?
duke@1 248 htmlWriter.codeText(throwsTag.exceptionName()) :
duke@1 249 htmlWriter.codeText(
jjg@1410 250 htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.CONTEXT_MEMBER,
duke@1 251 throwsTag.exceptionType())));
duke@1 252 TagletOutput text = new TagletOutputImpl(
duke@1 253 htmlWriter.commentTagsToString(throwsTag, null,
duke@1 254 throwsTag.inlineTags(), false));
duke@1 255 if (text != null && text.toString().length() > 0) {
duke@1 256 result += " - " + text;
duke@1 257 }
bpatel@766 258 result += "</dd>";
duke@1 259 return new TagletOutputImpl(result);
duke@1 260 }
duke@1 261
duke@1 262 /**
duke@1 263 * {@inheritDoc}
duke@1 264 */
duke@1 265 public TagletOutput throwsTagOutput(Type throwsType) {
bpatel@766 266 return new TagletOutputImpl(DocletConstants.NL + "<dd>" +
duke@1 267 htmlWriter.codeText(htmlWriter.getLink(
jjg@1410 268 new LinkInfoImpl(configuration, LinkInfoImpl.CONTEXT_MEMBER, throwsType))) + "</dd>");
duke@1 269 }
duke@1 270
duke@1 271 /**
duke@1 272 * {@inheritDoc}
duke@1 273 */
duke@1 274 public TagletOutput valueTagOutput(FieldDoc field, String constantVal,
duke@1 275 boolean includeLink) {
duke@1 276 return new TagletOutputImpl(includeLink ?
duke@1 277 htmlWriter.getDocLink(LinkInfoImpl.CONTEXT_VALUE_TAG, field,
duke@1 278 constantVal, false) : constantVal);
duke@1 279 }
duke@1 280
duke@1 281 /**
duke@1 282 * {@inheritDoc}
duke@1 283 */
duke@1 284 public TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags) {
duke@1 285 return commentTagsToOutput(holderTag, null, tags, false);
duke@1 286 }
duke@1 287
duke@1 288 /**
duke@1 289 * {@inheritDoc}
duke@1 290 */
duke@1 291 public TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags) {
duke@1 292 return commentTagsToOutput(null, holderDoc, tags, false);
duke@1 293 }
duke@1 294
duke@1 295 /**
duke@1 296 * {@inheritDoc}
duke@1 297 */
duke@1 298 public TagletOutput commentTagsToOutput(Tag holderTag,
duke@1 299 Doc holderDoc, Tag[] tags, boolean isFirstSentence) {
duke@1 300 return new TagletOutputImpl(htmlWriter.commentTagsToString(
duke@1 301 holderTag, holderDoc, tags, isFirstSentence));
duke@1 302 }
duke@1 303
duke@1 304 /**
duke@1 305 * {@inheritDoc}
duke@1 306 */
duke@1 307 public Configuration configuration() {
jjg@1410 308 return configuration;
duke@1 309 }
duke@1 310
duke@1 311 /**
duke@1 312 * Return an instance of a TagletWriter that knows how to write HTML.
duke@1 313 *
duke@1 314 * @return an instance of a TagletWriter that knows how to write HTML.
duke@1 315 */
duke@1 316 public TagletOutput getTagletOutputInstance() {
duke@1 317 return new TagletOutputImpl("");
duke@1 318 }
duke@1 319 }

mercurial