src/share/classes/com/sun/tools/javadoc/TagImpl.java

Thu, 31 Aug 2017 15:17:03 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:17:03 +0800
changeset 2525
2eb010b6cb22
parent 1359
25e14ad23cef
parent 0
959103a6100f
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2012, 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.javadoc;
aoqi@0 27
aoqi@0 28 import com.sun.javadoc.*;
aoqi@0 29
aoqi@0 30 /**
aoqi@0 31 * Represents a documentation tag, e.g. @since, @author, @version.
aoqi@0 32 * Given a tag (e.g. "@since 1.2"), holds tag name (e.g. "@since")
aoqi@0 33 * and tag text (e.g. "1.2"). TagImpls with structure or which require
aoqi@0 34 * special processing are handled by subclasses (ParamTagImpl, SeeTagImpl,
aoqi@0 35 * and ThrowsTagImpl
aoqi@0 36 *
aoqi@0 37 * <p><b>This is NOT part of any supported API.
aoqi@0 38 * If you write code that depends on this, you do so at your own risk.
aoqi@0 39 * This code and its internal interfaces are subject to change or
aoqi@0 40 * deletion without notice.</b>
aoqi@0 41 *
aoqi@0 42 * @author Robert Field
aoqi@0 43 * @author Atul M Dambalkar
aoqi@0 44 * @author Neal M Gafter
aoqi@0 45 * @see SeeTagImpl
aoqi@0 46 * @see ParamTagImpl
aoqi@0 47 * @see ThrowsTagImpl
aoqi@0 48 * @see Doc#tags()
aoqi@0 49 *
aoqi@0 50 */
aoqi@0 51 class TagImpl implements Tag {
aoqi@0 52
aoqi@0 53 protected final String text;
aoqi@0 54 protected final String name;
aoqi@0 55 protected final DocImpl holder;
aoqi@0 56
aoqi@0 57 /**
aoqi@0 58 * Cached first sentence.
aoqi@0 59 */
aoqi@0 60 private Tag[] firstSentence;
aoqi@0 61
aoqi@0 62 /**
aoqi@0 63 * Cached inline tags.
aoqi@0 64 */
aoqi@0 65 private Tag[] inlineTags;
aoqi@0 66
aoqi@0 67 /**
aoqi@0 68 * Constructor
aoqi@0 69 */
aoqi@0 70 TagImpl(DocImpl holder, String name, String text) {
aoqi@0 71 this.holder = holder;
aoqi@0 72 this.name = name;
aoqi@0 73 this.text = text;
aoqi@0 74 }
aoqi@0 75
aoqi@0 76 /**
aoqi@0 77 * Return the name of this tag.
aoqi@0 78 */
aoqi@0 79 public String name() {
aoqi@0 80 return name;
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 /**
aoqi@0 84 * Return the containing {@link Doc} of this Tag element.
aoqi@0 85 */
aoqi@0 86 public Doc holder() {
aoqi@0 87 return holder;
aoqi@0 88 }
aoqi@0 89
aoqi@0 90 /**
aoqi@0 91 * Return the kind of this tag.
aoqi@0 92 */
aoqi@0 93 public String kind() {
aoqi@0 94 return name;
aoqi@0 95 }
aoqi@0 96
aoqi@0 97 /**
aoqi@0 98 * Return the text of this tag, that is, portion beyond tag name.
aoqi@0 99 */
aoqi@0 100 public String text() {
aoqi@0 101 return text;
aoqi@0 102 }
aoqi@0 103
aoqi@0 104 DocEnv docenv() {
aoqi@0 105 return holder.env;
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 /**
aoqi@0 109 * for use by subclasses which have two part tag text.
aoqi@0 110 */
aoqi@0 111 String[] divideAtWhite() {
aoqi@0 112 String[] sa = new String[2];
aoqi@0 113 int len = text.length();
aoqi@0 114 // if no white space found
aoqi@0 115 sa[0] = text;
aoqi@0 116 sa[1] = "";
aoqi@0 117 for (int inx = 0; inx < len; ++inx) {
aoqi@0 118 char ch = text.charAt(inx);
aoqi@0 119 if (Character.isWhitespace(ch)) {
aoqi@0 120 sa[0] = text.substring(0, inx);
aoqi@0 121 for (; inx < len; ++inx) {
aoqi@0 122 ch = text.charAt(inx);
aoqi@0 123 if (!Character.isWhitespace(ch)) {
aoqi@0 124 sa[1] = text.substring(inx, len);
aoqi@0 125 break;
aoqi@0 126 }
aoqi@0 127 }
aoqi@0 128 break;
aoqi@0 129 }
aoqi@0 130 }
aoqi@0 131 return sa;
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 /**
aoqi@0 135 * convert this object to a string.
aoqi@0 136 */
aoqi@0 137 public String toString() {
aoqi@0 138 return name + ":" + text;
aoqi@0 139 }
aoqi@0 140
aoqi@0 141 /**
aoqi@0 142 * For documentation comment with embedded @link tags, return the array of
aoqi@0 143 * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s).
aoqi@0 144 * Within a comment string "This is an example of inline tags for a
aoqi@0 145 * documentation comment {@link Doc {@link Doc commentlabel}}",
aoqi@0 146 * where inside the inner braces, the first "Doc" carries exctly the same
aoqi@0 147 * syntax as a SeeTagImpl and the second "commentlabel" is label for the Html
aoqi@0 148 * Link, will return an array of TagImpl(s) with first element as TagImpl with
aoqi@0 149 * comment text "This is an example of inline tags for a documentation
aoqi@0 150 * comment" and second element as SeeTagImpl with referenced class as "Doc"
aoqi@0 151 * and the label for the Html Link as "commentlabel".
aoqi@0 152 *
aoqi@0 153 * @return TagImpl[] Array of tags with inline SeeTagImpls.
aoqi@0 154 * @see ParamTagImpl
aoqi@0 155 * @see ThrowsTagImpl
aoqi@0 156 */
aoqi@0 157 public Tag[] inlineTags() {
aoqi@0 158 if (inlineTags == null) {
aoqi@0 159 inlineTags = Comment.getInlineTags(holder, text);
aoqi@0 160 }
aoqi@0 161 return inlineTags;
aoqi@0 162 }
aoqi@0 163
aoqi@0 164 /**
aoqi@0 165 * Return array of tags for the first sentence in the doc comment text.
aoqi@0 166 */
aoqi@0 167 public Tag[] firstSentenceTags() {
aoqi@0 168 if (firstSentence == null) {
aoqi@0 169 //Parse all sentences first to avoid duplicate warnings.
aoqi@0 170 inlineTags();
aoqi@0 171 try {
aoqi@0 172 docenv().setSilent(true);
aoqi@0 173 firstSentence = Comment.firstSentenceTags(holder, text);
aoqi@0 174 } finally {
aoqi@0 175 docenv().setSilent(false);
aoqi@0 176 }
aoqi@0 177 }
aoqi@0 178 return firstSentence;
aoqi@0 179 }
aoqi@0 180
aoqi@0 181 /**
aoqi@0 182 * Return the doc item to which this tag is attached.
aoqi@0 183 * @return the doc item to which this tag is attached.
aoqi@0 184 */
aoqi@0 185 public SourcePosition position() {
aoqi@0 186 return holder.position();
aoqi@0 187 }
aoqi@0 188 }

mercurial