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