duke@1: /* duke@1: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. Sun designates this duke@1: * particular file as subject to the "Classpath" exception as provided duke@1: * by Sun in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * duke@1: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: * CA 95054 USA or visit www.sun.com if you need additional information or duke@1: * have any questions. duke@1: */ duke@1: duke@1: package com.sun.tools.doclets.internal.toolkit.taglets; duke@1: duke@1: import com.sun.tools.doclets.internal.toolkit.*; duke@1: import com.sun.tools.doclets.internal.toolkit.util.*; duke@1: import com.sun.javadoc.*; duke@1: duke@1: /** duke@1: * The interface for the taglet writer. duke@1: * duke@1: * @since 1.5 duke@1: * @author Jamie Ho duke@1: */ duke@1: duke@1: public abstract class TagletWriter { duke@1: duke@1: /** duke@1: * True if we only want to write the first sentence. duke@1: */ duke@1: protected boolean isFirstSentence = false; duke@1: duke@1: /** duke@1: * @return an instance of the output object. duke@1: */ duke@1: public abstract TagletOutput getOutputInstance(); duke@1: duke@1: /** duke@1: * Returns the output for the DocRoot inline tag. duke@1: * @return the output for the DocRoot inline tag. duke@1: */ duke@1: protected abstract TagletOutput getDocRootOutput(); duke@1: duke@1: /** duke@1: * Return the deprecated tag output. duke@1: * duke@1: * @param doc the doc to write deprecated documentation for. duke@1: * @return the output of the deprecated tag. duke@1: */ duke@1: protected abstract TagletOutput deprecatedTagOutput(Doc doc); duke@1: duke@1: /** duke@1: * Returns {@link MessageRetriever} for output purposes. duke@1: * duke@1: * @return {@link MessageRetriever} for output purposes. duke@1: */ duke@1: protected abstract MessageRetriever getMsgRetriever(); duke@1: duke@1: /** duke@1: * Return the header for the param tags. duke@1: * duke@1: * @param header the header to display. duke@1: * @return the header for the param tags. duke@1: */ duke@1: protected abstract TagletOutput getParamHeader(String header); duke@1: duke@1: /** duke@1: * Return the output for param tags. duke@1: * duke@1: * @param paramTag the parameter to document. duke@1: * @param paramName the name of the parameter. duke@1: * @return the output of the param tag. duke@1: */ duke@1: protected abstract TagletOutput paramTagOutput(ParamTag paramTag, duke@1: String paramName); duke@1: duke@1: /** duke@1: * Return the return tag output. duke@1: * duke@1: * @param returnTag the return tag to output. duke@1: * @return the output of the return tag. duke@1: */ duke@1: protected abstract TagletOutput returnTagOutput(Tag returnTag); duke@1: duke@1: /** duke@1: * Return the see tag output. duke@1: * duke@1: * @param seeTags the array of See tags. duke@1: * @return the output of the see tags. duke@1: */ duke@1: protected abstract TagletOutput seeTagOutput(Doc holder, SeeTag[] seeTags); duke@1: duke@1: /** duke@1: * Return the output for a simple tag. duke@1: * duke@1: * @param simpleTags the array of simple tags. duke@1: * @return the output of the simple tags. duke@1: */ duke@1: protected abstract TagletOutput simpleTagOutput(Tag[] simpleTags, duke@1: String header); duke@1: duke@1: /** duke@1: * Return the output for a simple tag. duke@1: * duke@1: * @param simpleTag the simple tag. duke@1: * @return the output of the simple tag. duke@1: */ duke@1: protected abstract TagletOutput simpleTagOutput(Tag simpleTag, String header); duke@1: duke@1: /** duke@1: * Return the header for the throws tag. duke@1: * duke@1: * @return the header for the throws tag. duke@1: */ duke@1: protected abstract TagletOutput getThrowsHeader(); duke@1: duke@1: /** duke@1: * Return the header for the throws tag. duke@1: * duke@1: * @param throwsTag the throws tag. duke@1: * @return the output of the throws tag. duke@1: */ duke@1: protected abstract TagletOutput throwsTagOutput(ThrowsTag throwsTag); duke@1: duke@1: /** duke@1: * Return the output for the throws tag. duke@1: * duke@1: * @param throwsType the throws type. duke@1: * @return the output of the throws type. duke@1: */ duke@1: protected abstract TagletOutput throwsTagOutput(Type throwsType); duke@1: duke@1: /** duke@1: * Return the output for the value tag. duke@1: * duke@1: * @param field the constant field that holds the value tag. duke@1: * @param constantVal the constant value to document. duke@1: * @param includeLink true if we should link the constant text to the duke@1: * constant field itself. duke@1: * @return the output of the value tag. duke@1: */ duke@1: protected abstract TagletOutput valueTagOutput(FieldDoc field, duke@1: String constantVal, boolean includeLink); duke@1: duke@1: /** duke@1: * Given an output object, append to it the tag documentation for duke@1: * the given member. duke@1: * duke@1: * @param tagletManager the manager that manages the taglets. duke@1: * @param doc the Doc that we are print tags for. duke@1: * @param taglets the taglets to print. duke@1: * @param writer the writer that will generate the output strings. duke@1: * @param output the output buffer to store the output in. duke@1: */ duke@1: public static void genTagOuput(TagletManager tagletManager, Doc doc, duke@1: Taglet[] taglets, TagletWriter writer, TagletOutput output) { duke@1: tagletManager.checkTags(doc, doc.tags(), false); duke@1: tagletManager.checkTags(doc, doc.inlineTags(), true); duke@1: TagletOutput currentOutput = null; duke@1: for (int i = 0; i < taglets.length; i++) { duke@1: if (doc instanceof ClassDoc && taglets[i] instanceof ParamTaglet) { duke@1: //The type parameters are documented in a special section away duke@1: //from the tag info, so skip here. duke@1: continue; duke@1: } duke@1: if (taglets[i] instanceof DeprecatedTaglet) { duke@1: //Deprecated information is documented "inline", not in tag info duke@1: //section. duke@1: continue; duke@1: } duke@1: try { duke@1: currentOutput = taglets[i].getTagletOutput(doc, writer); duke@1: } catch (IllegalArgumentException e) { duke@1: //The taglet does not take a member as an argument. Let's try duke@1: //a single tag. duke@1: Tag[] tags = doc.tags(taglets[i].getName()); duke@1: if (tags.length > 0) { duke@1: currentOutput = taglets[i].getTagletOutput(tags[0], writer); duke@1: } duke@1: } duke@1: if (currentOutput != null) { duke@1: tagletManager.seenCustomTag(taglets[i].getName()); duke@1: output.appendOutput(currentOutput); duke@1: } duke@1: } duke@1: } duke@1: duke@1: /** duke@1: * Given an inline tag, return its output. duke@1: * @param tagletManager The taglet manager for the current doclet. duke@1: * @param holderTag The tag this holds this inline tag. Null if there duke@1: * is no tag that holds it. duke@1: * @param inlineTag The inline tag to be documented. duke@1: * @param tagletWriter The taglet writer to write the output. duke@1: * @return The output of the inline tag. duke@1: */ duke@1: public static TagletOutput getInlineTagOuput(TagletManager tagletManager, duke@1: Tag holderTag, Tag inlineTag, TagletWriter tagletWriter) { duke@1: Taglet[] definedTags = tagletManager.getInlineCustomTags(); duke@1: //This is a custom inline tag. duke@1: for (int j = 0; j < definedTags.length; j++) { duke@1: if (("@"+definedTags[j].getName()).equals(inlineTag.name())) { duke@1: //Given a name of a seen custom tag, remove it from the duke@1: // set of unseen custom tags. duke@1: tagletManager.seenCustomTag(definedTags[j].getName()); duke@1: TagletOutput output = definedTags[j].getTagletOutput( duke@1: holderTag != null && duke@1: definedTags[j].getName().equals("inheritDoc") ? duke@1: holderTag : inlineTag, tagletWriter); duke@1: return output; duke@1: } duke@1: } duke@1: return null; duke@1: } duke@1: duke@1: /** duke@1: * Converts inline tags and text to TagOutput, expanding the duke@1: * inline tags along the way. Called wherever text can contain duke@1: * an inline tag, such as in comments or in free-form text arguments duke@1: * to non-inline tags. duke@1: * duke@1: * @param holderTag the tag that holds the documentation. duke@1: * @param tags array of text tags and inline tags (often alternating) duke@1: * present in the text of interest for this doc. duke@1: * @return the {@link TagletOutput} representing the comments. duke@1: */ duke@1: public abstract TagletOutput commentTagsToOutput(Tag holderTag, Tag[] tags); duke@1: duke@1: /** duke@1: * Converts inline tags and text to TagOutput, expanding the duke@1: * inline tags along the way. Called wherever text can contain duke@1: * an inline tag, such as in comments or in free-form text arguments duke@1: * to non-inline tags. duke@1: * duke@1: * @param holderDoc specific doc where comment resides. duke@1: * @param tags array of text tags and inline tags (often alternating) duke@1: * present in the text of interest for this doc. duke@1: * @return the {@link TagletOutput} representing the comments. duke@1: */ duke@1: public abstract TagletOutput commentTagsToOutput(Doc holderDoc, Tag[] tags); duke@1: duke@1: /** duke@1: * Converts inline tags and text to TagOutput, expanding the duke@1: * inline tags along the way. Called wherever text can contain duke@1: * an inline tag, such as in comments or in free-form text arguments duke@1: * to non-inline tags. duke@1: * duke@1: * @param holderTag the tag that holds the documentation. duke@1: * @param holderDoc specific doc where comment resides. duke@1: * @param tags array of text tags and inline tags (often alternating) duke@1: * present in the text of interest for this doc. duke@1: * @param isFirstSentence true if this is the first sentence. duke@1: * @return the {@link TagletOutput} representing the comments. duke@1: */ duke@1: public abstract TagletOutput commentTagsToOutput(Tag holderTag, duke@1: Doc holderDoc, Tag[] tags, boolean isFirstSentence); duke@1: duke@1: /** duke@1: * @return an instance of the configuration used for this doclet. duke@1: */ duke@1: public abstract Configuration configuration(); duke@1: duke@1: /** duke@1: * @return an instance of the taglet output object. duke@1: */ duke@1: public abstract TagletOutput getTagletOutputInstance(); duke@1: }