langtools/src/share/classes/com/sun/tools/javadoc/Comment.java
author ksrini
Fri, 05 Aug 2011 19:41:05 -0700
changeset 10203 cca843a7d258
parent 5520 86e4b9a9da40
child 13844 56339cf983a3
permissions -rw-r--r--
7064544: (javadoc) miscellaneous fixes requested by netbeans Summary: Contributed by netbeans team, modified to suit by the langtools team. Reviewed-by: jjg, bpatel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
10203
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 5520
diff changeset
     2
 * Copyright (c) 1997, 2011, 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: 2212
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: 2212
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: 2212
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2212
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javadoc;
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
import com.sun.tools.javac.util.ListBuffer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 * Comment contains all information in comment part.
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 *      It allows users to get first sentence of this comment, get
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 *      comment for different tags...
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * @author Kaiyang Liu (original)
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * @author Robert Field (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
class Comment {
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
     * sorted comments with different tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    private final ListBuffer<Tag> tagList = new ListBuffer<Tag>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
     * text minus any tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    private String text;
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
     * Doc environment
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    private final DocEnv docenv;
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
     * constructor of Comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    Comment(final DocImpl holder, final String commentString) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
        this.docenv = holder.env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
         * Separate the comment into the text part and zero to N tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
         * Simple state machine is in one of three states:
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
         * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
         * IN_TEXT: parsing the comment text or tag text.
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
         * TAG_NAME: parsing the name of a tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
         * TAG_GAP: skipping through the gap between the tag name and
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
         * the tag text.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
         * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
         */
1870
57a1138dffc8 6795903: fix latent build warnings in langtools repository
jjg
parents: 10
diff changeset
    74
        @SuppressWarnings("fallthrough")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
        class CommentStringParser {
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
            /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
             * The entry point to the comment string parser
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
             */
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
            void parseCommentStateMachine() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
                final int IN_TEXT = 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
                final int TAG_GAP = 2;
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
                final int TAG_NAME = 3;
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
                int state = TAG_GAP;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
                boolean newLine = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
                String tagName = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
                int tagStart = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
                int textStart = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
                int lastNonWhite = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
                int len = commentString.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
                for (int inx = 0; inx < len; ++inx) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
                    char ch = commentString.charAt(inx);
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
                    boolean isWhite = Character.isWhitespace(ch);
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
                    switch (state)  {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
                        case TAG_NAME:
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
                            if (isWhite) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
                                tagName = commentString.substring(tagStart, inx);
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
                                state = TAG_GAP;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
                            break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
                        case TAG_GAP:
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                            if (isWhite) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
                                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
                            textStart = inx;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
                            state = IN_TEXT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
                            /* fall thru */
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
                        case IN_TEXT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
                            if (newLine && ch == '@') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
                                parseCommentComponent(tagName, textStart,
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
                                                      lastNonWhite+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
                                tagStart = inx;
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
                                state = TAG_NAME;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
                            break;
10203
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 5520
diff changeset
   115
                    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
                    if (ch == '\n') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                        newLine = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
                    } else if (!isWhite) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
                        lastNonWhite = inx;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
                        newLine = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
                // Finish what's currently being processed
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
                switch (state)  {
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
                    case TAG_NAME:
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
                        tagName = commentString.substring(tagStart, len);
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
                        /* fall thru */
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
                    case TAG_GAP:
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
                        textStart = len;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
                        /* fall thru */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
                    case IN_TEXT:
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
                        parseCommentComponent(tagName, textStart, lastNonWhite+1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
                        break;
10203
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 5520
diff changeset
   134
                }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
            /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
             * Save away the last parsed item.
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
             */
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            void parseCommentComponent(String tagName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
                                       int from, int upto) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
                String tx = upto <= from ? "" : commentString.substring(from, upto);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
                if (tagName == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
                    text = tx;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
                    TagImpl tag;
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
                    if (tagName.equals("@exception") || tagName.equals("@throws")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
                        warnIfEmpty(tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
                        tag = new ThrowsTagImpl(holder, tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
                    } else if (tagName.equals("@param")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
                        warnIfEmpty(tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
                        tag = new ParamTagImpl(holder, tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
                    } else if (tagName.equals("@see")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
                        warnIfEmpty(tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
                        tag = new SeeTagImpl(holder, tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
                    } else if (tagName.equals("@serialField")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                        warnIfEmpty(tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
                        tag = new SerialFieldTagImpl(holder, tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
                    } else if (tagName.equals("@return")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
                        warnIfEmpty(tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
                        tag = new TagImpl(holder, tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
                    } else if (tagName.equals("@author")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
                        warnIfEmpty(tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
                        tag = new TagImpl(holder, tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
                    } else if (tagName.equals("@version")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
                        warnIfEmpty(tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
                        tag = new TagImpl(holder, tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
                        tag = new TagImpl(holder, tagName, tx);
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
                    tagList.append(tag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
            void warnIfEmpty(String tagName, String tx) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                if (tx.length() == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
                    docenv.warning(holder, "tag.tag_has_no_arguments", tagName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
            }
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
        new CommentStringParser().parseCommentStateMachine();
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     * Return the text of the comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    String commentText() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
        return text;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     * Return all tags in this comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    Tag[] tags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        return tagList.toArray(new Tag[tagList.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     * Return tags of the specified kind in this comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    Tag[] tags(String tagname) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        ListBuffer<Tag> found = new ListBuffer<Tag>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        String target = tagname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        if (target.charAt(0) != '@') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
            target = "@" + target;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        for (Tag tag : tagList) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            if (tag.kind().equals(target)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                found.append(tag);
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        return found.toArray(new Tag[found.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * Return throws tags in this comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
    ThrowsTag[] throwsTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        ListBuffer<ThrowsTag> found = new ListBuffer<ThrowsTag>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
        for (Tag next : tagList) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
            if (next instanceof ThrowsTag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
                found.append((ThrowsTag)next);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        return found.toArray(new ThrowsTag[found.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     * Return param tags (excluding type param tags) in this comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    ParamTag[] paramTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        return paramTags(false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     * Return type param tags in this comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    ParamTag[] typeParamTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
        return paramTags(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     * Return param tags in this comment.  If typeParams is true
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
     * include only type param tags, otherwise include only ordinary
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     * param tags.
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    private ParamTag[] paramTags(boolean typeParams) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        ListBuffer<ParamTag> found = new ListBuffer<ParamTag>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
        for (Tag next : tagList) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
            if (next instanceof ParamTag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                ParamTag p = (ParamTag)next;
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
                if (typeParams == p.isTypeParameter()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
                    found.append(p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        return found.toArray(new ParamTag[found.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     * Return see also tags in this comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    SeeTag[] seeTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        ListBuffer<SeeTag> found = new ListBuffer<SeeTag>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        for (Tag next : tagList) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
            if (next instanceof SeeTag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                found.append((SeeTag)next);
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        return found.toArray(new SeeTag[found.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     * Return serialField tags in this comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    SerialFieldTag[] serialFieldTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        ListBuffer<SerialFieldTag> found = new ListBuffer<SerialFieldTag>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        for (Tag next : tagList) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            if (next instanceof SerialFieldTag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
                found.append((SerialFieldTag)next);
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        return found.toArray(new SerialFieldTag[found.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
     * Return array of tags with text and inline See Tags for a Doc comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
    static Tag[] getInlineTags(DocImpl holder, String inlinetext) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
        ListBuffer<Tag> taglist = new ListBuffer<Tag>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        int delimend = 0, textstart = 0, len = inlinetext.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        DocEnv docenv = holder.env;
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
        if (len == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
            return taglist.toArray(new Tag[taglist.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
        while (true) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
            int linkstart;
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
            if ((linkstart = inlineTagFound(holder, inlinetext,
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
                                            textstart)) == -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                taglist.append(new TagImpl(holder, "Text",
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                                           inlinetext.substring(textstart)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                int seetextstart = linkstart;
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                for (int i = linkstart; i < inlinetext.length(); i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                    char c = inlinetext.charAt(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
                    if (Character.isWhitespace(c) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
                        c == '}') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
                        seetextstart = i;
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
                     }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
                String linkName = inlinetext.substring(linkstart+2, seetextstart);
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
                //Move past the white space after the inline tag name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
                while (Character.isWhitespace(inlinetext.
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
                                                  charAt(seetextstart))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
                    if (inlinetext.length() <= seetextstart) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
                        taglist.append(new TagImpl(holder, "Text",
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
                                                   inlinetext.substring(textstart, seetextstart)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
                        docenv.warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
                                       "tag.Improper_Use_Of_Link_Tag",
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
                                       inlinetext);
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
                        return taglist.toArray(new Tag[taglist.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
                        seetextstart++;
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
                taglist.append(new TagImpl(holder, "Text",
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
                                           inlinetext.substring(textstart, linkstart)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
                textstart = seetextstart;   // this text is actually seetag
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
                if ((delimend = findInlineTagDelim(inlinetext, textstart)) == -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
                    //Missing closing '}' character.
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                    // store the text as it is with the {@link.
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
                    taglist.append(new TagImpl(holder, "Text",
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                                               inlinetext.substring(textstart)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
                    docenv.warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                                   "tag.End_delimiter_missing_for_possible_SeeTag",
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                                   inlinetext);
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                    return taglist.toArray(new Tag[taglist.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                    //Found closing '}' character.
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                    if (linkName.equals("see")
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
                           || linkName.equals("link")
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
                           || linkName.equals("linkplain")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
                        taglist.append( new SeeTagImpl(holder, "@" + linkName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
                              inlinetext.substring(textstart, delimend)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
                        taglist.append( new TagImpl(holder, "@" + linkName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
                              inlinetext.substring(textstart, delimend)));
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
                    textstart = delimend + 1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            if (textstart == inlinetext.length()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        return taglist.toArray(new Tag[taglist.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
     * Recursively find the index of the closing '}' character for an inline tag
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
     * and return it.  If it can't be found, return -1.
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
     * @param inlineText the text to search in.
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
     * @param searchStart the index of the place to start searching at.
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     * @return the index of the closing '}' character for an inline tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
     * If it can't be found, return -1.
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
    private static int findInlineTagDelim(String inlineText, int searchStart) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        int delimEnd, nestedOpenBrace;
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        if ((delimEnd = inlineText.indexOf("}", searchStart)) == -1) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
            return -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        } else if (((nestedOpenBrace = inlineText.indexOf("{", searchStart)) != -1) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
            nestedOpenBrace < delimEnd){
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
            //Found a nested open brace.
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
            int nestedCloseBrace = findInlineTagDelim(inlineText, nestedOpenBrace + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
            return (nestedCloseBrace != -1) ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
                findInlineTagDelim(inlineText, nestedCloseBrace + 1) :
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
                -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
            return delimEnd;
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
     * Recursively search for the string "{@" followed by
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
     * name of inline tag and white space,
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
     * if found
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
     *    return the index of the text following the white space.
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
     * else
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
     *    return -1.
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
     */
10203
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 5520
diff changeset
   396
    private static int inlineTagFound(DocImpl holder, String inlinetext, int start) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        DocEnv docenv = holder.env;
10203
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 5520
diff changeset
   398
        int linkstart = inlinetext.indexOf("{@", start);
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 5520
diff changeset
   399
        if (start == inlinetext.length() || linkstart == -1) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
            return -1;
10203
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 5520
diff changeset
   401
        } else if (inlinetext.indexOf('}', linkstart) == -1) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
            //Missing '}'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
            docenv.warning(holder, "tag.Improper_Use_Of_Link_Tag",
10203
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 5520
diff changeset
   404
                    inlinetext.substring(linkstart, inlinetext.length()));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
            return -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
            return linkstart;
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
     * Return array of tags for the locale specific first sentence in the text.
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
    static Tag[] firstSentenceTags(DocImpl holder, String text) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        DocLocale doclocale = holder.env.doclocale;
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        return getInlineTags(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
                             doclocale.localeSpecificFirstSentence(holder, text));
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
     * Return text for this Doc comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
     */
10203
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 5520
diff changeset
   424
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        return text;
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
}