Tue, 03 Dec 2013 14:21:45 -0800
8025416: doclet not substituting {@docRoot} in some cases
Reviewed-by: jjg
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.*; |
jjg@1743 | 29 | import com.sun.tools.doclets.formats.html.markup.ContentBuilder; |
jjg@1743 | 30 | import com.sun.tools.doclets.formats.html.markup.HtmlStyle; |
jjg@1742 | 31 | import com.sun.tools.doclets.formats.html.markup.HtmlTree; |
jjg@1743 | 32 | import com.sun.tools.doclets.formats.html.markup.RawHtml; |
jjg@1742 | 33 | import com.sun.tools.doclets.formats.html.markup.StringContent; |
duke@1 | 34 | import com.sun.tools.doclets.internal.toolkit.*; |
duke@1 | 35 | import com.sun.tools.doclets.internal.toolkit.builders.SerializedFormBuilder; |
duke@1 | 36 | import com.sun.tools.doclets.internal.toolkit.taglets.*; |
duke@1 | 37 | import com.sun.tools.doclets.internal.toolkit.util.*; |
duke@1 | 38 | |
duke@1 | 39 | /** |
duke@1 | 40 | * The taglet writer that writes HTML. |
duke@1 | 41 | * |
jjg@1359 | 42 | * <p><b>This is NOT part of any supported API. |
jjg@1359 | 43 | * If you write code that depends on this, you do so at your own risk. |
jjg@1359 | 44 | * This code and its internal interfaces are subject to change or |
jjg@1359 | 45 | * deletion without notice.</b> |
jjg@1359 | 46 | * |
duke@1 | 47 | * @since 1.5 |
duke@1 | 48 | * @author Jamie Ho |
bpatel@233 | 49 | * @author Bhavesh Patel (Modified) |
duke@1 | 50 | */ |
duke@1 | 51 | |
duke@1 | 52 | public class TagletWriterImpl extends TagletWriter { |
duke@1 | 53 | |
jjg@1410 | 54 | private final HtmlDocletWriter htmlWriter; |
jjg@1410 | 55 | private final ConfigurationImpl configuration; |
duke@1 | 56 | |
duke@1 | 57 | public TagletWriterImpl(HtmlDocletWriter htmlWriter, boolean isFirstSentence) { |
jjg@1410 | 58 | super(isFirstSentence); |
duke@1 | 59 | this.htmlWriter = htmlWriter; |
jjg@1410 | 60 | configuration = htmlWriter.configuration; |
duke@1 | 61 | } |
duke@1 | 62 | |
duke@1 | 63 | /** |
duke@1 | 64 | * {@inheritDoc} |
duke@1 | 65 | */ |
jjg@1751 | 66 | public Content getOutputInstance() { |
jjg@1751 | 67 | return new ContentBuilder(); |
duke@1 | 68 | } |
duke@1 | 69 | |
duke@1 | 70 | /** |
duke@1 | 71 | * {@inheritDoc} |
duke@1 | 72 | */ |
jjg@1751 | 73 | protected Content codeTagOutput(Tag tag) { |
jjg@1911 | 74 | Content result = HtmlTree.CODE(new StringContent(Util.normalizeNewlines(tag.text()))); |
jjg@1751 | 75 | return result; |
jjg@1742 | 76 | } |
jjg@1742 | 77 | |
jjg@1742 | 78 | /** |
jjg@1742 | 79 | * {@inheritDoc} |
jjg@1742 | 80 | */ |
jjg@1751 | 81 | public Content getDocRootOutput() { |
jjg@1751 | 82 | String path; |
bpatel@2212 | 83 | if (htmlWriter.pathToRoot.isEmpty()) |
jjg@1751 | 84 | path = "."; |
bpatel@997 | 85 | else |
jjg@1751 | 86 | path = htmlWriter.pathToRoot.getPath(); |
jjg@1751 | 87 | return new StringContent(path); |
duke@1 | 88 | } |
duke@1 | 89 | |
duke@1 | 90 | /** |
duke@1 | 91 | * {@inheritDoc} |
duke@1 | 92 | */ |
jjg@1751 | 93 | public Content deprecatedTagOutput(Doc doc) { |
jjg@1743 | 94 | ContentBuilder result = new ContentBuilder(); |
duke@1 | 95 | Tag[] deprs = doc.tags("deprecated"); |
duke@1 | 96 | if (doc instanceof ClassDoc) { |
duke@1 | 97 | if (Util.isDeprecated((ProgramElementDoc) doc)) { |
bpatel@2147 | 98 | result.addContent(HtmlTree.SPAN(HtmlStyle.deprecatedLabel, |
jjg@1743 | 99 | new StringContent(configuration.getText("doclet.Deprecated")))); |
jjg@1743 | 100 | result.addContent(RawHtml.nbsp); |
duke@1 | 101 | if (deprs.length > 0) { |
duke@1 | 102 | Tag[] commentTags = deprs[0].inlineTags(); |
duke@1 | 103 | if (commentTags.length > 0) { |
jjg@1743 | 104 | result.addContent(commentTagsToOutput(null, doc, |
jjg@1751 | 105 | deprs[0].inlineTags(), false) |
duke@1 | 106 | ); |
duke@1 | 107 | } |
duke@1 | 108 | } |
duke@1 | 109 | } |
duke@1 | 110 | } else { |
duke@1 | 111 | MemberDoc member = (MemberDoc) doc; |
duke@1 | 112 | if (Util.isDeprecated((ProgramElementDoc) doc)) { |
bpatel@2147 | 113 | result.addContent(HtmlTree.SPAN(HtmlStyle.deprecatedLabel, |
jjg@1743 | 114 | new StringContent(configuration.getText("doclet.Deprecated")))); |
jjg@1743 | 115 | result.addContent(RawHtml.nbsp); |
duke@1 | 116 | if (deprs.length > 0) { |
jjg@1751 | 117 | Content body = commentTagsToOutput(null, doc, |
jjg@1743 | 118 | deprs[0].inlineTags(), false); |
bpatel@2116 | 119 | if (!body.isEmpty()) |
bpatel@2147 | 120 | result.addContent(HtmlTree.SPAN(HtmlStyle.deprecationComment, body)); |
duke@1 | 121 | } |
duke@1 | 122 | } else { |
duke@1 | 123 | if (Util.isDeprecated(member.containingClass())) { |
bpatel@2147 | 124 | result.addContent(HtmlTree.SPAN(HtmlStyle.deprecatedLabel, |
jjg@1743 | 125 | new StringContent(configuration.getText("doclet.Deprecated")))); |
jjg@1743 | 126 | result.addContent(RawHtml.nbsp); |
duke@1 | 127 | } |
duke@1 | 128 | } |
duke@1 | 129 | } |
jjg@1751 | 130 | return result; |
duke@1 | 131 | } |
duke@1 | 132 | |
duke@1 | 133 | /** |
duke@1 | 134 | * {@inheritDoc} |
duke@1 | 135 | */ |
jjg@1751 | 136 | protected Content literalTagOutput(Tag tag) { |
jjg@1911 | 137 | Content result = new StringContent(Util.normalizeNewlines(tag.text())); |
jjg@1751 | 138 | return result; |
jjg@1742 | 139 | } |
jjg@1742 | 140 | |
jjg@1742 | 141 | /** |
jjg@1742 | 142 | * {@inheritDoc} |
jjg@1742 | 143 | */ |
duke@1 | 144 | public MessageRetriever getMsgRetriever() { |
jjg@1410 | 145 | return configuration.message; |
duke@1 | 146 | } |
duke@1 | 147 | |
duke@1 | 148 | /** |
duke@1 | 149 | * {@inheritDoc} |
duke@1 | 150 | */ |
jjg@1751 | 151 | public Content getParamHeader(String header) { |
bpatel@2147 | 152 | HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.paramLabel, |
jjg@1743 | 153 | new StringContent(header))); |
jjg@1751 | 154 | return result; |
duke@1 | 155 | } |
duke@1 | 156 | |
duke@1 | 157 | /** |
duke@1 | 158 | * {@inheritDoc} |
duke@1 | 159 | */ |
jjg@1751 | 160 | public Content paramTagOutput(ParamTag paramTag, String paramName) { |
jjg@1743 | 161 | ContentBuilder body = new ContentBuilder(); |
jjg@1743 | 162 | body.addContent(HtmlTree.CODE(new RawHtml(paramName))); |
jjg@1743 | 163 | body.addContent(" - "); |
jjg@1745 | 164 | body.addContent(htmlWriter.commentTagsToContent(paramTag, null, paramTag.inlineTags(), false)); |
jjg@1743 | 165 | HtmlTree result = HtmlTree.DD(body); |
jjg@1751 | 166 | return result; |
duke@1 | 167 | } |
duke@1 | 168 | |
duke@1 | 169 | /** |
duke@1 | 170 | * {@inheritDoc} |
duke@1 | 171 | */ |
jjg@1751 | 172 | public Content propertyTagOutput(Tag tag, String prefix) { |
jjg@1749 | 173 | Content body = new ContentBuilder(); |
jjg@1749 | 174 | body.addContent(new RawHtml(prefix)); |
jjg@1749 | 175 | body.addContent(" "); |
jjg@1749 | 176 | body.addContent(HtmlTree.CODE(new RawHtml(tag.text()))); |
jjg@1749 | 177 | body.addContent("."); |
jjg@1749 | 178 | Content result = HtmlTree.P(body); |
jjg@1751 | 179 | return result; |
jjg@1749 | 180 | } |
jjg@1749 | 181 | |
jjg@1749 | 182 | /** |
jjg@1749 | 183 | * {@inheritDoc} |
jjg@1749 | 184 | */ |
jjg@1751 | 185 | public Content returnTagOutput(Tag returnTag) { |
jjg@1743 | 186 | ContentBuilder result = new ContentBuilder(); |
bpatel@2147 | 187 | result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.returnLabel, |
jjg@1743 | 188 | new StringContent(configuration.getText("doclet.Returns"))))); |
jjg@1745 | 189 | result.addContent(HtmlTree.DD(htmlWriter.commentTagsToContent( |
jjg@1745 | 190 | returnTag, null, returnTag.inlineTags(), false))); |
jjg@1751 | 191 | return result; |
duke@1 | 192 | } |
duke@1 | 193 | |
duke@1 | 194 | /** |
duke@1 | 195 | * {@inheritDoc} |
duke@1 | 196 | */ |
jjg@1751 | 197 | public Content seeTagOutput(Doc holder, SeeTag[] seeTags) { |
jjg@1743 | 198 | ContentBuilder body = new ContentBuilder(); |
duke@1 | 199 | if (seeTags.length > 0) { |
duke@1 | 200 | for (int i = 0; i < seeTags.length; ++i) { |
jjg@1743 | 201 | appendSeparatorIfNotEmpty(body); |
jjg@1745 | 202 | body.addContent(htmlWriter.seeTagToContent(seeTags[i])); |
duke@1 | 203 | } |
duke@1 | 204 | } |
duke@1 | 205 | if (holder.isField() && ((FieldDoc)holder).constantValue() != null && |
duke@1 | 206 | htmlWriter instanceof ClassWriterImpl) { |
duke@1 | 207 | //Automatically add link to constant values page for constant fields. |
jjg@1743 | 208 | appendSeparatorIfNotEmpty(body); |
jjg@1373 | 209 | DocPath constantsPath = |
jjg@1373 | 210 | htmlWriter.pathToRoot.resolve(DocPaths.CONSTANT_VALUES); |
jjg@1373 | 211 | String whichConstant = |
jjg@1373 | 212 | ((ClassWriterImpl) htmlWriter).getClassDoc().qualifiedName() + "." + ((FieldDoc) holder).name(); |
jjg@1373 | 213 | DocLink link = constantsPath.fragment(whichConstant); |
jjg@1743 | 214 | body.addContent(htmlWriter.getHyperLink(link, |
jjg@1743 | 215 | new StringContent(configuration.getText("doclet.Constants_Summary")))); |
duke@1 | 216 | } |
duke@1 | 217 | if (holder.isClass() && ((ClassDoc)holder).isSerializable()) { |
duke@1 | 218 | //Automatically add link to serialized form page for serializable classes. |
bpatel@233 | 219 | if ((SerializedFormBuilder.serialInclude(holder) && |
duke@1 | 220 | SerializedFormBuilder.serialInclude(((ClassDoc)holder).containingPackage()))) { |
jjg@1743 | 221 | appendSeparatorIfNotEmpty(body); |
jjg@1373 | 222 | DocPath serialPath = htmlWriter.pathToRoot.resolve(DocPaths.SERIALIZED_FORM); |
jjg@1373 | 223 | DocLink link = serialPath.fragment(((ClassDoc)holder).qualifiedName()); |
jjg@1743 | 224 | body.addContent(htmlWriter.getHyperLink(link, |
jjg@1743 | 225 | new StringContent(configuration.getText("doclet.Serialized_Form")))); |
duke@1 | 226 | } |
duke@1 | 227 | } |
jjg@1743 | 228 | if (body.isEmpty()) |
jjg@1751 | 229 | return body; |
jjg@1743 | 230 | |
jjg@1743 | 231 | ContentBuilder result = new ContentBuilder(); |
bpatel@2147 | 232 | result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.seeLabel, |
jjg@1743 | 233 | new StringContent(configuration.getText("doclet.See_Also"))))); |
jjg@1743 | 234 | result.addContent(HtmlTree.DD(body)); |
jjg@1751 | 235 | return result; |
jjg@1743 | 236 | |
duke@1 | 237 | } |
duke@1 | 238 | |
jjg@1743 | 239 | private void appendSeparatorIfNotEmpty(ContentBuilder body) { |
jjg@1743 | 240 | if (!body.isEmpty()) { |
jjg@1743 | 241 | body.addContent(", "); |
jjg@1743 | 242 | body.addContent(DocletConstants.NL); |
duke@1 | 243 | } |
jjg@1743 | 244 | } |
duke@1 | 245 | |
duke@1 | 246 | /** |
duke@1 | 247 | * {@inheritDoc} |
duke@1 | 248 | */ |
jjg@1751 | 249 | public Content simpleTagOutput(Tag[] simpleTags, String header) { |
jjg@1743 | 250 | ContentBuilder result = new ContentBuilder(); |
bpatel@2147 | 251 | result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.simpleTagLabel, new RawHtml(header)))); |
jjg@1743 | 252 | ContentBuilder body = new ContentBuilder(); |
duke@1 | 253 | for (int i = 0; i < simpleTags.length; i++) { |
duke@1 | 254 | if (i > 0) { |
jjg@1743 | 255 | body.addContent(", "); |
duke@1 | 256 | } |
jjg@1745 | 257 | body.addContent(htmlWriter.commentTagsToContent( |
jjg@1745 | 258 | simpleTags[i], null, simpleTags[i].inlineTags(), false)); |
duke@1 | 259 | } |
jjg@1743 | 260 | result.addContent(HtmlTree.DD(body)); |
jjg@1751 | 261 | return result; |
duke@1 | 262 | } |
duke@1 | 263 | |
duke@1 | 264 | /** |
duke@1 | 265 | * {@inheritDoc} |
duke@1 | 266 | */ |
jjg@1751 | 267 | public Content simpleTagOutput(Tag simpleTag, String header) { |
jjg@1743 | 268 | ContentBuilder result = new ContentBuilder(); |
bpatel@2147 | 269 | result.addContent(HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.simpleTagLabel, new RawHtml(header)))); |
jjg@1745 | 270 | Content body = htmlWriter.commentTagsToContent( |
jjg@1745 | 271 | simpleTag, null, simpleTag.inlineTags(), false); |
jjg@1743 | 272 | result.addContent(HtmlTree.DD(body)); |
jjg@1751 | 273 | return result; |
duke@1 | 274 | } |
duke@1 | 275 | |
duke@1 | 276 | /** |
duke@1 | 277 | * {@inheritDoc} |
duke@1 | 278 | */ |
jjg@1751 | 279 | public Content getThrowsHeader() { |
bpatel@2147 | 280 | HtmlTree result = HtmlTree.DT(HtmlTree.SPAN(HtmlStyle.throwsLabel, |
jjg@1743 | 281 | new StringContent(configuration.getText("doclet.Throws")))); |
jjg@1751 | 282 | return result; |
duke@1 | 283 | } |
duke@1 | 284 | |
duke@1 | 285 | /** |
duke@1 | 286 | * {@inheritDoc} |
duke@1 | 287 | */ |
jjg@1751 | 288 | public Content throwsTagOutput(ThrowsTag throwsTag) { |
jjg@1743 | 289 | ContentBuilder body = new ContentBuilder(); |
jjg@1743 | 290 | Content excName = (throwsTag.exceptionType() == null) ? |
jjg@1743 | 291 | new RawHtml(throwsTag.exceptionName()) : |
jjg@1735 | 292 | htmlWriter.getLink(new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, |
jjg@1743 | 293 | throwsTag.exceptionType())); |
jjg@1743 | 294 | body.addContent(HtmlTree.CODE(excName)); |
jjg@1745 | 295 | Content desc = htmlWriter.commentTagsToContent(throwsTag, null, |
jjg@1743 | 296 | throwsTag.inlineTags(), false); |
jjg@1743 | 297 | if (desc != null && !desc.isEmpty()) { |
jjg@1743 | 298 | body.addContent(" - "); |
jjg@1745 | 299 | body.addContent(desc); |
duke@1 | 300 | } |
jjg@1751 | 301 | HtmlTree result = HtmlTree.DD(body); |
jjg@1751 | 302 | return result; |
duke@1 | 303 | } |
duke@1 | 304 | |
duke@1 | 305 | /** |
duke@1 | 306 | * {@inheritDoc} |
duke@1 | 307 | */ |
jjg@1751 | 308 | public Content throwsTagOutput(Type throwsType) { |
jjg@1743 | 309 | HtmlTree result = HtmlTree.DD(HtmlTree.CODE(htmlWriter.getLink( |
jjg@1743 | 310 | new LinkInfoImpl(configuration, LinkInfoImpl.Kind.MEMBER, throwsType)))); |
jjg@1751 | 311 | return result; |
duke@1 | 312 | } |
duke@1 | 313 | |
duke@1 | 314 | /** |
duke@1 | 315 | * {@inheritDoc} |
duke@1 | 316 | */ |
jjg@1751 | 317 | public Content valueTagOutput(FieldDoc field, String constantVal, |
duke@1 | 318 | boolean includeLink) { |
jjg@1751 | 319 | return includeLink ? |
jjg@1735 | 320 | htmlWriter.getDocLink(LinkInfoImpl.Kind.VALUE_TAG, field, |
jjg@1751 | 321 | constantVal, false) : new RawHtml(constantVal); |
duke@1 | 322 | } |
duke@1 | 323 | |
duke@1 | 324 | /** |
duke@1 | 325 | * {@inheritDoc} |
duke@1 | 326 | */ |
jjg@1751 | 327 | public Content commentTagsToOutput(Tag holderTag, Tag[] tags) { |
duke@1 | 328 | return commentTagsToOutput(holderTag, null, tags, false); |
duke@1 | 329 | } |
duke@1 | 330 | |
duke@1 | 331 | /** |
duke@1 | 332 | * {@inheritDoc} |
duke@1 | 333 | */ |
jjg@1751 | 334 | public Content commentTagsToOutput(Doc holderDoc, Tag[] tags) { |
duke@1 | 335 | return commentTagsToOutput(null, holderDoc, tags, false); |
duke@1 | 336 | } |
duke@1 | 337 | |
duke@1 | 338 | /** |
duke@1 | 339 | * {@inheritDoc} |
duke@1 | 340 | */ |
jjg@1751 | 341 | public Content commentTagsToOutput(Tag holderTag, |
duke@1 | 342 | Doc holderDoc, Tag[] tags, boolean isFirstSentence) { |
jjg@1751 | 343 | return htmlWriter.commentTagsToContent( |
jjg@1751 | 344 | holderTag, holderDoc, tags, isFirstSentence); |
duke@1 | 345 | } |
duke@1 | 346 | |
duke@1 | 347 | /** |
duke@1 | 348 | * {@inheritDoc} |
duke@1 | 349 | */ |
duke@1 | 350 | public Configuration configuration() { |
jjg@1410 | 351 | return configuration; |
duke@1 | 352 | } |
duke@1 | 353 | } |