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 */
25
26 package com.sun.tools.doclets.internal.toolkit.taglets;
27
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;
32
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 */
43
44 public class SimpleTaglet extends BaseTaglet implements InheritableTaglet {
45
46 /**
47 * The marker in the location string for excluded tags.
48 */
49 public static final String EXCLUDED = "x";
50
51 /**
52 * The marker in the location string for packages.
94 */
95 protected String header;
96
97 /**
98 * The possible locations that this tag can appear in.
99 */
100 protected String locations;
101
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.contains(ALL) && !locations.contains(EXCLUDED)) {
116 this.locations = PACKAGE + TYPE + FIELD + METHOD + CONSTRUCTOR + OVERVIEW;
117 } else {
118 this.locations = locations;
119 }
120 }
121
122 /**
123 * Return the name of this <code>Taglet</code>.
124 */
125 public String getName() {
126 return tagName;
127 }
128
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.
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.contains(TYPE) && !locations.contains(EXCLUDED);
193 }
194
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 }
204
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 }
215
216 /**
217 * {@inheritDoc}
218 */
219 public Content getTagletOutput(Tag tag, TagletWriter writer) {
220 return header == null || tag == null ? null : writer.simpleTagOutput(tag, header);
221 }
222
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 }
|
1 /*
2 * Copyright (c) 2001, 2015, 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 */
25
26 package jdk.javadoc.internal.doclets.toolkit.taglets;
27
28 import java.util.List;
29 import java.util.Locale;
30
31 import javax.lang.model.element.Element;
32
33 import com.sun.source.doctree.DocTree;
34
35 import jdk.javadoc.internal.doclets.toolkit.Content;
36 import jdk.javadoc.internal.doclets.toolkit.util.CommentHelper;
37 import jdk.javadoc.internal.doclets.toolkit.util.DocFinder;
38 import jdk.javadoc.internal.doclets.toolkit.util.Utils;
39
40 /**
41 * A simple single argument custom tag.
42 *
43 * <p><b>This is NOT part of any supported API.
44 * If you write code that depends on this, you do so at your own risk.
45 * This code and its internal interfaces are subject to change or
46 * deletion without notice.</b>
47 *
48 * @author Jamie Ho
49 */
50
51 public class SimpleTaglet extends BaseTaglet implements InheritableTaglet {
52
53 /**
54 * The marker in the location string for excluded tags.
55 */
56 public static final String EXCLUDED = "x";
57
58 /**
59 * The marker in the location string for packages.
101 */
102 protected String header;
103
104 /**
105 * The possible locations that this tag can appear in.
106 */
107 protected String locations;
108
109 /**
110 * Construct a <code>SimpleTaglet</code>.
111 * @param tagName the name of this tag
112 * @param header the header to output.
113 * @param locations the possible locations that this tag
114 * can appear in. The <code>String</code> can contain 'p'
115 * for package, 't' for type, 'm' for method, 'c' for constructor
116 * and 'f' for field.
117 */
118 public SimpleTaglet(String tagName, String header, String locations) {
119 this.tagName = tagName;
120 this.header = header;
121 locations = Utils.toLowerCase(locations);
122 if (locations.contains(ALL) && !locations.contains(EXCLUDED)) {
123 this.locations = PACKAGE + TYPE + FIELD + METHOD + CONSTRUCTOR + OVERVIEW;
124 } else {
125 this.locations = locations;
126 }
127 }
128
129 /**
130 * Return the name of this <code>Taglet</code>.
131 */
132 public String getName() {
133 return tagName;
134 }
135
136 /**
137 * Return true if this <code>SimpleTaglet</code>
138 * is used in constructor documentation.
139 * @return true if this <code>SimpleTaglet</code>
140 * is used in constructor documentation and false
141 * otherwise.
194 * @return true if this <code>SimpleTaglet</code>
195 * is used in type documentation and false
196 * otherwise.
197 */
198 public boolean inType() {
199 return locations.contains(TYPE) && !locations.contains(EXCLUDED);
200 }
201
202 /**
203 * Return true if this <code>Taglet</code>
204 * is an inline tag.
205 * @return true if this <code>Taglet</code>
206 * is an inline tag and false otherwise.
207 */
208 public boolean isInlineTag() {
209 return false;
210 }
211
212 @Override
213 public void inherit(DocFinder.Input input, DocFinder.Output output) {
214 List<? extends DocTree> tags = input.utils.getBlockTags(input.element, tagName);
215 if (!tags.isEmpty()) {
216 output.holder = input.element;
217 output.holderTag = tags.get(0);
218 CommentHelper ch = input.utils.getCommentHelper(output.holder);
219 output.inlineTags = input.isFirstSentence
220 ? ch.getFirstSentenceTrees(input.utils.configuration, output.holderTag)
221 : ch.getTags(input.utils.configuration, output.holderTag);
222 }
223 }
224
225 /**
226 * {@inheritDoc}
227 */
228 public Content getTagletOutput(Element element, DocTree tag, TagletWriter writer) {
229 return header == null || tag == null ? null : writer.simpleTagOutput(element, tag, header);
230 }
231
232 /**
233 * {@inheritDoc}
234 */
235 public Content getTagletOutput(Element holder, TagletWriter writer) {
236 Utils utils = writer.configuration().utils;
237 List<? extends DocTree> tags = utils.getBlockTags(holder, getName());
238 if (header == null || tags.isEmpty()) {
239 return null;
240 }
241 return writer.simpleTagOutput(holder, tags, header);
242 }
243 }
|