aoqi@0: /* aoqi@0: * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.doclets.internal.toolkit.taglets; aoqi@0: aoqi@0: import com.sun.javadoc.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.*; aoqi@0: import com.sun.tools.doclets.internal.toolkit.util.*; aoqi@0: aoqi@0: /** aoqi@0: * The interface for the taglet writer. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: * aoqi@0: * @since 1.5 aoqi@0: * @author Jamie Ho aoqi@0: */ aoqi@0: aoqi@0: public abstract class TagletWriter { aoqi@0: aoqi@0: /** aoqi@0: * True if we only want to write the first sentence. aoqi@0: */ aoqi@0: protected final boolean isFirstSentence; aoqi@0: aoqi@0: protected TagletWriter(boolean isFirstSentence) { aoqi@0: this.isFirstSentence = isFirstSentence; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * @return an instance of an output object. aoqi@0: */ aoqi@0: public abstract Content getOutputInstance(); aoqi@0: aoqi@0: /** aoqi@0: * Return the output for a {@code...} tag. aoqi@0: * aoqi@0: * @param tag the tag. aoqi@0: * @return the output of the taglet. aoqi@0: */ aoqi@0: protected abstract Content codeTagOutput(Tag tag); aoqi@0: aoqi@0: /** aoqi@0: * Returns the output for the DocRoot inline tag. aoqi@0: * @return the output for the DocRoot inline tag. aoqi@0: */ aoqi@0: protected abstract Content getDocRootOutput(); aoqi@0: aoqi@0: /** aoqi@0: * Return the deprecated tag output. aoqi@0: * aoqi@0: * @param doc the doc to write deprecated documentation for. aoqi@0: * @return the output of the deprecated tag. aoqi@0: */ aoqi@0: protected abstract Content deprecatedTagOutput(Doc doc); aoqi@0: aoqi@0: /** aoqi@0: * Return the output for a {@literal...} tag. aoqi@0: * aoqi@0: * @param tag the tag. aoqi@0: * @return the output of the taglet. aoqi@0: */ aoqi@0: protected abstract Content literalTagOutput(Tag tag); aoqi@0: aoqi@0: /** aoqi@0: * Returns {@link MessageRetriever} for output purposes. aoqi@0: * aoqi@0: * @return {@link MessageRetriever} for output purposes. aoqi@0: */ aoqi@0: protected abstract MessageRetriever getMsgRetriever(); aoqi@0: aoqi@0: /** aoqi@0: * Return the header for the param tags. aoqi@0: * aoqi@0: * @param header the header to display. aoqi@0: * @return the header for the param tags. aoqi@0: */ aoqi@0: protected abstract Content getParamHeader(String header); aoqi@0: aoqi@0: /** aoqi@0: * Return the output for param tags. aoqi@0: * aoqi@0: * @param paramTag the parameter to document. aoqi@0: * @param paramName the name of the parameter. aoqi@0: * @return the output of the param tag. aoqi@0: */ aoqi@0: protected abstract Content paramTagOutput(ParamTag paramTag, aoqi@0: String paramName); aoqi@0: aoqi@0: /** aoqi@0: * Return the output for property tags. aoqi@0: * aoqi@0: * @param propertyTag the parameter to document. aoqi@0: * @param prefix the text with which to prefix the property name. aoqi@0: * @return the output of the param tag. aoqi@0: */ aoqi@0: protected abstract Content propertyTagOutput(Tag propertyTag, String prefix); aoqi@0: aoqi@0: /** aoqi@0: * Return the return tag output. aoqi@0: * aoqi@0: * @param returnTag the return tag to output. aoqi@0: * @return the output of the return tag. aoqi@0: */ aoqi@0: protected abstract Content returnTagOutput(Tag returnTag); aoqi@0: aoqi@0: /** aoqi@0: * Return the see tag output. aoqi@0: * aoqi@0: * @param seeTags the array of See tags. aoqi@0: * @return the output of the see tags. aoqi@0: */ aoqi@0: protected abstract Content seeTagOutput(Doc holder, SeeTag[] seeTags); aoqi@0: aoqi@0: /** aoqi@0: * Return the output for a simple tag. aoqi@0: * aoqi@0: * @param simpleTags the array of simple tags. aoqi@0: * @return the output of the simple tags. aoqi@0: */ aoqi@0: protected abstract Content simpleTagOutput(Tag[] simpleTags, aoqi@0: String header); aoqi@0: aoqi@0: /** aoqi@0: * Return the output for a simple tag. aoqi@0: * aoqi@0: * @param simpleTag the simple tag. aoqi@0: * @return the output of the simple tag. aoqi@0: */ aoqi@0: protected abstract Content simpleTagOutput(Tag simpleTag, String header); aoqi@0: aoqi@0: /** aoqi@0: * Return the header for the throws tag. aoqi@0: * aoqi@0: * @return the header for the throws tag. aoqi@0: */ aoqi@0: protected abstract Content getThrowsHeader(); aoqi@0: aoqi@0: /** aoqi@0: * Return the header for the throws tag. aoqi@0: * aoqi@0: * @param throwsTag the throws tag. aoqi@0: * @return the output of the throws tag. aoqi@0: */ aoqi@0: protected abstract Content throwsTagOutput(ThrowsTag throwsTag); aoqi@0: aoqi@0: /** aoqi@0: * Return the output for the throws tag. aoqi@0: * aoqi@0: * @param throwsType the throws type. aoqi@0: * @return the output of the throws type. aoqi@0: */ aoqi@0: protected abstract Content throwsTagOutput(Type throwsType); aoqi@0: aoqi@0: /** aoqi@0: * Return the output for the value tag. aoqi@0: * aoqi@0: * @param field the constant field that holds the value tag. aoqi@0: * @param constantVal the constant value to document. aoqi@0: * @param includeLink true if we should link the constant text to the aoqi@0: * constant field itself. aoqi@0: * @return the output of the value tag. aoqi@0: */ aoqi@0: protected abstract Content valueTagOutput(FieldDoc field, aoqi@0: String constantVal, boolean includeLink); aoqi@0: aoqi@0: /** aoqi@0: * Given an output object, append to it the tag documentation for aoqi@0: * the given member. aoqi@0: * aoqi@0: * @param tagletManager the manager that manages the taglets. aoqi@0: * @param doc the Doc that we are print tags for. aoqi@0: * @param taglets the taglets to print. aoqi@0: * @param writer the writer that will generate the output strings. aoqi@0: * @param output the output buffer to store the output in. aoqi@0: */ aoqi@0: public static void genTagOuput(TagletManager tagletManager, Doc doc, aoqi@0: Taglet[] taglets, TagletWriter writer, Content output) { aoqi@0: tagletManager.checkTags(doc, doc.tags(), false); aoqi@0: tagletManager.checkTags(doc, doc.inlineTags(), true); aoqi@0: Content currentOutput = null; aoqi@0: for (int i = 0; i < taglets.length; i++) { aoqi@0: currentOutput = null; aoqi@0: if (doc instanceof ClassDoc && taglets[i] instanceof ParamTaglet) { aoqi@0: //The type parameters are documented in a special section away aoqi@0: //from the tag info, so skip here. aoqi@0: continue; aoqi@0: } aoqi@0: if (taglets[i] instanceof DeprecatedTaglet) { aoqi@0: //Deprecated information is documented "inline", not in tag info aoqi@0: //section. aoqi@0: continue; aoqi@0: } aoqi@0: try { aoqi@0: currentOutput = taglets[i].getTagletOutput(doc, writer); aoqi@0: } catch (IllegalArgumentException e) { aoqi@0: //The taglet does not take a member as an argument. Let's try aoqi@0: //a single tag. aoqi@0: Tag[] tags = doc.tags(taglets[i].getName()); aoqi@0: if (tags.length > 0) { aoqi@0: currentOutput = taglets[i].getTagletOutput(tags[0], writer); aoqi@0: } aoqi@0: } aoqi@0: if (currentOutput != null) { aoqi@0: tagletManager.seenCustomTag(taglets[i].getName()); aoqi@0: output.addContent(currentOutput); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Given an inline tag, return its output. aoqi@0: * @param tagletManager The taglet manager for the current doclet. aoqi@0: * @param holderTag The tag this holds this inline tag. Null if there aoqi@0: * is no tag that holds it. aoqi@0: * @param inlineTag The inline tag to be documented. aoqi@0: * @param tagletWriter The taglet writer to write the output. aoqi@0: * @return The output of the inline tag. aoqi@0: */ aoqi@0: public static Content getInlineTagOuput(TagletManager tagletManager, aoqi@0: Tag holderTag, Tag inlineTag, TagletWriter tagletWriter) { aoqi@0: Taglet[] definedTags = tagletManager.getInlineCustomTaglets(); aoqi@0: //This is a custom inline tag. aoqi@0: for (int j = 0; j < definedTags.length; j++) { aoqi@0: if (("@"+definedTags[j].getName()).equals(inlineTag.name())) { aoqi@0: //Given a name of a seen custom tag, remove it from the aoqi@0: // set of unseen custom tags. aoqi@0: tagletManager.seenCustomTag(definedTags[j].getName()); aoqi@0: Content output = definedTags[j].getTagletOutput( aoqi@0: holderTag != null && aoqi@0: definedTags[j].getName().equals("inheritDoc") ? aoqi@0: holderTag : inlineTag, tagletWriter); aoqi@0: return output; aoqi@0: } aoqi@0: } aoqi@0: return null; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Converts inline tags and text to TagOutput, expanding the aoqi@0: * inline tags along the way. Called wherever text can contain aoqi@0: * an inline tag, such as in comments or in free-form text arguments aoqi@0: * to non-inline tags. aoqi@0: * aoqi@0: * @param holderTag the tag that holds the documentation. aoqi@0: * @param tags array of text tags and inline tags (often alternating) aoqi@0: * present in the text of interest for this doc. aoqi@0: * @return the {@link Content} representing the comments. aoqi@0: */ aoqi@0: public abstract Content commentTagsToOutput(Tag holderTag, Tag[] tags); aoqi@0: aoqi@0: /** aoqi@0: * Converts inline tags and text to TagOutput, expanding the aoqi@0: * inline tags along the way. Called wherever text can contain aoqi@0: * an inline tag, such as in comments or in free-form text arguments aoqi@0: * to non-inline tags. aoqi@0: * aoqi@0: * @param holderDoc specific doc where comment resides. aoqi@0: * @param tags array of text tags and inline tags (often alternating) aoqi@0: * present in the text of interest for this doc. aoqi@0: * @return the {@link Content} representing the comments. aoqi@0: */ aoqi@0: public abstract Content commentTagsToOutput(Doc holderDoc, Tag[] tags); aoqi@0: aoqi@0: /** aoqi@0: * Converts inline tags and text to TagOutput, expanding the aoqi@0: * inline tags along the way. Called wherever text can contain aoqi@0: * an inline tag, such as in comments or in free-form text arguments aoqi@0: * to non-inline tags. aoqi@0: * aoqi@0: * @param holderTag the tag that holds the documentation. aoqi@0: * @param holderDoc specific doc where comment resides. aoqi@0: * @param tags array of text tags and inline tags (often alternating) aoqi@0: * present in the text of interest for this doc. aoqi@0: * @param isFirstSentence true if this is the first sentence. aoqi@0: * @return the {@link Content} representing the comments. aoqi@0: */ aoqi@0: public abstract Content commentTagsToOutput(Tag holderTag, aoqi@0: Doc holderDoc, Tag[] tags, boolean isFirstSentence); aoqi@0: aoqi@0: /** aoqi@0: * @return an instance of the configuration used for this doclet. aoqi@0: */ aoqi@0: public abstract Configuration configuration(); aoqi@0: }