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

Tue, 23 Oct 2012 13:20:37 -0700

author
jjg
date
Tue, 23 Oct 2012 13:20:37 -0700
changeset 1372
78962d89f283
parent 1362
c46e0c9940d6
child 1373
4a1c57a1c410
permissions
-rw-r--r--

8000741: refactor javadoc to use abstraction to handle relative paths
Reviewed-by: darcy

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

mercurial