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