001: /*
002: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.doclets.internal.toolkit.taglets;
027:
028: import com.sun.tools.doclets.internal.toolkit.*;
029: import com.sun.tools.doclets.internal.toolkit.util.*;
030: import com.sun.javadoc.*;
031:
032: /**
033: * The interface for the taglet writer.
034: *
035: * @since 1.5
036: * @author Jamie Ho
037: */
038:
039: public abstract class TagletWriter {
040:
041: /**
042: * True if we only want to write the first sentence.
043: */
044: protected boolean isFirstSentence = false;
045:
046: /**
047: * @return an instance of the output object.
048: */
049: public abstract TagletOutput getOutputInstance();
050:
051: /**
052: * Returns the output for the DocRoot inline tag.
053: * @return the output for the DocRoot inline tag.
054: */
055: protected abstract TagletOutput getDocRootOutput();
056:
057: /**
058: * Return the deprecated tag output.
059: *
060: * @param doc the doc to write deprecated documentation for.
061: * @return the output of the deprecated tag.
062: */
063: protected abstract TagletOutput deprecatedTagOutput(Doc doc);
064:
065: /**
066: * Returns {@link MessageRetriever} for output purposes.
067: *
068: * @return {@link MessageRetriever} for output purposes.
069: */
070: protected abstract MessageRetriever getMsgRetriever();
071:
072: /**
073: * Return the header for the param tags.
074: *
075: * @param header the header to display.
076: * @return the header for the param tags.
077: */
078: protected abstract TagletOutput getParamHeader(String header);
079:
080: /**
081: * Return the output for param tags.
082: *
083: * @param paramTag the parameter to document.
084: * @param paramName the name of the parameter.
085: * @return the output of the param tag.
086: */
087: protected abstract TagletOutput paramTagOutput(ParamTag paramTag,
088: String paramName);
089:
090: /**
091: * Return the return tag output.
092: *
093: * @param returnTag the return tag to output.
094: * @return the output of the return tag.
095: */
096: protected abstract TagletOutput returnTagOutput(Tag returnTag);
097:
098: /**
099: * Return the see tag output.
100: *
101: * @param seeTags the array of See tags.
102: * @return the output of the see tags.
103: */
104: protected abstract TagletOutput seeTagOutput(Doc holder,
105: SeeTag[] seeTags);
106:
107: /**
108: * Return the output for a simple tag.
109: *
110: * @param simpleTags the array of simple tags.
111: * @return the output of the simple tags.
112: */
113: protected abstract TagletOutput simpleTagOutput(Tag[] simpleTags,
114: String header);
115:
116: /**
117: * Return the output for a simple tag.
118: *
119: * @param simpleTag the simple tag.
120: * @return the output of the simple tag.
121: */
122: protected abstract TagletOutput simpleTagOutput(Tag simpleTag,
123: String header);
124:
125: /**
126: * Return the header for the throws tag.
127: *
128: * @return the header for the throws tag.
129: */
130: protected abstract TagletOutput getThrowsHeader();
131:
132: /**
133: * Return the header for the throws tag.
134: *
135: * @param throwsTag the throws tag.
136: * @return the output of the throws tag.
137: */
138: protected abstract TagletOutput throwsTagOutput(ThrowsTag throwsTag);
139:
140: /**
141: * Return the output for the throws tag.
142: *
143: * @param throwsType the throws type.
144: * @return the output of the throws type.
145: */
146: protected abstract TagletOutput throwsTagOutput(Type throwsType);
147:
148: /**
149: * Return the output for the value tag.
150: *
151: * @param field the constant field that holds the value tag.
152: * @param constantVal the constant value to document.
153: * @param includeLink true if we should link the constant text to the
154: * constant field itself.
155: * @return the output of the value tag.
156: */
157: protected abstract TagletOutput valueTagOutput(FieldDoc field,
158: String constantVal, boolean includeLink);
159:
160: /**
161: * Given an output object, append to it the tag documentation for
162: * the given member.
163: *
164: * @param tagletManager the manager that manages the taglets.
165: * @param doc the Doc that we are print tags for.
166: * @param taglets the taglets to print.
167: * @param writer the writer that will generate the output strings.
168: * @param output the output buffer to store the output in.
169: */
170: public static void genTagOuput(TagletManager tagletManager,
171: Doc doc, Taglet[] taglets, TagletWriter writer,
172: TagletOutput output) {
173: tagletManager.checkTags(doc, doc.tags(), false);
174: tagletManager.checkTags(doc, doc.inlineTags(), true);
175: TagletOutput currentOutput = null;
176: for (int i = 0; i < taglets.length; i++) {
177: if (doc instanceof ClassDoc
178: && taglets[i] instanceof ParamTaglet) {
179: //The type parameters are documented in a special section away
180: //from the tag info, so skip here.
181: continue;
182: }
183: if (taglets[i] instanceof DeprecatedTaglet) {
184: //Deprecated information is documented "inline", not in tag info
185: //section.
186: continue;
187: }
188: try {
189: currentOutput = taglets[i].getTagletOutput(doc, writer);
190: } catch (IllegalArgumentException e) {
191: //The taglet does not take a member as an argument. Let's try
192: //a single tag.
193: Tag[] tags = doc.tags(taglets[i].getName());
194: if (tags.length > 0) {
195: currentOutput = taglets[i].getTagletOutput(tags[0],
196: writer);
197: }
198: }
199: if (currentOutput != null) {
200: tagletManager.seenCustomTag(taglets[i].getName());
201: output.appendOutput(currentOutput);
202: }
203: }
204: }
205:
206: /**
207: * Given an inline tag, return its output.
208: * @param tagletManager The taglet manager for the current doclet.
209: * @param holderTag The tag this holds this inline tag. Null if there
210: * is no tag that holds it.
211: * @param inlineTag The inline tag to be documented.
212: * @param tagletWriter The taglet writer to write the output.
213: * @return The output of the inline tag.
214: */
215: public static TagletOutput getInlineTagOuput(
216: TagletManager tagletManager, Tag holderTag, Tag inlineTag,
217: TagletWriter tagletWriter) {
218: Taglet[] definedTags = tagletManager.getInlineCustomTags();
219: //This is a custom inline tag.
220: for (int j = 0; j < definedTags.length; j++) {
221: if (("@" + definedTags[j].getName()).equals(inlineTag
222: .name())) {
223: //Given a name of a seen custom tag, remove it from the
224: // set of unseen custom tags.
225: tagletManager.seenCustomTag(definedTags[j].getName());
226: TagletOutput output = definedTags[j].getTagletOutput(
227: holderTag != null
228: && definedTags[j].getName().equals(
229: "inheritDoc") ? holderTag
230: : inlineTag, tagletWriter);
231: return output;
232: }
233: }
234: return null;
235: }
236:
237: /**
238: * Converts inline tags and text to TagOutput, expanding the
239: * inline tags along the way. Called wherever text can contain
240: * an inline tag, such as in comments or in free-form text arguments
241: * to non-inline tags.
242: *
243: * @param holderTag the tag that holds the documentation.
244: * @param tags array of text tags and inline tags (often alternating)
245: * present in the text of interest for this doc.
246: * @return the {@link TagletOutput} representing the comments.
247: */
248: public abstract TagletOutput commentTagsToOutput(Tag holderTag,
249: Tag[] tags);
250:
251: /**
252: * Converts inline tags and text to TagOutput, expanding the
253: * inline tags along the way. Called wherever text can contain
254: * an inline tag, such as in comments or in free-form text arguments
255: * to non-inline tags.
256: *
257: * @param holderDoc specific doc where comment resides.
258: * @param tags array of text tags and inline tags (often alternating)
259: * present in the text of interest for this doc.
260: * @return the {@link TagletOutput} representing the comments.
261: */
262: public abstract TagletOutput commentTagsToOutput(Doc holderDoc,
263: Tag[] tags);
264:
265: /**
266: * Converts inline tags and text to TagOutput, expanding the
267: * inline tags along the way. Called wherever text can contain
268: * an inline tag, such as in comments or in free-form text arguments
269: * to non-inline tags.
270: *
271: * @param holderTag the tag that holds the documentation.
272: * @param holderDoc specific doc where comment resides.
273: * @param tags array of text tags and inline tags (often alternating)
274: * present in the text of interest for this doc.
275: * @param isFirstSentence true if this is the first sentence.
276: * @return the {@link TagletOutput} representing the comments.
277: */
278: public abstract TagletOutput commentTagsToOutput(Tag holderTag,
279: Doc holderDoc, Tag[] tags, boolean isFirstSentence);
280:
281: /**
282: * @return an instance of the configuration used for this doclet.
283: */
284: public abstract Configuration configuration();
285:
286: /**
287: * @return an instance of the taglet output object.
288: */
289: public abstract TagletOutput getTagletOutputInstance();
290: }
|