001: /*
002: * Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.doclets.internal.toolkit.taglets;
027:
028: import com.sun.javadoc.*;
029:
030: /**
031: * A simple single argument custom tag.
032: *
033: * This code is not part of an API.
034: * It is implementation that is subject to change.
035: * Do not use it as an API
036: *
037: * @author Jamie Ho
038: */
039:
040: public class SimpleTaglet extends BaseTaglet {
041:
042: /**
043: * The marker in the location string for excluded tags.
044: */
045: public static final String EXCLUDED = "x";
046:
047: /**
048: * The marker in the location string for packages.
049: */
050: public static final String PACKAGE = "p";
051:
052: /**
053: * The marker in the location string for types.
054: */
055: public static final String TYPE = "t";
056:
057: /**
058: * The marker in the location string for constructors.
059: */
060: public static final String CONSTRUCTOR = "c";
061:
062: /**
063: * The marker in the location string for fields.
064: */
065: public static final String FIELD = "f";
066:
067: /**
068: * The marker in the location string for methods.
069: */
070: public static final String METHOD = "m";
071:
072: /**
073: * The marker in the location string for overview.
074: */
075: public static final String OVERVIEW = "o";
076:
077: /**
078: * Use in location string when the tag is to
079: * appear in all locations.
080: */
081: public static final String ALL = "a";
082:
083: /**
084: * The name of this tag.
085: */
086: protected String tagName;
087:
088: /**
089: * The header to output.
090: */
091: protected String header;
092:
093: /**
094: * The possible locations that this tag can appear in.
095: */
096: protected String locations;
097:
098: /**
099: * Construct a <code>SimpleTaglet</code>.
100: * @param tagName the name of this tag
101: * @param header the header to output.
102: * @param locations the possible locations that this tag
103: * can appear in. The <code>String</code> can contain 'p'
104: * for package, 't' for type, 'm' for method, 'c' for constructor
105: * and 'f' for field.
106: */
107: public SimpleTaglet(String tagName, String header, String locations) {
108: this .tagName = tagName;
109: this .header = header;
110: locations = locations.toLowerCase();
111: if (locations.indexOf(ALL) != -1
112: && locations.indexOf(EXCLUDED) == -1) {
113: this .locations = PACKAGE + TYPE + FIELD + METHOD
114: + CONSTRUCTOR + OVERVIEW;
115: } else {
116: this .locations = locations;
117: }
118: }
119:
120: /**
121: * Return the name of this <code>Taglet</code>.
122: */
123: public String getName() {
124: return tagName;
125: }
126:
127: /**
128: * Return true if this <code>SimpleTaglet</code>
129: * is used in constructor documentation.
130: * @return true if this <code>SimpleTaglet</code>
131: * is used in constructor documentation and false
132: * otherwise.
133: */
134: public boolean inConstructor() {
135: return locations.indexOf(CONSTRUCTOR) != -1
136: && locations.indexOf(EXCLUDED) == -1;
137: }
138:
139: /**
140: * Return true if this <code>SimpleTaglet</code>
141: * is used in field documentation.
142: * @return true if this <code>SimpleTaglet</code>
143: * is used in field documentation and false
144: * otherwise.
145: */
146: public boolean inField() {
147: return locations.indexOf(FIELD) != -1
148: && locations.indexOf(EXCLUDED) == -1;
149: }
150:
151: /**
152: * Return true if this <code>SimpleTaglet</code>
153: * is used in method documentation.
154: * @return true if this <code>SimpleTaglet</code>
155: * is used in method documentation and false
156: * otherwise.
157: */
158: public boolean inMethod() {
159: return locations.indexOf(METHOD) != -1
160: && locations.indexOf(EXCLUDED) == -1;
161: }
162:
163: /**
164: * Return true if this <code>SimpleTaglet</code>
165: * is used in overview documentation.
166: * @return true if this <code>SimpleTaglet</code>
167: * is used in overview documentation and false
168: * otherwise.
169: */
170: public boolean inOverview() {
171: return locations.indexOf(OVERVIEW) != -1
172: && locations.indexOf(EXCLUDED) == -1;
173: }
174:
175: /**
176: * Return true if this <code>SimpleTaglet</code>
177: * is used in package documentation.
178: * @return true if this <code>SimpleTaglet</code>
179: * is used in package documentation and false
180: * otherwise.
181: */
182: public boolean inPackage() {
183: return locations.indexOf(PACKAGE) != -1
184: && locations.indexOf(EXCLUDED) == -1;
185: }
186:
187: /**
188: * Return true if this <code>SimpleTaglet</code>
189: * is used in type documentation (classes or interfaces).
190: * @return true if this <code>SimpleTaglet</code>
191: * is used in type documentation and false
192: * otherwise.
193: */
194: public boolean inType() {
195: return locations.indexOf(TYPE) != -1
196: && locations.indexOf(EXCLUDED) == -1;
197: }
198:
199: /**
200: * Return true if this <code>Taglet</code>
201: * is an inline tag.
202: * @return true if this <code>Taglet</code>
203: * is an inline tag and false otherwise.
204: */
205: public boolean isInlineTag() {
206: return false;
207: }
208:
209: /**
210: * {@inheritDoc}
211: */
212: public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) {
213: return header == null || tag == null ? null : writer
214: .simpleTagOutput(tag, header);
215: }
216:
217: /**
218: * {@inheritDoc}
219: */
220: public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
221: if (header == null || holder.tags(getName()).length == 0) {
222: return null;
223: }
224: return writer.simpleTagOutput(holder.tags(getName()), header);
225: }
226: }
|