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