duke@1: /* ohair@554: * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved. duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: * duke@1: * This code is free software; you can redistribute it and/or modify it duke@1: * under the terms of the GNU General Public License version 2 only, as ohair@554: * published by the Free Software Foundation. Oracle designates this duke@1: * particular file as subject to the "Classpath" exception as provided ohair@554: * by Oracle in the LICENSE file that accompanied this code. duke@1: * duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: * version 2 for more details (a copy is included in the LICENSE file that duke@1: * accompanied this code). duke@1: * duke@1: * You should have received a copy of the GNU General Public License version duke@1: * 2 along with this work; if not, write to the Free Software Foundation, duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. duke@1: */ duke@1: duke@1: package com.sun.tools.javadoc; duke@1: duke@1: import com.sun.javadoc.*; duke@1: duke@1: /** duke@1: * Represents a documentation tag, e.g. @since, @author, @version. duke@1: * Given a tag (e.g. "@since 1.2"), holds tag name (e.g. "@since") duke@1: * and tag text (e.g. "1.2"). TagImpls with structure or which require duke@1: * special processing are handled by subclasses (ParamTagImpl, SeeTagImpl, duke@1: * and ThrowsTagImpl duke@1: * duke@1: * @author Robert Field duke@1: * @author Atul M Dambalkar duke@1: * @author Neal M Gafter duke@1: * @see SeeTagImpl duke@1: * @see ParamTagImpl duke@1: * @see ThrowsTagImpl duke@1: * @see Doc#tags() duke@1: * duke@1: */ duke@1: class TagImpl implements Tag { duke@1: duke@1: protected final String text; duke@1: protected final String name; duke@1: protected final DocImpl holder; duke@1: duke@1: /** duke@1: * Cached first sentence. duke@1: */ duke@1: private Tag[] firstSentence; duke@1: duke@1: /** duke@1: * Cached inline tags. duke@1: */ duke@1: private Tag[] inlineTags; duke@1: duke@1: /** duke@1: * Constructor duke@1: */ duke@1: TagImpl(DocImpl holder, String name, String text) { duke@1: this.holder = holder; duke@1: this.name = name; duke@1: this.text = text; duke@1: } duke@1: duke@1: /** duke@1: * Return the name of this tag. duke@1: */ duke@1: public String name() { duke@1: return name; duke@1: } duke@1: duke@1: /** duke@1: * Return the containing {@link Doc} of this Tag element. duke@1: */ duke@1: public Doc holder() { duke@1: return holder; duke@1: } duke@1: duke@1: /** duke@1: * Return the kind of this tag. duke@1: */ duke@1: public String kind() { duke@1: return name; duke@1: } duke@1: duke@1: /** duke@1: * Return the text of this tag, that is, portion beyond tag name. duke@1: */ duke@1: public String text() { duke@1: return text; duke@1: } duke@1: duke@1: DocEnv docenv() { duke@1: return holder.env; duke@1: } duke@1: duke@1: /** duke@1: * for use by subclasses which have two part tag text. duke@1: */ duke@1: String[] divideAtWhite() { duke@1: String[] sa = new String[2]; duke@1: int len = text.length(); duke@1: // if no white space found duke@1: sa[0] = text; duke@1: sa[1] = ""; duke@1: for (int inx = 0; inx < len; ++inx) { duke@1: char ch = text.charAt(inx); duke@1: if (Character.isWhitespace(ch)) { duke@1: sa[0] = text.substring(0, inx); duke@1: for (; inx < len; ++inx) { duke@1: ch = text.charAt(inx); duke@1: if (!Character.isWhitespace(ch)) { duke@1: sa[1] = text.substring(inx, len); duke@1: break; duke@1: } duke@1: } duke@1: break; duke@1: } duke@1: } duke@1: return sa; duke@1: } duke@1: duke@1: /** duke@1: * convert this object to a string. duke@1: */ duke@1: public String toString() { duke@1: return name + ":" + text; duke@1: } duke@1: duke@1: /** duke@1: * For documentation comment with embedded @link tags, return the array of duke@1: * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s). duke@1: * Within a comment string "This is an example of inline tags for a duke@1: * documentation comment {@link Doc {@link Doc commentlabel}}", duke@1: * where inside the inner braces, the first "Doc" carries exctly the same duke@1: * syntax as a SeeTagImpl and the second "commentlabel" is label for the Html duke@1: * Link, will return an array of TagImpl(s) with first element as TagImpl with duke@1: * comment text "This is an example of inline tags for a documentation duke@1: * comment" and second element as SeeTagImpl with referenced class as "Doc" duke@1: * and the label for the Html Link as "commentlabel". duke@1: * duke@1: * @return TagImpl[] Array of tags with inline SeeTagImpls. duke@1: * @see ParamTagImpl duke@1: * @see ThrowsTagImpl duke@1: */ duke@1: public Tag[] inlineTags() { duke@1: if (inlineTags == null) { duke@1: inlineTags = Comment.getInlineTags(holder, text); duke@1: } duke@1: return inlineTags; duke@1: } duke@1: duke@1: /** duke@1: * Return array of tags for the first sentence in the doc comment text. duke@1: */ duke@1: public Tag[] firstSentenceTags() { duke@1: if (firstSentence == null) { duke@1: //Parse all sentences first to avoid duplicate warnings. duke@1: inlineTags(); duke@1: try { duke@1: docenv().setSilent(true); duke@1: firstSentence = Comment.firstSentenceTags(holder, text); duke@1: } finally { duke@1: docenv().setSilent(false); duke@1: } duke@1: } duke@1: return firstSentence; duke@1: } duke@1: duke@1: /** duke@1: * Return the doc item to which this tag is attached. duke@1: * @return the doc item to which this tag is attached. duke@1: */ duke@1: public SourcePosition position() { duke@1: return holder.position(); duke@1: } duke@1: }