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

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

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

mercurial