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

Tue, 28 Dec 2010 15:54:52 -0800

author
ohair
date
Tue, 28 Dec 2010 15:54:52 -0800
changeset 798
4868a36f6fd8
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

6962318: Update copyright year
Reviewed-by: xdono

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

mercurial