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

Tue, 14 May 2013 10:14:57 -0700

author
jjg
date
Tue, 14 May 2013 10:14:57 -0700
changeset 1751
ca8808c88f94
parent 1724
d918b63a5509
child 2413
fe033d997ddf
permissions
-rw-r--r--

8012308: Remove TagletOutput in favor of direct use of Content
Reviewed-by: darcy

     1 /*
     2  * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.tools.doclets.internal.toolkit.taglets;
    28 import com.sun.javadoc.*;
    29 import com.sun.tools.doclets.internal.toolkit.Content;
    30 import com.sun.tools.doclets.internal.toolkit.util.DocFinder;
    32 /**
    33  * A simple single argument custom tag.
    34  *
    35  *  <p><b>This is NOT part of any supported API.
    36  *  If you write code that depends on this, you do so at your own risk.
    37  *  This code and its internal interfaces are subject to change or
    38  *  deletion without notice.</b>
    39  *
    40  * @author Jamie Ho
    41  */
    43 public class SimpleTaglet extends BaseTaglet implements InheritableTaglet {
    45     /**
    46      * The marker in the location string for excluded tags.
    47      */
    48     public static final String EXCLUDED = "x";
    50     /**
    51      * The marker in the location string for packages.
    52      */
    53     public static final String PACKAGE = "p";
    55     /**
    56      * The marker in the location string for types.
    57      */
    58     public static final String TYPE = "t";
    60     /**
    61      * The marker in the location string for constructors.
    62      */
    63     public static final String CONSTRUCTOR = "c";
    65     /**
    66      * The marker in the location string for fields.
    67      */
    68     public static final String FIELD = "f";
    70     /**
    71      * The marker in the location string for methods.
    72      */
    73     public static final String METHOD = "m";
    75     /**
    76      * The marker in the location string for overview.
    77      */
    78     public static final String OVERVIEW = "o";
    80     /**
    81      * Use in location string when the tag is to
    82      * appear in all locations.
    83      */
    84     public static final String ALL = "a";
    86     /**
    87      * The name of this tag.
    88      */
    89     protected String tagName;
    91     /**
    92      * The header to output.
    93      */
    94     protected String header;
    96     /**
    97      * The possible locations that this tag can appear in.
    98      */
    99     protected String locations;
   101     /**
   102      * Construct a <code>SimpleTaglet</code>.
   103      * @param tagName the name of this tag
   104      * @param header the header to output.
   105      * @param locations the possible locations that this tag
   106      * can appear in.  The <code>String</code> can contain 'p'
   107      * for package, 't' for type, 'm' for method, 'c' for constructor
   108      * and 'f' for field.
   109      */
   110     public SimpleTaglet(String tagName, String header, String locations) {
   111         this.tagName = tagName;
   112         this.header = header;
   113         locations = locations.toLowerCase();
   114         if (locations.indexOf(ALL) != -1 && locations.indexOf(EXCLUDED) == -1) {
   115             this.locations = PACKAGE + TYPE + FIELD + METHOD + CONSTRUCTOR + OVERVIEW;
   116         } else {
   117             this.locations = locations;
   118         }
   119     }
   121     /**
   122      * Return the name of this <code>Taglet</code>.
   123      */
   124     public String getName() {
   125         return tagName;
   126     }
   128     /**
   129      * Return true if this <code>SimpleTaglet</code>
   130      * is used in constructor documentation.
   131      * @return true if this <code>SimpleTaglet</code>
   132      * is used in constructor documentation and false
   133      * otherwise.
   134      */
   135     public boolean inConstructor() {
   136         return locations.indexOf(CONSTRUCTOR) != -1 && locations.indexOf(EXCLUDED) == -1;
   137     }
   139     /**
   140      * Return true if this <code>SimpleTaglet</code>
   141      * is used in field documentation.
   142      * @return true if this <code>SimpleTaglet</code>
   143      * is used in field documentation and false
   144      * otherwise.
   145      */
   146     public boolean inField() {
   147         return locations.indexOf(FIELD) != -1 && locations.indexOf(EXCLUDED) == -1;
   148     }
   150     /**
   151      * Return true if this <code>SimpleTaglet</code>
   152      * is used in method documentation.
   153      * @return true if this <code>SimpleTaglet</code>
   154      * is used in method documentation and false
   155      * otherwise.
   156      */
   157     public boolean inMethod() {
   158         return locations.indexOf(METHOD) != -1 && locations.indexOf(EXCLUDED) == -1;
   159     }
   161     /**
   162      * Return true if this <code>SimpleTaglet</code>
   163      * is used in overview documentation.
   164      * @return true if this <code>SimpleTaglet</code>
   165      * is used in overview documentation and false
   166      * otherwise.
   167      */
   168     public boolean inOverview() {
   169         return locations.indexOf(OVERVIEW) != -1 && locations.indexOf(EXCLUDED) == -1;
   170     }
   172     /**
   173      * Return true if this <code>SimpleTaglet</code>
   174      * is used in package documentation.
   175      * @return true if this <code>SimpleTaglet</code>
   176      * is used in package documentation and false
   177      * otherwise.
   178      */
   179     public boolean inPackage() {
   180         return locations.indexOf(PACKAGE) != -1 && locations.indexOf(EXCLUDED) == -1;
   181     }
   183     /**
   184      * Return true if this <code>SimpleTaglet</code>
   185      * is used in type documentation (classes or interfaces).
   186      * @return true if this <code>SimpleTaglet</code>
   187      * is used in type documentation and false
   188      * otherwise.
   189      */
   190     public boolean inType() {
   191         return locations.indexOf(TYPE) != -1&& locations.indexOf(EXCLUDED) == -1;
   192     }
   194     /**
   195      * Return true if this <code>Taglet</code>
   196      * is an inline tag.
   197      * @return true if this <code>Taglet</code>
   198      * is an inline tag and false otherwise.
   199      */
   200     public boolean isInlineTag() {
   201         return false;
   202     }
   204     @Override
   205     public void inherit(DocFinder.Input input, DocFinder.Output output) {
   206         Tag[] tags = input.element.tags(tagName);
   207         if (tags.length > 0) {
   208             output.holder = input.element;
   209             output.holderTag = tags[0];
   210             output.inlineTags = input.isFirstSentence
   211                     ? tags[0].firstSentenceTags() : tags[0].inlineTags();
   212         }
   213     }
   215     /**
   216      * {@inheritDoc}
   217      */
   218     public Content getTagletOutput(Tag tag, TagletWriter writer) {
   219         return header == null || tag == null ? null : writer.simpleTagOutput(tag, header);
   220     }
   222     /**
   223      * {@inheritDoc}
   224      */
   225     public Content getTagletOutput(Doc holder, TagletWriter writer) {
   226         if (header == null || holder.tags(getName()).length == 0) {
   227             return null;
   228         }
   229         return writer.simpleTagOutput(holder.tags(getName()), header);
   230     }
   231 }

mercurial