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

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

mercurial