src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletWriter.java

Tue, 18 Jun 2013 20:56:04 -0700

author
mfang
date
Tue, 18 Jun 2013 20:56:04 -0700
changeset 1841
792c40d5185a
parent 1751
ca8808c88f94
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8015657: jdk8 l10n resource file translation update 3
Reviewed-by: yhuang

duke@1 1 /*
jjg@1606 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.internal.toolkit.taglets;
duke@1 27
jjg@1357 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.util.*;
duke@1 31
duke@1 32 /**
duke@1 33 * The interface for the taglet writer.
duke@1 34 *
jjg@1359 35 * <p><b>This is NOT part of any supported API.
jjg@1359 36 * If you write code that depends on this, you do so at your own risk.
jjg@1359 37 * This code and its internal interfaces are subject to change or
jjg@1359 38 * deletion without notice.</b>
jjg@1359 39 *
duke@1 40 * @since 1.5
duke@1 41 * @author Jamie Ho
duke@1 42 */
duke@1 43
duke@1 44 public abstract class TagletWriter {
duke@1 45
duke@1 46 /**
duke@1 47 * True if we only want to write the first sentence.
duke@1 48 */
jjg@1410 49 protected final boolean isFirstSentence;
jjg@1410 50
jjg@1410 51 protected TagletWriter(boolean isFirstSentence) {
jjg@1410 52 this.isFirstSentence = isFirstSentence;
jjg@1410 53 }
duke@1 54
duke@1 55 /**
jjg@1742 56 * @return an instance of an output object.
duke@1 57 */
jjg@1751 58 public abstract Content getOutputInstance();
duke@1 59
duke@1 60 /**
jjg@1742 61 * Return the output for a {@code...} tag.
jjg@1742 62 *
jjg@1742 63 * @param tag the tag.
jjg@1742 64 * @return the output of the taglet.
jjg@1742 65 */
jjg@1751 66 protected abstract Content codeTagOutput(Tag tag);
jjg@1742 67
jjg@1742 68 /**
duke@1 69 * Returns the output for the DocRoot inline tag.
duke@1 70 * @return the output for the DocRoot inline tag.
duke@1 71 */
jjg@1751 72 protected abstract Content getDocRootOutput();
duke@1 73
duke@1 74 /**
duke@1 75 * Return the deprecated tag output.
duke@1 76 *
duke@1 77 * @param doc the doc to write deprecated documentation for.
duke@1 78 * @return the output of the deprecated tag.
duke@1 79 */
jjg@1751 80 protected abstract Content deprecatedTagOutput(Doc doc);
duke@1 81
duke@1 82 /**
jjg@1742 83 * Return the output for a {@literal...} tag.
jjg@1742 84 *
jjg@1742 85 * @param tag the tag.
jjg@1742 86 * @return the output of the taglet.
jjg@1742 87 */
jjg@1751 88 protected abstract Content literalTagOutput(Tag tag);
jjg@1742 89
jjg@1742 90 /**
duke@1 91 * Returns {@link MessageRetriever} for output purposes.
duke@1 92 *
duke@1 93 * @return {@link MessageRetriever} for output purposes.
duke@1 94 */
duke@1 95 protected abstract MessageRetriever getMsgRetriever();
duke@1 96
duke@1 97 /**
duke@1 98 * Return the header for the param tags.
duke@1 99 *
duke@1 100 * @param header the header to display.
duke@1 101 * @return the header for the param tags.
duke@1 102 */
jjg@1751 103 protected abstract Content getParamHeader(String header);
duke@1 104
duke@1 105 /**
duke@1 106 * Return the output for param tags.
duke@1 107 *
duke@1 108 * @param paramTag the parameter to document.
duke@1 109 * @param paramName the name of the parameter.
duke@1 110 * @return the output of the param tag.
duke@1 111 */
jjg@1751 112 protected abstract Content paramTagOutput(ParamTag paramTag,
duke@1 113 String paramName);
duke@1 114
duke@1 115 /**
jjg@1749 116 * Return the output for property tags.
jjg@1749 117 *
jjg@1749 118 * @param propertyTag the parameter to document.
jjg@1749 119 * @param prefix the text with which to prefix the property name.
jjg@1749 120 * @return the output of the param tag.
jjg@1749 121 */
jjg@1751 122 protected abstract Content propertyTagOutput(Tag propertyTag, String prefix);
jjg@1749 123
jjg@1749 124 /**
duke@1 125 * Return the return tag output.
duke@1 126 *
duke@1 127 * @param returnTag the return tag to output.
duke@1 128 * @return the output of the return tag.
duke@1 129 */
jjg@1751 130 protected abstract Content returnTagOutput(Tag returnTag);
duke@1 131
duke@1 132 /**
duke@1 133 * Return the see tag output.
duke@1 134 *
duke@1 135 * @param seeTags the array of See tags.
duke@1 136 * @return the output of the see tags.
duke@1 137 */
jjg@1751 138 protected abstract Content seeTagOutput(Doc holder, SeeTag[] seeTags);
duke@1 139
duke@1 140 /**
duke@1 141 * Return the output for a simple tag.
duke@1 142 *
duke@1 143 * @param simpleTags the array of simple tags.
duke@1 144 * @return the output of the simple tags.
duke@1 145 */
jjg@1751 146 protected abstract Content simpleTagOutput(Tag[] simpleTags,
duke@1 147 String header);
duke@1 148
duke@1 149 /**
duke@1 150 * Return the output for a simple tag.
duke@1 151 *
duke@1 152 * @param simpleTag the simple tag.
duke@1 153 * @return the output of the simple tag.
duke@1 154 */
jjg@1751 155 protected abstract Content simpleTagOutput(Tag simpleTag, String header);
duke@1 156
duke@1 157 /**
duke@1 158 * Return the header for the throws tag.
duke@1 159 *
duke@1 160 * @return the header for the throws tag.
duke@1 161 */
jjg@1751 162 protected abstract Content getThrowsHeader();
duke@1 163
duke@1 164 /**
duke@1 165 * Return the header for the throws tag.
duke@1 166 *
duke@1 167 * @param throwsTag the throws tag.
duke@1 168 * @return the output of the throws tag.
duke@1 169 */
jjg@1751 170 protected abstract Content throwsTagOutput(ThrowsTag throwsTag);
duke@1 171
duke@1 172 /**
duke@1 173 * Return the output for the throws tag.
duke@1 174 *
duke@1 175 * @param throwsType the throws type.
duke@1 176 * @return the output of the throws type.
duke@1 177 */
jjg@1751 178 protected abstract Content throwsTagOutput(Type throwsType);
duke@1 179
duke@1 180 /**
duke@1 181 * Return the output for the value tag.
duke@1 182 *
duke@1 183 * @param field the constant field that holds the value tag.
duke@1 184 * @param constantVal the constant value to document.
duke@1 185 * @param includeLink true if we should link the constant text to the
duke@1 186 * constant field itself.
duke@1 187 * @return the output of the value tag.
duke@1 188 */
jjg@1751 189 protected abstract Content valueTagOutput(FieldDoc field,
duke@1 190 String constantVal, boolean includeLink);
duke@1 191
duke@1 192 /**
duke@1 193 * Given an output object, append to it the tag documentation for
duke@1 194 * the given member.
duke@1 195 *
duke@1 196 * @param tagletManager the manager that manages the taglets.
duke@1 197 * @param doc the Doc that we are print tags for.
duke@1 198 * @param taglets the taglets to print.
duke@1 199 * @param writer the writer that will generate the output strings.
duke@1 200 * @param output the output buffer to store the output in.
duke@1 201 */
duke@1 202 public static void genTagOuput(TagletManager tagletManager, Doc doc,
jjg@1751 203 Taglet[] taglets, TagletWriter writer, Content output) {
duke@1 204 tagletManager.checkTags(doc, doc.tags(), false);
duke@1 205 tagletManager.checkTags(doc, doc.inlineTags(), true);
jjg@1751 206 Content currentOutput = null;
duke@1 207 for (int i = 0; i < taglets.length; i++) {
jjg@1606 208 currentOutput = null;
duke@1 209 if (doc instanceof ClassDoc && taglets[i] instanceof ParamTaglet) {
duke@1 210 //The type parameters are documented in a special section away
duke@1 211 //from the tag info, so skip here.
duke@1 212 continue;
duke@1 213 }
duke@1 214 if (taglets[i] instanceof DeprecatedTaglet) {
duke@1 215 //Deprecated information is documented "inline", not in tag info
duke@1 216 //section.
duke@1 217 continue;
duke@1 218 }
duke@1 219 try {
duke@1 220 currentOutput = taglets[i].getTagletOutput(doc, writer);
duke@1 221 } catch (IllegalArgumentException e) {
duke@1 222 //The taglet does not take a member as an argument. Let's try
duke@1 223 //a single tag.
duke@1 224 Tag[] tags = doc.tags(taglets[i].getName());
duke@1 225 if (tags.length > 0) {
duke@1 226 currentOutput = taglets[i].getTagletOutput(tags[0], writer);
duke@1 227 }
duke@1 228 }
duke@1 229 if (currentOutput != null) {
duke@1 230 tagletManager.seenCustomTag(taglets[i].getName());
jjg@1751 231 output.addContent(currentOutput);
duke@1 232 }
duke@1 233 }
duke@1 234 }
duke@1 235
duke@1 236 /**
duke@1 237 * Given an inline tag, return its output.
duke@1 238 * @param tagletManager The taglet manager for the current doclet.
duke@1 239 * @param holderTag The tag this holds this inline tag. Null if there
duke@1 240 * is no tag that holds it.
duke@1 241 * @param inlineTag The inline tag to be documented.
duke@1 242 * @param tagletWriter The taglet writer to write the output.
duke@1 243 * @return The output of the inline tag.
duke@1 244 */
jjg@1751 245 public static Content getInlineTagOuput(TagletManager tagletManager,
duke@1 246 Tag holderTag, Tag inlineTag, TagletWriter tagletWriter) {
jjg@1750 247 Taglet[] definedTags = tagletManager.getInlineCustomTaglets();
duke@1 248 //This is a custom inline tag.
duke@1 249 for (int j = 0; j < definedTags.length; j++) {
duke@1 250 if (("@"+definedTags[j].getName()).equals(inlineTag.name())) {
duke@1 251 //Given a name of a seen custom tag, remove it from the
duke@1 252 // set of unseen custom tags.
duke@1 253 tagletManager.seenCustomTag(definedTags[j].getName());
jjg@1751 254 Content output = definedTags[j].getTagletOutput(
duke@1 255 holderTag != null &&
duke@1 256 definedTags[j].getName().equals("inheritDoc") ?
duke@1 257 holderTag : inlineTag, tagletWriter);
duke@1 258 return output;
duke@1 259 }
duke@1 260 }
duke@1 261 return null;
duke@1 262 }
duke@1 263
duke@1 264 /**
duke@1 265 * Converts inline tags and text to TagOutput, expanding the
duke@1 266 * inline tags along the way. Called wherever text can contain
duke@1 267 * an inline tag, such as in comments or in free-form text arguments
duke@1 268 * to non-inline tags.
duke@1 269 *
duke@1 270 * @param holderTag the tag that holds the documentation.
duke@1 271 * @param tags array of text tags and inline tags (often alternating)
duke@1 272 * present in the text of interest for this doc.
jjg@1751 273 * @return the {@link Content} representing the comments.
duke@1 274 */
jjg@1751 275 public abstract Content commentTagsToOutput(Tag holderTag, Tag[] tags);
duke@1 276
duke@1 277 /**
duke@1 278 * Converts inline tags and text to TagOutput, expanding the
duke@1 279 * inline tags along the way. Called wherever text can contain
duke@1 280 * an inline tag, such as in comments or in free-form text arguments
duke@1 281 * to non-inline tags.
duke@1 282 *
duke@1 283 * @param holderDoc specific doc where comment resides.
duke@1 284 * @param tags array of text tags and inline tags (often alternating)
duke@1 285 * present in the text of interest for this doc.
jjg@1751 286 * @return the {@link Content} representing the comments.
duke@1 287 */
jjg@1751 288 public abstract Content commentTagsToOutput(Doc holderDoc, Tag[] tags);
duke@1 289
duke@1 290 /**
duke@1 291 * Converts inline tags and text to TagOutput, expanding the
duke@1 292 * inline tags along the way. Called wherever text can contain
duke@1 293 * an inline tag, such as in comments or in free-form text arguments
duke@1 294 * to non-inline tags.
duke@1 295 *
duke@1 296 * @param holderTag the tag that holds the documentation.
duke@1 297 * @param holderDoc specific doc where comment resides.
duke@1 298 * @param tags array of text tags and inline tags (often alternating)
duke@1 299 * present in the text of interest for this doc.
duke@1 300 * @param isFirstSentence true if this is the first sentence.
jjg@1751 301 * @return the {@link Content} representing the comments.
duke@1 302 */
jjg@1751 303 public abstract Content commentTagsToOutput(Tag holderTag,
duke@1 304 Doc holderDoc, Tag[] tags, boolean isFirstSentence);
duke@1 305
duke@1 306 /**
duke@1 307 * @return an instance of the configuration used for this doclet.
duke@1 308 */
duke@1 309 public abstract Configuration configuration();
duke@1 310 }

mercurial