duke@1: /* ohair@554: * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as duke@1: * published by the Free Software Foundation. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: import com.sun.tools.doclets.Taglet; duke@1: import com.sun.javadoc.*; duke@1: import java.util.Map; duke@1: duke@1: /** duke@1: * A sample Taglet representing @todo. This tag can be used in any kind of duke@1: * {@link com.sun.javadoc.Doc}. It is not an inline tag. The text is displayed duke@1: * in yellow to remind the developer to perform a task. For duke@1: * example, "@todo Fix this!" would be shown as: duke@1: *
duke@1: *
duke@1: * To Do: duke@1: *
Fix this! duke@1: *
duke@1: *
duke@1: * duke@1: * @author Jamie Ho duke@1: * @since 1.4 duke@1: */ duke@1: duke@1: public class ToDoTaglet implements Taglet { duke@1: duke@1: private static final String NAME = "todo"; duke@1: private static final String HEADER = "To Do:"; duke@1: duke@1: /** duke@1: * Return the name of this custom tag. duke@1: */ duke@1: public String getName() { duke@1: return NAME; duke@1: } duke@1: duke@1: /** duke@1: * Will return true since @todo duke@1: * can be used in field documentation. duke@1: * @return true since @todo duke@1: * can be used in field documentation and false duke@1: * otherwise. duke@1: */ duke@1: public boolean inField() { duke@1: return true; duke@1: } duke@1: duke@1: /** duke@1: * Will return true since @todo duke@1: * can be used in constructor documentation. duke@1: * @return true since @todo duke@1: * can be used in constructor documentation and false duke@1: * otherwise. duke@1: */ duke@1: public boolean inConstructor() { duke@1: return true; duke@1: } duke@1: duke@1: /** duke@1: * Will return true since @todo duke@1: * can be used in method documentation. duke@1: * @return true since @todo duke@1: * can be used in method documentation and false duke@1: * otherwise. duke@1: */ duke@1: public boolean inMethod() { duke@1: return true; duke@1: } duke@1: duke@1: /** duke@1: * Will return true since @todo duke@1: * can be used in method documentation. duke@1: * @return true since @todo duke@1: * can be used in overview documentation and false duke@1: * otherwise. duke@1: */ duke@1: public boolean inOverview() { duke@1: return true; duke@1: } duke@1: duke@1: /** duke@1: * Will return true since @todo duke@1: * can be used in package documentation. duke@1: * @return true since @todo duke@1: * can be used in package documentation and false duke@1: * otherwise. duke@1: */ duke@1: public boolean inPackage() { duke@1: return true; duke@1: } duke@1: duke@1: /** duke@1: * Will return true since @todo duke@1: * can be used in type documentation (classes or interfaces). duke@1: * @return true since @todo duke@1: * can be used in type documentation and false duke@1: * otherwise. duke@1: */ duke@1: public boolean inType() { duke@1: return true; duke@1: } duke@1: duke@1: /** duke@1: * Will return false since @todo duke@1: * is not an inline tag. duke@1: * @return false since @todo duke@1: * is not an inline tag. duke@1: */ duke@1: duke@1: public boolean isInlineTag() { duke@1: return false; duke@1: } duke@1: duke@1: /** duke@1: * Register this Taglet. duke@1: * @param tagletMap the map to register this tag to. duke@1: */ duke@1: public static void register(Map tagletMap) { duke@1: ToDoTaglet tag = new ToDoTaglet(); duke@1: Taglet t = (Taglet) tagletMap.get(tag.getName()); duke@1: if (t != null) { duke@1: tagletMap.remove(tag.getName()); duke@1: } duke@1: tagletMap.put(tag.getName(), tag); duke@1: } duke@1: duke@1: /** duke@1: * Given the Tag representation of this custom duke@1: * tag, return its string representation. duke@1: * @param tag the Tag representation of this custom tag. duke@1: */ duke@1: public String toString(Tag tag) { duke@1: return "
" + HEADER + "
" duke@1: + "
" duke@1: + tag.text() duke@1: + "
\n"; duke@1: } duke@1: duke@1: /** duke@1: * Given an array of Tags representing this custom duke@1: * tag, return its string representation. duke@1: * @param tags the array of Tags representing of this custom tag. duke@1: */ duke@1: public String toString(Tag[] tags) { duke@1: if (tags.length == 0) { duke@1: return null; duke@1: } duke@1: String result = "\n
" + HEADER + "
"; duke@1: result += "
"; duke@1: for (int i = 0; i < tags.length; i++) { duke@1: if (i > 0) { duke@1: result += ", "; duke@1: } duke@1: result += tags[i].text(); duke@1: } duke@1: return result + "
\n"; duke@1: } duke@1: }