src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SimpleTaglet.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

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

mercurial