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

Wed, 31 Oct 2012 13:48:15 -0700

author
jjg
date
Wed, 31 Oct 2012 13:48:15 -0700
changeset 1383
b980e8e6aabf
parent 1359
25e14ad23cef
child 1410
bfec2a1cc869
permissions
-rw-r--r--

8001664: refactor javadoc to use abstraction to handle files
Reviewed-by: darcy

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

mercurial