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