src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/SeeTagImpl.java
author ksrini
Fri, 09 Feb 2018 13:58:17 -0800
changeset 48840 5e2d2067da48
parent 47216 71c04702a3d5
permissions -rw-r--r--
8194651: javadoc: mark the com.sun.javadoc API for removal Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2018, 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: 5010
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: 5010
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: 5010
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5010
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5010
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: 27224
diff changeset
    26
package com.sun.tools.javadoc.main;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    28
import java.io.File;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    29
import java.util.Locale;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    30
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 8631
diff changeset
    31
import com.sun.javadoc.*;
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    32
import com.sun.tools.javac.code.Printer;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    33
import com.sun.tools.javac.code.Symbol;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    34
import com.sun.tools.javac.code.Type.CapturedType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
    37
import static com.sun.tools.javac.code.Kinds.Kind.*;
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
    38
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * Represents a see also documentation tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * The @see tag can be plain text, or reference a class or member.
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    43
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    44
 *  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: 14258
diff changeset
    45
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    46
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14258
diff changeset
    47
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * @author Kaiyang Liu (original)
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * @author Robert Field (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * @author Atul M Dambalkar
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 */
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    53
@Deprecated(since="9", forRemoval=true)
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    54
@SuppressWarnings("removal")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
class SeeTagImpl extends TagImpl implements SeeTag, LayoutCharacters {
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    //### TODO: Searching for classes, fields, and methods
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    //### should follow the normal rules applied by the compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     * where of  where#what - i.e. the class name (may be empty)
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    private String where;
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * what of  where#what - i.e. the member (may be null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    private String what;
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    private PackageDoc referencedPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    private ClassDoc referencedClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    private MemberDoc referencedMember;
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    String label = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    SeeTagImpl(DocImpl holder, String name, String text) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
        super(holder, name, text);
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        parseSeeString();
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        if (where != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
            ClassDocImpl container = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            if (holder instanceof MemberDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
                container =
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
                  (ClassDocImpl)((ProgramElementDoc)holder).containingClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            } else if (holder instanceof ClassDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
                container = (ClassDocImpl)holder;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            findReferenced(container);
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    88
            if (showRef) showRef();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    92
    private static final boolean showRef = false;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    93
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    94
    private void showRef() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    95
        Symbol sym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    96
        if (referencedMember != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    97
            if (referencedMember instanceof MethodDocImpl)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    98
                sym = ((MethodDocImpl) referencedMember).sym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
    99
            else if (referencedMember instanceof FieldDocImpl)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   100
                sym = ((FieldDocImpl) referencedMember).sym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   101
            else
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   102
                sym = ((ConstructorDocImpl) referencedMember).sym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   103
        } else if (referencedClass != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   104
            sym = ((ClassDocImpl) referencedClass).tsym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   105
        } else if (referencedPackage != null) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   106
            sym = ((PackageDocImpl) referencedPackage).sym;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   107
        } else
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   108
            return;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   109
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   110
        final JavacMessages messages = JavacMessages.instance(docenv().context);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   111
        Locale locale = Locale.getDefault();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   112
        Printer printer = new Printer() {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   113
            int count;
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   114
            @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   115
            protected String localize(Locale locale, String key, Object... args) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   116
                return messages.getLocalizedString(locale, key, args);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   117
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   118
            @Override
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   119
            protected String capturedVarId(CapturedType t, Locale locale) {
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   120
                return "CAP#" + (++count);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   121
            }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   122
        };
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   123
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   124
        String s = text.replaceAll("\\s+", " ");  // normalize white space
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   125
        int sp = s.indexOf(" ");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   126
        int lparen = s.indexOf("(");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   127
        int rparen = s.indexOf(")");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   128
        String seetext = (sp == -1) ? s
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   129
                : (lparen == -1 || sp < lparen) ? s.substring(0, sp)
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   130
                : s.substring(0, rparen + 1);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   131
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   132
        File file = new File(holder.position().file().getAbsoluteFile().toURI().normalize());
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   133
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   134
        StringBuilder sb = new StringBuilder();
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   135
        sb.append("+++ ").append(file).append(": ")
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   136
                .append(name()).append(" ").append(seetext).append(": ");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   137
        sb.append(sym.getKind()).append(" ");
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   138
        if (sym.kind == MTH || sym.kind == VAR)
14541
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   139
            sb.append(printer.visit(sym.owner, locale)).append(".");
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   140
        sb.append(printer.visit(sym, locale));
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   141
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   142
        System.err.println(sb);
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   143
    }
36f9d11fc9aa 7021614: extend com.sun.source API to support parsing javadoc comments
jjg
parents: 14447
diff changeset
   144
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
     * get the class name part of @see, For instance,
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     * if the comment is @see String#startsWith(java.lang.String) .
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     *      This function returns String.
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
     * Returns null if format was not that of java reference.
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * Return empty string if class name was not specified..
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    public String referencedClassName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        return where;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     * get the package referenced by  @see. For instance,
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     * if the comment is @see java.lang
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     *      This function returns a PackageDocImpl for java.lang
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     * Returns null if no known package found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    public PackageDoc referencedPackage() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        return referencedPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * get the class referenced by the class name part of @see, For instance,
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     * if the comment is @see String#startsWith(java.lang.String) .
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     *      This function returns a ClassDocImpl for java.lang.String.
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * Returns null if class is not a class specified on the javadoc command line..
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    public ClassDoc referencedClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
        return referencedClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * get the name of the member referenced by the prototype part of @see,
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * For instance,
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * if the comment is @see String#startsWith(java.lang.String) .
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     *      This function returns "startsWith(java.lang.String)"
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * Returns null if format was not that of java reference.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * Return empty string if member name was not specified..
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    public String referencedMemberName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        return what;
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * get the member referenced by the prototype part of @see,
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
     * For instance,
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     * if the comment is @see String#startsWith(java.lang.String) .
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
     *      This function returns a MethodDocImpl for startsWith.
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     * Returns null if member could not be determined.
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    public MemberDoc referencedMember() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        return referencedMember;
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    }
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
     * parse @see part of comment. Determine 'where' and 'what'
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    private void parseSeeString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
        int len = text.length();
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
        if (len == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        switch (text.charAt(0)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            case '<':
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
                if (text.charAt(len-1) != '>') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
                    docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                                     "tag.see.no_close_bracket_on_url",
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
                                     name, text);
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
            case '"':
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
                if (len == 1 || text.charAt(len-1) != '"') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
                    docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
                                     "tag.see.no_close_quote",
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
                                     name, text);
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
//                    text = text.substring(1,len-1); // strip quotes
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        // check that the text is one word, with possible parentheses
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
        // this part of code doesn't allow
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        // @see <a href=.....>asfd</a>
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        // comment it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        // the code assumes that there is no initial white space.
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        int parens = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        int commentstart = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        int start = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        int cp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        for (int i = start; i < len ; i += Character.charCount(cp)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            cp = text.codePointAt(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            switch (cp) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
                case '(': parens++; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
                case ')': parens--; break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
                case '[': case ']': case '.': case '#': break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                case ',':
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
                    if (parens <= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
                        docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
                                         "tag.see.malformed_see_tag",
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
                                         name, text);
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
                        return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
                case ' ': case '\t': case '\n': case CR:
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
                    if (parens == 0) { //here onwards the comment starts.
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
                        commentstart = i;
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
                        i = len;
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
                default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
                    if (!Character.isJavaIdentifierPart(cp)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                        docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                                         "tag.see.illegal_character",
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                                         name, ""+cp, text);
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        if (parens != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
            docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
                             "tag.see.malformed_see_tag",
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
                             name, text);
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        String seetext = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        String labeltext = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        if (commentstart > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            seetext = text.substring(start, commentstart);
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
            labeltext = text.substring(commentstart + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            // strip off the white space which can be between seetext and the
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
            // actual label.
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            for (int i = 0; i < labeltext.length(); i++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
                char ch2 = labeltext.charAt(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
                if (!(ch2 == ' ' || ch2 == '\t' || ch2 == '\n')) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                    label = labeltext.substring(i);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
                    break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
            seetext = text;
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            label = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        int sharp = seetext.indexOf('#');
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        if (sharp >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
            // class#member
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
            where = seetext.substring(0, sharp);
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
            what = seetext.substring(sharp + 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
            if (seetext.indexOf('(') >= 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
                docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
                                 "tag.see.missing_sharp",
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
                                 name, text);
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
                where = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
                what = seetext;
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
                // no member specified, text names class
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
                where = seetext;
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
                what = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
     * Find what is referenced by the see also.  If possible, sets
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
     * referencedClass and referencedMember.
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
     * @param containingClass the class containing the comment containing
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     * the tag. May be null, if, for example, it is a package comment.
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    private void findReferenced(ClassDocImpl containingClass) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
        if (where.length() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            if (containingClass != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
                referencedClass = containingClass.findClass(where);
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
                referencedClass = docenv().lookupClass(where);
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            if (referencedClass == null && holder() instanceof ProgramElementDoc) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                referencedClass = docenv().lookupClass(
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                    ((ProgramElementDoc) holder()).containingPackage().name() + "." + where);
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
            if (referencedClass == null) { /* may just not be in this run */
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
                // check if it's a package name
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
                referencedPackage = docenv().lookupPackage(where);
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            if (containingClass == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                                 "tag.see.class_not_specified",
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                                 name, text);
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                referencedClass = containingClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        where = referencedClass.qualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        if (what == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
            return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
            int paren = what.indexOf('(');
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
            String memName = (paren >= 0 ? what.substring(0, paren) : what);
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
            String[] paramarr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            if (paren > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
                // has parameter list -- should be method or constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                paramarr = new ParameterParseMachine(what.
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                        substring(paren, what.length())).parseParameters();
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                if (paramarr != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                    referencedMember = findExecutableMember(memName, paramarr,
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
                                                            referencedClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
                    referencedMember = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
                // no parameter list -- should be field
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
                referencedMember = findExecutableMember(memName, null,
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
                                                        referencedClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
                FieldDoc fd = ((ClassDocImpl)referencedClass).
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
                                                            findField(memName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
                // when no args given, prefer fields over methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
                if (referencedMember == null ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
                    (fd != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
                     fd.containingClass()
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
                         .subclassOf(referencedMember.containingClass()))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
                    referencedMember = fd;
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
            if (referencedMember == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
                docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
                                 "tag.see.can_not_find_member",
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
                                 name, what, where);
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
            }
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
    private MemberDoc findReferencedMethod(String memName, String[] paramarr,
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
                                           ClassDoc referencedClass) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        MemberDoc meth = findExecutableMember(memName, paramarr, referencedClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
        if (meth == null) {
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14541
diff changeset
   392
            for (ClassDoc nestedClass : referencedClass.innerClasses()) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 14541
diff changeset
   393
                meth = findReferencedMethod(memName, paramarr, nestedClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
                if (meth != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
                    return meth;
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    private MemberDoc findExecutableMember(String memName, String[] paramarr,
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
                                           ClassDoc referencedClass) {
23794
9437acfa99e9 8031625: javadoc problems referencing inner class constructors
bpatel
parents: 22163
diff changeset
   404
        String className = referencedClass.name();
9437acfa99e9 8031625: javadoc problems referencing inner class constructors
bpatel
parents: 22163
diff changeset
   405
        if (memName.equals(className.substring(className.lastIndexOf(".") + 1))) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
            return ((ClassDocImpl)referencedClass).findConstructor(memName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
                                                                   paramarr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        } else {   // it's a method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
            return ((ClassDocImpl)referencedClass).findMethod(memName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
                                                              paramarr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
    // separate "int, String" from "(int, String)"
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
    // (int i, String s) ==> [0] = "int",  [1] = String
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
    // (int[][], String[]) ==> [0] = "int[][]" // [1] = "String[]"
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
    class ParameterParseMachine {
5010
c9fd6294653a 6931482: minor findbugs fixes
jjg
parents: 1264
diff changeset
   418
        static final int START = 0;
c9fd6294653a 6931482: minor findbugs fixes
jjg
parents: 1264
diff changeset
   419
        static final int TYPE = 1;
c9fd6294653a 6931482: minor findbugs fixes
jjg
parents: 1264
diff changeset
   420
        static final int NAME = 2;
c9fd6294653a 6931482: minor findbugs fixes
jjg
parents: 1264
diff changeset
   421
        static final int TNSPACE = 3;  // space between type and name
c9fd6294653a 6931482: minor findbugs fixes
jjg
parents: 1264
diff changeset
   422
        static final int ARRAYDECORATION = 4;
c9fd6294653a 6931482: minor findbugs fixes
jjg
parents: 1264
diff changeset
   423
        static final int ARRAYSPACE = 5;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
        String parameters;
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   427
        StringBuilder typeId;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
        ListBuffer<String> paramList;
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
        ParameterParseMachine(String parameters) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
            this.parameters = parameters;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   433
            this.paramList = new ListBuffer<>();
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   434
            typeId = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        public String[] parseParameters() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
            if (parameters.equals("()")) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
                return new String[0];
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
            }   // now strip off '(' and ')'
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
            int state = START;
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
            int prevstate = START;
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
            parameters = parameters.substring(1, parameters.length() - 1);
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
            int cp;
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
            for (int index = 0; index < parameters.length(); index += Character.charCount(cp)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
                cp = parameters.codePointAt(index);
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
                switch (state) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
                    case START:
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
                        if (Character.isJavaIdentifierStart(cp)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
                            typeId.append(Character.toChars(cp));
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
                            state = TYPE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
                        prevstate = START;
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
                    case TYPE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
                        if (Character.isJavaIdentifierPart(cp) || cp == '.') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
                            typeId.append(Character.toChars(cp));
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
                        } else if (cp == '[') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
                            typeId.append('[');
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
                            state = ARRAYDECORATION;
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
                        } else if (Character.isWhitespace(cp)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
                            state = TNSPACE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
                        } else if (cp == ',') {  // no name, just type
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
                            addTypeToParamList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
                            state = START;
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
                        prevstate = TYPE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
                    case TNSPACE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
                        if (Character.isJavaIdentifierStart(cp)) { // name
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
                            if (prevstate == ARRAYDECORATION) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
                                docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
                                                 "tag.missing_comma_space",
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
                                                 name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
                                                 "(" + parameters + ")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
                                return (String[])null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
                            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
                            addTypeToParamList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
                            state = NAME;
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
                        } else if (cp == '[') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
                            typeId.append('[');
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
                            state = ARRAYDECORATION;
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
                        } else if (cp == ',') {   // just the type
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
                            addTypeToParamList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
                            state = START;
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
                        } // consume rest all
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
                        prevstate = TNSPACE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
                    case ARRAYDECORATION:
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
                        if (cp == ']') {
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
                            typeId.append(']');
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
                            state = TNSPACE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
                        } else if (!Character.isWhitespace(cp)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
                            docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
                                             "tag.illegal_char_in_arr_dim",
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
                                             name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
                                             "(" + parameters + ")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
                            return (String[])null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
                        prevstate = ARRAYDECORATION;
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
                    case NAME:
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
                        if (cp == ',') {  // just consume everything till ','
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
                            state = START;
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
                        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
                        prevstate = NAME;
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
                        break;
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
            if (state == ARRAYDECORATION ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
                (state == START && prevstate == TNSPACE)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
                docenv().warning(holder,
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
                                 "tag.illegal_see_tag",
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
                                 "(" + parameters + ")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
            if (typeId.length() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
                paramList.append(typeId.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
            }
868
d0f233085cbb 6657907: javadoc has unchecked warnings
jjg
parents: 10
diff changeset
   519
            return paramList.toArray(new String[paramList.length()]);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
        void addTypeToParamList() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
            if (typeId.length() > 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
                paramList.append(typeId.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
                typeId.setLength(0);
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
     * Return the kind of this tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 5520
diff changeset
   533
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
    public String kind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
        return "@see";
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
     * Return the label of the see tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
    public String label() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
        return label;
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
}