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

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/com/sun/javadoc/testLegacyTaglet/ToDoTaglet.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,177 @@
     1.4 +/*
     1.5 + * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +import com.sun.tools.doclets.Taglet;
    1.28 +import com.sun.javadoc.*;
    1.29 +import java.util.Map;
    1.30 +
    1.31 +/**
    1.32 + * A sample Taglet representing @todo. This tag can be used in any kind of
    1.33 + * {@link com.sun.javadoc.Doc}.  It is not an inline tag. The text is displayed
    1.34 + * in yellow to remind the developer to perform a task.  For
    1.35 + * example, "@todo Fix this!" would be shown as:
    1.36 + * <DL>
    1.37 + * <DT>
    1.38 + * <B>To Do:</B>
    1.39 + * <DD><table cellpadding=2 cellspacing=0><tr><td bgcolor="yellow">Fix this!
    1.40 + * </td></tr></table></DD>
    1.41 + * </DL>
    1.42 + *
    1.43 + * @author Jamie Ho
    1.44 + * @since 1.4
    1.45 + */
    1.46 +
    1.47 +public class ToDoTaglet implements Taglet {
    1.48 +
    1.49 +    private static final String NAME = "todo";
    1.50 +    private static final String HEADER = "To Do:";
    1.51 +
    1.52 +    /**
    1.53 +     * Return the name of this custom tag.
    1.54 +     */
    1.55 +    public String getName() {
    1.56 +        return NAME;
    1.57 +    }
    1.58 +
    1.59 +    /**
    1.60 +     * Will return true since <code>@todo</code>
    1.61 +     * can be used in field documentation.
    1.62 +     * @return true since <code>@todo</code>
    1.63 +     * can be used in field documentation and false
    1.64 +     * otherwise.
    1.65 +     */
    1.66 +    public boolean inField() {
    1.67 +        return true;
    1.68 +    }
    1.69 +
    1.70 +    /**
    1.71 +     * Will return true since <code>@todo</code>
    1.72 +     * can be used in constructor documentation.
    1.73 +     * @return true since <code>@todo</code>
    1.74 +     * can be used in constructor documentation and false
    1.75 +     * otherwise.
    1.76 +     */
    1.77 +    public boolean inConstructor() {
    1.78 +        return true;
    1.79 +    }
    1.80 +
    1.81 +    /**
    1.82 +     * Will return true since <code>@todo</code>
    1.83 +     * can be used in method documentation.
    1.84 +     * @return true since <code>@todo</code>
    1.85 +     * can be used in method documentation and false
    1.86 +     * otherwise.
    1.87 +     */
    1.88 +    public boolean inMethod() {
    1.89 +        return true;
    1.90 +    }
    1.91 +
    1.92 +    /**
    1.93 +     * Will return true since <code>@todo</code>
    1.94 +     * can be used in method documentation.
    1.95 +     * @return true since <code>@todo</code>
    1.96 +     * can be used in overview documentation and false
    1.97 +     * otherwise.
    1.98 +     */
    1.99 +    public boolean inOverview() {
   1.100 +        return true;
   1.101 +    }
   1.102 +
   1.103 +    /**
   1.104 +     * Will return true since <code>@todo</code>
   1.105 +     * can be used in package documentation.
   1.106 +     * @return true since <code>@todo</code>
   1.107 +     * can be used in package documentation and false
   1.108 +     * otherwise.
   1.109 +     */
   1.110 +    public boolean inPackage() {
   1.111 +        return true;
   1.112 +    }
   1.113 +
   1.114 +    /**
   1.115 +     * Will return true since <code>@todo</code>
   1.116 +     * can be used in type documentation (classes or interfaces).
   1.117 +     * @return true since <code>@todo</code>
   1.118 +     * can be used in type documentation and false
   1.119 +     * otherwise.
   1.120 +     */
   1.121 +    public boolean inType() {
   1.122 +        return true;
   1.123 +    }
   1.124 +
   1.125 +    /**
   1.126 +     * Will return false since <code>@todo</code>
   1.127 +     * is not an inline tag.
   1.128 +     * @return false since <code>@todo</code>
   1.129 +     * is not an inline tag.
   1.130 +     */
   1.131 +
   1.132 +    public boolean isInlineTag() {
   1.133 +        return false;
   1.134 +    }
   1.135 +
   1.136 +    /**
   1.137 +     * Register this Taglet.
   1.138 +     * @param tagletMap  the map to register this tag to.
   1.139 +     */
   1.140 +    public static void register(Map tagletMap) {
   1.141 +       ToDoTaglet tag = new ToDoTaglet();
   1.142 +       Taglet t = (Taglet) tagletMap.get(tag.getName());
   1.143 +       if (t != null) {
   1.144 +           tagletMap.remove(tag.getName());
   1.145 +       }
   1.146 +       tagletMap.put(tag.getName(), tag);
   1.147 +    }
   1.148 +
   1.149 +    /**
   1.150 +     * Given the <code>Tag</code> representation of this custom
   1.151 +     * tag, return its string representation.
   1.152 +     * @param tag   the <code>Tag</code> representation of this custom tag.
   1.153 +     */
   1.154 +    public String toString(Tag tag) {
   1.155 +        return "<DT><B>" + HEADER + "</B><DD>"
   1.156 +               + "<table cellpadding=2 cellspacing=0><tr><td bgcolor=\"yellow\">"
   1.157 +               + tag.text()
   1.158 +               + "</td></tr></table></DD>\n";
   1.159 +    }
   1.160 +
   1.161 +    /**
   1.162 +     * Given an array of <code>Tag</code>s representing this custom
   1.163 +     * tag, return its string representation.
   1.164 +     * @param tags  the array of <code>Tag</code>s representing of this custom tag.
   1.165 +     */
   1.166 +    public String toString(Tag[] tags) {
   1.167 +        if (tags.length == 0) {
   1.168 +            return null;
   1.169 +        }
   1.170 +        String result = "\n<DT><B>" + HEADER + "</B><DD>";
   1.171 +        result += "<table cellpadding=2 cellspacing=0><tr><td bgcolor=\"yellow\">";
   1.172 +        for (int i = 0; i < tags.length; i++) {
   1.173 +            if (i > 0) {
   1.174 +                result += ", ";
   1.175 +            }
   1.176 +            result += tags[i].text();
   1.177 +        }
   1.178 +        return result + "</td></tr></table></DD>\n";
   1.179 +    }
   1.180 +}

mercurial