test/com/sun/javadoc/testLegacyTaglet/ToDoTaglet.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

     1 /*
     2  * Copyright (c) 2003, 2007, 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.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 import com.sun.tools.doclets.Taglet;
    25 import com.sun.javadoc.*;
    26 import java.util.Map;
    28 /**
    29  * A sample Taglet representing @todo. This tag can be used in any kind of
    30  * {@link com.sun.javadoc.Doc}.  It is not an inline tag. The text is displayed
    31  * in yellow to remind the developer to perform a task.  For
    32  * example, "@todo Fix this!" would be shown as:
    33  * <DL>
    34  * <DT>
    35  * <B>To Do:</B>
    36  * <DD><table cellpadding=2 cellspacing=0><tr><td bgcolor="yellow">Fix this!
    37  * </td></tr></table></DD>
    38  * </DL>
    39  *
    40  * @author Jamie Ho
    41  * @since 1.4
    42  */
    44 public class ToDoTaglet implements Taglet {
    46     private static final String NAME = "todo";
    47     private static final String HEADER = "To Do:";
    49     /**
    50      * Return the name of this custom tag.
    51      */
    52     public String getName() {
    53         return NAME;
    54     }
    56     /**
    57      * Will return true since <code>@todo</code>
    58      * can be used in field documentation.
    59      * @return true since <code>@todo</code>
    60      * can be used in field documentation and false
    61      * otherwise.
    62      */
    63     public boolean inField() {
    64         return true;
    65     }
    67     /**
    68      * Will return true since <code>@todo</code>
    69      * can be used in constructor documentation.
    70      * @return true since <code>@todo</code>
    71      * can be used in constructor documentation and false
    72      * otherwise.
    73      */
    74     public boolean inConstructor() {
    75         return true;
    76     }
    78     /**
    79      * Will return true since <code>@todo</code>
    80      * can be used in method documentation.
    81      * @return true since <code>@todo</code>
    82      * can be used in method documentation and false
    83      * otherwise.
    84      */
    85     public boolean inMethod() {
    86         return true;
    87     }
    89     /**
    90      * Will return true since <code>@todo</code>
    91      * can be used in method documentation.
    92      * @return true since <code>@todo</code>
    93      * can be used in overview documentation and false
    94      * otherwise.
    95      */
    96     public boolean inOverview() {
    97         return true;
    98     }
   100     /**
   101      * Will return true since <code>@todo</code>
   102      * can be used in package documentation.
   103      * @return true since <code>@todo</code>
   104      * can be used in package documentation and false
   105      * otherwise.
   106      */
   107     public boolean inPackage() {
   108         return true;
   109     }
   111     /**
   112      * Will return true since <code>@todo</code>
   113      * can be used in type documentation (classes or interfaces).
   114      * @return true since <code>@todo</code>
   115      * can be used in type documentation and false
   116      * otherwise.
   117      */
   118     public boolean inType() {
   119         return true;
   120     }
   122     /**
   123      * Will return false since <code>@todo</code>
   124      * is not an inline tag.
   125      * @return false since <code>@todo</code>
   126      * is not an inline tag.
   127      */
   129     public boolean isInlineTag() {
   130         return false;
   131     }
   133     /**
   134      * Register this Taglet.
   135      * @param tagletMap  the map to register this tag to.
   136      */
   137     public static void register(Map tagletMap) {
   138        ToDoTaglet tag = new ToDoTaglet();
   139        Taglet t = (Taglet) tagletMap.get(tag.getName());
   140        if (t != null) {
   141            tagletMap.remove(tag.getName());
   142        }
   143        tagletMap.put(tag.getName(), tag);
   144     }
   146     /**
   147      * Given the <code>Tag</code> representation of this custom
   148      * tag, return its string representation.
   149      * @param tag   the <code>Tag</code> representation of this custom tag.
   150      */
   151     public String toString(Tag tag) {
   152         return "<DT><B>" + HEADER + "</B><DD>"
   153                + "<table cellpadding=2 cellspacing=0><tr><td bgcolor=\"yellow\">"
   154                + tag.text()
   155                + "</td></tr></table></DD>\n";
   156     }
   158     /**
   159      * Given an array of <code>Tag</code>s representing this custom
   160      * tag, return its string representation.
   161      * @param tags  the array of <code>Tag</code>s representing of this custom tag.
   162      */
   163     public String toString(Tag[] tags) {
   164         if (tags.length == 0) {
   165             return null;
   166         }
   167         String result = "\n<DT><B>" + HEADER + "</B><DD>";
   168         result += "<table cellpadding=2 cellspacing=0><tr><td bgcolor=\"yellow\">";
   169         for (int i = 0; i < tags.length; i++) {
   170             if (i > 0) {
   171                 result += ", ";
   172             }
   173             result += tags[i].text();
   174         }
   175         return result + "</td></tr></table></DD>\n";
   176     }
   177 }

mercurial