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

Mon, 25 Mar 2013 16:55:14 -0700

author
mfang
date
Mon, 25 Mar 2013 16:55:14 -0700
changeset 1658
fdf30b225e1c
parent 1359
25e14ad23cef
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8010521: jdk8 l10n resource file translation update 2
Reviewed-by: naoto, yhuang

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

mercurial