langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/TagImpl.java
author jjg
Fri, 27 May 2016 13:06:58 -0700
changeset 38617 d93a7f64e231
parent 37938 42baa89d2156
permissions -rw-r--r--
8157606: deprecate com.sun.javadoc API Reviewed-by: ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
     2
 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 10
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
37938
42baa89d2156 8075703: jdk.javadoc module exports com.sun.tools.javadoc package which contains a lot of internal API.
jjg
parents: 25874
diff changeset
    26
package com.sun.tools.javadoc.main;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.javadoc.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
 * Represents a documentation tag, e.g. @since, @author, @version.
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 * Given a tag (e.g. "@since 1.2"), holds tag name (e.g. "@since")
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * and tag text (e.g. "1.2").  TagImpls with structure or which require
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * special processing are handled by subclasses (ParamTagImpl, SeeTagImpl,
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * and ThrowsTagImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    37
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    38
 *  If you write code that depends on this, you do so at your own risk.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    39
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    40
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 5520
diff changeset
    41
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * @author Robert Field
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * @author Neal M Gafter
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * @see SeeTagImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * @see ParamTagImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * @see ThrowsTagImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * @see Doc#tags()
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 */
38617
d93a7f64e231 8157606: deprecate com.sun.javadoc API
jjg
parents: 37938
diff changeset
    51
@Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
class TagImpl implements Tag {
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    protected final String text;
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    protected final String name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    protected final DocImpl holder;
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * Cached first sentence.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    private Tag[] firstSentence;
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * Cached inline tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    private Tag[] inlineTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     *  Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    TagImpl(DocImpl holder, String name, String text) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        this.holder = holder;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        this.text = text;
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     * Return the name of this tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    public String name() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     * Return the containing {@link Doc} of this Tag element.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    public Doc holder() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        return holder;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     * Return the kind of this tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    public String kind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     * Return the text of this tag, that is, portion beyond tag name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    public String text() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        return text;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    DocEnv docenv() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        return holder.env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * for use by subclasses which have two part tag text.
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    String[] divideAtWhite() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        String[] sa = new String[2];
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        int len = text.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        // if no white space found
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
        sa[0] = text;
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        sa[1] = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        for (int inx = 0; inx < len; ++inx) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
            char ch = text.charAt(inx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            if (Character.isWhitespace(ch)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
                sa[0] = text.substring(0, inx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
                for (; inx < len; ++inx) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
                    ch = text.charAt(inx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
                    if (!Character.isWhitespace(ch)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                        sa[1] = text.substring(inx, len);
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        return sa;
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     * convert this object to a string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        return name + ":" + text;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * For documentation comment with embedded @link tags, return the array of
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     * TagImpls consisting of SeeTagImpl(s) and text containing TagImpl(s).
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     * Within a comment string "This is an example of inline tags for a
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * documentation comment {@link Doc {@link Doc commentlabel}}",
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     * where inside the inner braces, the first "Doc" carries exctly the same
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     * syntax as a SeeTagImpl and the second "commentlabel" is label for the Html
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     * Link, will return an array of TagImpl(s) with first element as TagImpl with
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * comment text "This is an example of inline tags for a documentation
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     * comment" and second element as SeeTagImpl with referenced class as "Doc"
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     * and the label for the Html Link as "commentlabel".
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     * @return TagImpl[] Array of tags with inline SeeTagImpls.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * @see ParamTagImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     * @see ThrowsTagImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    public Tag[] inlineTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        if (inlineTags == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            inlineTags = Comment.getInlineTags(holder, text);
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        return inlineTags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * Return array of tags for the first sentence in the doc comment text.
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    public Tag[] firstSentenceTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        if (firstSentence == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
            //Parse all sentences first to avoid duplicate warnings.
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
            inlineTags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                docenv().setSilent(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
                firstSentence = Comment.firstSentenceTags(holder, text);
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                docenv().setSilent(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        return firstSentence;
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * Return the doc item to which this tag is attached.
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     * @return the doc item to which this tag is attached.
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    public SourcePosition position() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        return holder.position();
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
}