Sat, 07 Nov 2020 10:30:02 +0800
Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe
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.Content;
30 import com.sun.tools.doclets.internal.toolkit.util.DocFinder;
31 import com.sun.tools.javac.util.StringUtils;
33 /**
34 * A simple single argument custom tag.
35 *
36 * <p><b>This is NOT part of any supported API.
37 * If you write code that depends on this, you do so at your own risk.
38 * This code and its internal interfaces are subject to change or
39 * deletion without notice.</b>
40 *
41 * @author Jamie Ho
42 */
44 public class SimpleTaglet extends BaseTaglet implements InheritableTaglet {
46 /**
47 * The marker in the location string for excluded tags.
48 */
49 public static final String EXCLUDED = "x";
51 /**
52 * The marker in the location string for packages.
53 */
54 public static final String PACKAGE = "p";
56 /**
57 * The marker in the location string for types.
58 */
59 public static final String TYPE = "t";
61 /**
62 * The marker in the location string for constructors.
63 */
64 public static final String CONSTRUCTOR = "c";
66 /**
67 * The marker in the location string for fields.
68 */
69 public static final String FIELD = "f";
71 /**
72 * The marker in the location string for methods.
73 */
74 public static final String METHOD = "m";
76 /**
77 * The marker in the location string for overview.
78 */
79 public static final String OVERVIEW = "o";
81 /**
82 * Use in location string when the tag is to
83 * appear in all locations.
84 */
85 public static final String ALL = "a";
87 /**
88 * The name of this tag.
89 */
90 protected String tagName;
92 /**
93 * The header to output.
94 */
95 protected String header;
97 /**
98 * The possible locations that this tag can appear in.
99 */
100 protected String locations;
102 /**
103 * Construct a <code>SimpleTaglet</code>.
104 * @param tagName the name of this tag
105 * @param header the header to output.
106 * @param locations the possible locations that this tag
107 * can appear in. The <code>String</code> can contain 'p'
108 * for package, 't' for type, 'm' for method, 'c' for constructor
109 * and 'f' for field.
110 */
111 public SimpleTaglet(String tagName, String header, String locations) {
112 this.tagName = tagName;
113 this.header = header;
114 locations = StringUtils.toLowerCase(locations);
115 if (locations.indexOf(ALL) != -1 && locations.indexOf(EXCLUDED) == -1) {
116 this.locations = PACKAGE + TYPE + FIELD + METHOD + CONSTRUCTOR + OVERVIEW;
117 } else {
118 this.locations = locations;
119 }
120 }
122 /**
123 * Return the name of this <code>Taglet</code>.
124 */
125 public String getName() {
126 return tagName;
127 }
129 /**
130 * Return true if this <code>SimpleTaglet</code>
131 * is used in constructor documentation.
132 * @return true if this <code>SimpleTaglet</code>
133 * is used in constructor documentation and false
134 * otherwise.
135 */
136 public boolean inConstructor() {
137 return locations.indexOf(CONSTRUCTOR) != -1 && locations.indexOf(EXCLUDED) == -1;
138 }
140 /**
141 * Return true if this <code>SimpleTaglet</code>
142 * is used in field documentation.
143 * @return true if this <code>SimpleTaglet</code>
144 * is used in field documentation and false
145 * otherwise.
146 */
147 public boolean inField() {
148 return locations.indexOf(FIELD) != -1 && locations.indexOf(EXCLUDED) == -1;
149 }
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 && locations.indexOf(EXCLUDED) == -1;
160 }
162 /**
163 * Return true if this <code>SimpleTaglet</code>
164 * is used in overview documentation.
165 * @return true if this <code>SimpleTaglet</code>
166 * is used in overview documentation and false
167 * otherwise.
168 */
169 public boolean inOverview() {
170 return locations.indexOf(OVERVIEW) != -1 && locations.indexOf(EXCLUDED) == -1;
171 }
173 /**
174 * Return true if this <code>SimpleTaglet</code>
175 * is used in package documentation.
176 * @return true if this <code>SimpleTaglet</code>
177 * is used in package documentation and false
178 * otherwise.
179 */
180 public boolean inPackage() {
181 return locations.indexOf(PACKAGE) != -1 && locations.indexOf(EXCLUDED) == -1;
182 }
184 /**
185 * Return true if this <code>SimpleTaglet</code>
186 * is used in type documentation (classes or interfaces).
187 * @return true if this <code>SimpleTaglet</code>
188 * is used in type documentation and false
189 * otherwise.
190 */
191 public boolean inType() {
192 return locations.indexOf(TYPE) != -1&& locations.indexOf(EXCLUDED) == -1;
193 }
195 /**
196 * Return true if this <code>Taglet</code>
197 * is an inline tag.
198 * @return true if this <code>Taglet</code>
199 * is an inline tag and false otherwise.
200 */
201 public boolean isInlineTag() {
202 return false;
203 }
205 @Override
206 public void inherit(DocFinder.Input input, DocFinder.Output output) {
207 Tag[] tags = input.element.tags(tagName);
208 if (tags.length > 0) {
209 output.holder = input.element;
210 output.holderTag = tags[0];
211 output.inlineTags = input.isFirstSentence
212 ? tags[0].firstSentenceTags() : tags[0].inlineTags();
213 }
214 }
216 /**
217 * {@inheritDoc}
218 */
219 public Content getTagletOutput(Tag tag, TagletWriter writer) {
220 return header == null || tag == null ? null : writer.simpleTagOutput(tag, header);
221 }
223 /**
224 * {@inheritDoc}
225 */
226 public Content getTagletOutput(Doc holder, TagletWriter writer) {
227 if (header == null || holder.tags(getName()).length == 0) {
228 return null;
229 }
230 return writer.simpleTagOutput(holder.tags(getName()), header);
231 }
232 }