Fri, 03 May 2013 17:44:38 -0700
8008768: Using {@inheritDoc} in simple tag defined via -tag fails
Reviewed-by: jjg, mduigou
Contributed-by: jonathan.gibbons@oracle.com, mike.duigou@oracle.com
1 /*
2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.doclets.internal.toolkit.taglets;
28 import com.sun.javadoc.*;
29 import com.sun.tools.doclets.internal.toolkit.util.DocFinder;
31 /**
32 * A simple single argument custom tag.
33 *
34 * <p><b>This is NOT part of any supported API.
35 * If you write code that depends on this, you do so at your own risk.
36 * This code and its internal interfaces are subject to change or
37 * deletion without notice.</b>
38 *
39 * @author Jamie Ho
40 */
42 public class SimpleTaglet extends BaseTaglet implements InheritableTaglet {
44 /**
45 * The marker in the location string for excluded tags.
46 */
47 public static final String EXCLUDED = "x";
49 /**
50 * The marker in the location string for packages.
51 */
52 public static final String PACKAGE = "p";
54 /**
55 * The marker in the location string for types.
56 */
57 public static final String TYPE = "t";
59 /**
60 * The marker in the location string for constructors.
61 */
62 public static final String CONSTRUCTOR = "c";
64 /**
65 * The marker in the location string for fields.
66 */
67 public static final String FIELD = "f";
69 /**
70 * The marker in the location string for methods.
71 */
72 public static final String METHOD = "m";
74 /**
75 * The marker in the location string for overview.
76 */
77 public static final String OVERVIEW = "o";
79 /**
80 * Use in location string when the tag is to
81 * appear in all locations.
82 */
83 public static final String ALL = "a";
85 /**
86 * The name of this tag.
87 */
88 protected String tagName;
90 /**
91 * The header to output.
92 */
93 protected String header;
95 /**
96 * The possible locations that this tag can appear in.
97 */
98 protected String locations;
100 /**
101 * Construct a <code>SimpleTaglet</code>.
102 * @param tagName the name of this tag
103 * @param header the header to output.
104 * @param locations the possible locations that this tag
105 * can appear in. The <code>String</code> can contain 'p'
106 * for package, 't' for type, 'm' for method, 'c' for constructor
107 * and 'f' for field.
108 */
109 public SimpleTaglet(String tagName, String header, String locations) {
110 this.tagName = tagName;
111 this.header = header;
112 locations = locations.toLowerCase();
113 if (locations.indexOf(ALL) != -1 && locations.indexOf(EXCLUDED) == -1) {
114 this.locations = PACKAGE + TYPE + FIELD + METHOD + CONSTRUCTOR + OVERVIEW;
115 } else {
116 this.locations = locations;
117 }
118 }
120 /**
121 * Return the name of this <code>Taglet</code>.
122 */
123 public String getName() {
124 return tagName;
125 }
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 && locations.indexOf(EXCLUDED) == -1;
136 }
138 /**
139 * Return true if this <code>SimpleTaglet</code>
140 * is used in field documentation.
141 * @return true if this <code>SimpleTaglet</code>
142 * is used in field documentation and false
143 * otherwise.
144 */
145 public boolean inField() {
146 return locations.indexOf(FIELD) != -1 && locations.indexOf(EXCLUDED) == -1;
147 }
149 /**
150 * Return true if this <code>SimpleTaglet</code>
151 * is used in method documentation.
152 * @return true if this <code>SimpleTaglet</code>
153 * is used in method documentation and false
154 * otherwise.
155 */
156 public boolean inMethod() {
157 return locations.indexOf(METHOD) != -1 && locations.indexOf(EXCLUDED) == -1;
158 }
160 /**
161 * Return true if this <code>SimpleTaglet</code>
162 * is used in overview documentation.
163 * @return true if this <code>SimpleTaglet</code>
164 * is used in overview documentation and false
165 * otherwise.
166 */
167 public boolean inOverview() {
168 return locations.indexOf(OVERVIEW) != -1 && locations.indexOf(EXCLUDED) == -1;
169 }
171 /**
172 * Return true if this <code>SimpleTaglet</code>
173 * is used in package documentation.
174 * @return true if this <code>SimpleTaglet</code>
175 * is used in package documentation and false
176 * otherwise.
177 */
178 public boolean inPackage() {
179 return locations.indexOf(PACKAGE) != -1 && locations.indexOf(EXCLUDED) == -1;
180 }
182 /**
183 * Return true if this <code>SimpleTaglet</code>
184 * is used in type documentation (classes or interfaces).
185 * @return true if this <code>SimpleTaglet</code>
186 * is used in type documentation and false
187 * otherwise.
188 */
189 public boolean inType() {
190 return locations.indexOf(TYPE) != -1&& locations.indexOf(EXCLUDED) == -1;
191 }
193 /**
194 * Return true if this <code>Taglet</code>
195 * is an inline tag.
196 * @return true if this <code>Taglet</code>
197 * is an inline tag and false otherwise.
198 */
199 public boolean isInlineTag() {
200 return false;
201 }
203 @Override
204 public void inherit(DocFinder.Input input, DocFinder.Output output) {
205 Tag[] tags = input.element.tags(tagName);
206 if (tags.length > 0) {
207 output.holder = input.element;
208 output.holderTag = tags[0];
209 output.inlineTags = input.isFirstSentence
210 ? tags[0].firstSentenceTags() : tags[0].inlineTags();
211 }
212 }
214 /**
215 * {@inheritDoc}
216 */
217 public TagletOutput getTagletOutput(Tag tag, TagletWriter writer) {
218 return header == null || tag == null ? null : writer.simpleTagOutput(tag, header);
219 }
221 /**
222 * {@inheritDoc}
223 */
224 public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) {
225 if (header == null || holder.tags(getName()).length == 0) {
226 return null;
227 }
228 return writer.simpleTagOutput(holder.tags(getName()), header);
229 }
230 }