src/jdk.javadoc/share/classes/com/sun/tools/javadoc/main/ClassDocImpl.java
author ksrini
Fri, 09 Feb 2018 13:58:17 -0800
changeset 48840 5e2d2067da48
parent 47216 71c04702a3d5
child 52902 e3398b2e1ab0
permissions -rw-r--r--
8194651: javadoc: mark the com.sun.javadoc API for removal Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3782
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: 3782
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: 3782
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3782
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3782
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: 36526
diff changeset
    26
package com.sun.tools.javadoc.main;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    28
import java.io.File;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    29
import java.io.IOException;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    30
import java.lang.reflect.Modifier;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    31
import java.net.URI;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    32
import java.util.HashSet;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    33
import java.util.Set;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14359
diff changeset
    34
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    35
import javax.tools.FileObject;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    36
import javax.tools.JavaFileManager.Location;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    37
import javax.tools.StandardJavaFileManager;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    38
import javax.tools.StandardLocation;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    39
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.javadoc.*;
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14359
diff changeset
    41
import com.sun.source.util.TreePath;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import com.sun.tools.javac.code.Flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import com.sun.tools.javac.code.Kinds;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
    44
import com.sun.tools.javac.code.Kinds.KindSelector;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import com.sun.tools.javac.code.Scope;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
import com.sun.tools.javac.code.Symbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
import com.sun.tools.javac.code.Symbol.*;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    48
import com.sun.tools.javac.code.Type;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    49
import com.sun.tools.javac.code.Type.ClassType;
18915
dcc9c8265f65 8016640: compiler hangs if the generics arity of a base class is wrong
mcimadamore
parents: 17275
diff changeset
    50
import com.sun.tools.javac.code.TypeTag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
import com.sun.tools.javac.comp.AttrContext;
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
import com.sun.tools.javac.comp.Env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
import com.sun.tools.javac.tree.JCTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
import com.sun.tools.javac.tree.JCTree.JCImport;
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
import com.sun.tools.javac.tree.TreeInfo;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    57
import com.sun.tools.javac.util.List;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    58
import com.sun.tools.javac.util.ListBuffer;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    59
import com.sun.tools.javac.util.Name;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
    60
import com.sun.tools.javac.util.Names;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
    61
import com.sun.tools.javac.util.Position;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
    62
import static com.sun.tools.javac.code.Kinds.Kind.*;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
    63
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
    64
import static com.sun.tools.javac.code.TypeTag.CLASS;
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10203
diff changeset
    65
import static com.sun.tools.javac.tree.JCTree.Tag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 * Represents a java class and provides access to information
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 * about the class, the class' comment and tags, and the
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 * members of the class.  A ClassDocImpl only exists if it was
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 * processed in this run of javadoc.  References to classes
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 * which may or may not have been processed in this run are
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 * referred to using Type (which can be converted to ClassDocImpl,
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 * if possible).
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 *
14260
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    76
 *  <p><b>This is NOT part of any supported API.
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    77
 *  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: 14259
diff changeset
    78
 *  This code and its internal interfaces are subject to change or
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    79
 *  deletion without notice.</b>
727a84636f12 8000665: fix "internal API" comments on javadoc files
jjg
parents: 14259
diff changeset
    80
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 * @see Type
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
 * @since 1.2
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
 * @author Robert Field
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
 * @author Neal Gafter (rewrite)
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
 * @author Scott Seligman (generics, enums, annotations)
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    89
@Deprecated(since="9", forRemoval=true)
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
    90
@SuppressWarnings("removal")
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    public final ClassType type;        // protected->public for debugging
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 32800
diff changeset
    94
    public final ClassSymbol tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    boolean isIncluded = false;         // Set in RootDocImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    private SerializedForm serializedForm;
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    public ClassDocImpl(DocEnv env, ClassSymbol sym) {
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14359
diff changeset
   104
        this(env, sym, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * Constructor
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     */
14802
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14359
diff changeset
   110
    public ClassDocImpl(DocEnv env, ClassSymbol sym, TreePath treePath) {
969e90f68ac5 8004828: refactor init of *DocImpl classes
jjg
parents: 14359
diff changeset
   111
        super(env, sym, treePath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        this.type = (ClassType)sym.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        this.tsym = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
16969
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   116
    public com.sun.javadoc.Type getElementType() {
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   117
        return null;
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   118
    }
b58d8a70d921 8009686: Generated javadoc documentation should be able to display type annotation on an array
bpatel
parents: 15385
diff changeset
   119
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     * Returns the flags in terms of javac's flags
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    protected long getFlags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        return getFlags(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     * Returns the flags of a ClassSymbol in terms of javac's flags
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    static long getFlags(ClassSymbol clazz) {
32800
8457813125e3 8135307: CompletionFailure thrown when calling FieldDoc.type, if the field's type is missing
jlahoda
parents: 31751
diff changeset
   131
        try {
8457813125e3 8135307: CompletionFailure thrown when calling FieldDoc.type, if the field's type is missing
jlahoda
parents: 31751
diff changeset
   132
            return clazz.flags();
8457813125e3 8135307: CompletionFailure thrown when calling FieldDoc.type, if the field's type is missing
jlahoda
parents: 31751
diff changeset
   133
        } catch (CompletionFailure ex) {
8457813125e3 8135307: CompletionFailure thrown when calling FieldDoc.type, if the field's type is missing
jlahoda
parents: 31751
diff changeset
   134
            /* Quietly ignore completion failures and try again - the type
8457813125e3 8135307: CompletionFailure thrown when calling FieldDoc.type, if the field's type is missing
jlahoda
parents: 31751
diff changeset
   135
             * for which the CompletionFailure was thrown shouldn't be completed
8457813125e3 8135307: CompletionFailure thrown when calling FieldDoc.type, if the field's type is missing
jlahoda
parents: 31751
diff changeset
   136
             * again by the completer that threw the CompletionFailure.
8457813125e3 8135307: CompletionFailure thrown when calling FieldDoc.type, if the field's type is missing
jlahoda
parents: 31751
diff changeset
   137
             */
8457813125e3 8135307: CompletionFailure thrown when calling FieldDoc.type, if the field's type is missing
jlahoda
parents: 31751
diff changeset
   138
            return getFlags(clazz);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     * Is a ClassSymbol an annotation type?
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    static boolean isAnnotationType(ClassSymbol clazz) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        return (getFlags(clazz) & Flags.ANNOTATION) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * Identify the containing class
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    protected ClassSymbol getContainingClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        return tsym.owner.enclClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
     * Return true if this is a class, not an interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   159
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    public boolean isClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        return !Modifier.isInterface(getModifiers());
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
     * Return true if this is a ordinary class,
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * not an enumeration, exception, an error, or an interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   168
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    public boolean isOrdinaryClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
        if (isEnum() || isInterface() || isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
        }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   173
        for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
            if (t.tsym == env.syms.errorType.tsym ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
                t.tsym == env.syms.exceptionType.tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * Return true if this is an enumeration.
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     * (For legacy doclets, return false.)
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   186
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    public boolean isEnum() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        return (getFlags() & Flags.ENUM) != 0
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
               &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
               !env.legacyDoclet;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
     * Return true if this is an interface, but not an annotation type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
     * Overridden by AnnotationTypeDocImpl.
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   197
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    public boolean isInterface() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        return Modifier.isInterface(getModifiers());
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     * Return true if this is an exception class
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   205
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    public boolean isException() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        if (isEnum() || isInterface() || isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
        }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   210
        for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
            if (t.tsym == env.syms.exceptionType.tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     * Return true if this is an error class
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   221
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    public boolean isError() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        if (isEnum() || isInterface() || isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
        }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   226
        for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
            if (t.tsym == env.syms.errorType.tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     * Return true if this is a throwable class
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
    public boolean isThrowable() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
        if (isEnum() || isInterface() || isAnnotationType()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
        }
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14260
diff changeset
   241
        for (Type t = type; t.hasTag(CLASS); t = env.types.supertype(t)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
            if (t.tsym == env.syms.throwableType.tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * Return true if this class is abstract
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    public boolean isAbstract() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        return Modifier.isAbstract(getModifiers());
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     * Returns true if this class was synthesized by the compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    public boolean isSynthetic() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        return (getFlags() & Flags.SYNTHETIC) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     * Return true if this class is included in the active set.
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     * A ClassDoc is included iff either it is specified on the
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     * commandline, or if it's containing package is specified
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     * on the command line, or if it is a member class of an
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * included class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    public boolean isIncluded() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        if (isIncluded) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        if (env.shouldDocument(tsym)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
            // Class is nameable from top-level and
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            // the class and all enclosing classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
            // pass the modifier filter.
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
            if (containingPackage().isIncluded()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
                return isIncluded=true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            ClassDoc outer = containingClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
            if (outer != null && outer.isIncluded()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
                return isIncluded=true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
     * Return the package that this class is contained in.
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   293
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    public PackageDoc containingPackage() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        PackageDocImpl p = env.getPackageDoc(tsym.packge());
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   296
        if (p.setDocPath == false) {
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   297
            FileObject docPath;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   298
            try {
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   299
                Location location = env.fileManager.hasLocation(StandardLocation.SOURCE_PATH)
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   300
                    ? StandardLocation.SOURCE_PATH : StandardLocation.CLASS_PATH;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   301
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   302
                docPath = env.fileManager.getFileForInput(
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   303
                        location, p.qualifiedName(), "package.html");
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   304
            } catch (IOException e) {
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   305
                docPath = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            }
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   307
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   308
            if (docPath == null) {
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   309
                // fall back on older semantics of looking in same directory as
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   310
                // source file for this class
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   311
                SourcePosition po = position();
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   312
                if (env.fileManager instanceof StandardJavaFileManager &&
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   313
                        po instanceof SourcePositionImpl) {
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   314
                    URI uri = ((SourcePositionImpl) po).filename.toUri();
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   315
                    if ("file".equals(uri.getScheme())) {
3782
ae62279eeb46 6419701: DefaultFileManager clean up: URI.create
jjg
parents: 2212
diff changeset
   316
                        File f = new File(uri);
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   317
                        File dir = f.getParentFile();
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   318
                        if (dir != null) {
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   319
                            File pf = new File(dir, "package.html");
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   320
                            if (pf.exists()) {
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   321
                                StandardJavaFileManager sfm = (StandardJavaFileManager) env.fileManager;
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   322
                                docPath = sfm.getJavaFileObjects(pf).iterator().next();
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   323
                            }
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   324
                        }
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   325
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   326
                    }
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   327
                }
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   328
            }
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   329
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
   330
            p.setDocPath(docPath);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        return p;
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
     * Return the class name without package qualifier - but with
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
     * enclosing class qualifier - as a String.
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
     * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
     * Examples:
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
     *  for java.util.Hashtable
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
     *  return Hashtable
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
     *  for java.util.Map.Entry
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
     *  return Map.Entry
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
    public String name() {
17275
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   347
        if (name == null) {
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   348
            name = getClassName(tsym, false);
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   349
        }
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   350
        return name;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
17275
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   353
    private String name;
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   354
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     * Return the qualified class name as a String.
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
     * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
     * Example:
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
     *  for java.util.Hashtable
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
     *  return java.util.Hashtable
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
     *  if no qualifier, just return flat name
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
     * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    public String qualifiedName() {
17275
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   365
        if (qualifiedName == null) {
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   366
            qualifiedName = getClassName(tsym, true);
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   367
        }
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   368
        return qualifiedName;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
17275
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   371
    private String qualifiedName;
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   372
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
     * Return unqualified name of type excluding any dimension information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
     * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
     * For example, a two dimensional array of String returns 'String'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
    public String typeName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        return name();
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
     * Return qualified name of type excluding any dimension information.
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
     *<p>
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
     * For example, a two dimensional array of String
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
     * returns 'java.lang.String'.
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    public String qualifiedTypeName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
        return qualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
     * Return the simple name of this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
    public String simpleTypeName() {
17275
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   396
        if (simpleTypeName == null) {
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   397
            simpleTypeName = tsym.name.toString();
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   398
        }
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   399
        return simpleTypeName;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
17275
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   402
    private String simpleTypeName;
bcaa1940863a 8012656: cache frequently used name strings for DocImpl classes
jjg
parents: 16969
diff changeset
   403
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     * Return the qualified name and any type parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     * Each parameter is a type variable with optional bounds.
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   408
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        return classToString(env, tsym, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
     * Return the class name as a string.  If "full" is true the name is
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
     * qualified, otherwise it is qualified by its enclosing class(es) only.
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
    static String getClassName(ClassSymbol c, boolean full) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
        if (full) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            return c.getQualifiedName().toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
            String n = "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            for ( ; c != null; c = c.owner.enclClass()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
                n = c.name + (n.equals("") ? "" : ".") + n;
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
            return n;
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
     * Return the class name with any type parameters as a string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
     * Each parameter is a type variable with optional bounds.
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
     * If "full" is true all names are qualified, otherwise they are
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
     * qualified by their enclosing class(es) only.
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
    static String classToString(DocEnv env, ClassSymbol c, boolean full) {
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   436
        StringBuilder s = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        if (!c.isInner()) {             // if c is not an inner class
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
            s.append(getClassName(c, full));
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
            // c is an inner class, so include type params of outer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
            ClassSymbol encl = c.owner.enclClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
            s.append(classToString(env, encl, full))
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
             .append('.')
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
             .append(c.name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        s.append(TypeMaker.typeParametersString(env, c, full));
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
        return s.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
     * Is this class (or any enclosing class) generic?  That is, does
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
     * it have type parameters?
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    static boolean isGeneric(ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        return c.type.allparams().nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
     * Return the formal type parameters of this class or interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
     * Return an empty array if there are none.
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
    public TypeVariable[] typeParameters() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        if (env.legacyDoclet) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
            return new TypeVariable[0];
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
        TypeVariable res[] = new TypeVariable[type.getTypeArguments().length()];
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        TypeMaker.getTypes(env, type.getTypeArguments(), res);
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
        return res;
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
     * Return the type parameter tags of this class or interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
    public ParamTag[] typeParamTags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
        return (env.legacyDoclet)
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
            ? new ParamTag[0]
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
            : comment().typeParamTags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
     * Return the modifier string for this class. If it's an interface
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
     * exclude 'abstract' keyword from the modifier string
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   484
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
    public String modifiers() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        return Modifier.toString(modifierSpecifier());
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
   489
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
    public int modifierSpecifier() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        int modifiers = getModifiers();
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        return (isInterface() || isAnnotationType())
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
                ? modifiers & ~Modifier.ABSTRACT
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
                : modifiers;
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
     * Return the superclass of this class
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
     * @return the ClassDocImpl for the superclass of this class, null
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
     * if there is no superclass.
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
    public ClassDoc superclass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        if (isInterface() || isAnnotationType()) return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
        if (tsym == env.syms.objectType.tsym) return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
        ClassSymbol c = (ClassSymbol)env.types.supertype(type).tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        if (c == null || c == tsym) c = (ClassSymbol)env.syms.objectType.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
        return env.getClassDoc(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
     * Return the superclass of this class.  Return null if this is an
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
     * interface.  A superclass is represented by either a
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
     * <code>ClassDoc</code> or a <code>ParameterizedType</code>.
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
    public com.sun.javadoc.Type superclassType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        if (isInterface() || isAnnotationType() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
                (tsym == env.syms.objectType.tsym))
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        Type sup = env.types.supertype(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
        return TypeMaker.getType(env,
18915
dcc9c8265f65 8016640: compiler hangs if the generics arity of a base class is wrong
mcimadamore
parents: 17275
diff changeset
   522
                                 (sup.hasTag(TypeTag.NONE)) ? env.syms.objectType : sup);
10
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
     * Test whether this class is a subclass of the specified class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
     * @param cd the candidate superclass.
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
     * @return true if cd is a superclass of this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
    public boolean subclassOf(ClassDoc cd) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
        return tsym.isSubClass(((ClassDocImpl)cd).tsym, env.types);
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 interfaces implemented by this class or interfaces
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
     * extended by this interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
     * @return An array of ClassDocImpl representing the interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
     * Return an empty array if there are no interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
    public ClassDoc[] interfaces() {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   543
        ListBuffer<ClassDocImpl> ta = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
        for (Type t : env.types.interfaces(type)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
            ta.append(env.getClassDoc((ClassSymbol)t.tsym));
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        //### Cache ta here?
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
        return ta.toArray(new ClassDocImpl[ta.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
     * Return interfaces implemented by this class or interfaces extended
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
     * by this interface. Includes only directly-declared interfaces, not
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
     * inherited interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
     * Return an empty array if there are no interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
    public com.sun.javadoc.Type[] interfaceTypes() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        //### Cache result here?
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        return TypeMaker.getTypes(env, env.types.interfaces(type));
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
     * Return fields in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
     * @param filter include only the included fields if filter==true
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
    public FieldDoc[] fields(boolean filter) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
        return fields(filter, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
     * Return included fields in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
    public FieldDoc[] fields() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
        return fields(true, false);
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
     * Return the enum constants if this is an enum type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
    public FieldDoc[] enumConstants() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        return fields(false, true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
     * Return fields in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
     * @param filter  if true, return only the included fields
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
     * @param enumConstants  if true, return the enum constants instead
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
    private FieldDoc[] fields(boolean filter, boolean enumConstants) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
        List<FieldDocImpl> fields = List.nil();
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   591
        for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   592
            if (sym != null && sym.kind == VAR) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   593
                VarSymbol s = (VarSymbol)sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
                boolean isEnum = ((s.flags() & Flags.ENUM) != 0) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
                                 !env.legacyDoclet;
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
                if (isEnum == enumConstants &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
                        (!filter || env.shouldDocument(s))) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
                    fields = fields.prepend(env.getFieldDoc(s));
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
        return fields.toArray(new FieldDocImpl[fields.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
     * Return methods in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
     * This method is overridden by AnnotationTypeDocImpl.
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
     * @param filter include only the included methods if filter==true
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
     * @return an array of MethodDocImpl for representing the visible
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
     * methods in this class.  Does not include constructors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
    public MethodDoc[] methods(boolean filter) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   614
        Names names = tsym.name.table.names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
        List<MethodDocImpl> methods = List.nil();
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   616
        for (Symbol sym :tsym.members().getSymbols(NON_RECURSIVE)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   617
            if (sym != null
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   618
                && sym.kind == MTH
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   619
                && sym.name != names.init
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   620
                && sym.name != names.clinit) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   621
                MethodSymbol s = (MethodSymbol)sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
                if (!filter || env.shouldDocument(s)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
                    methods = methods.prepend(env.getMethodDoc(s));
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
        //### Cache methods here?
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
        return methods.toArray(new MethodDocImpl[methods.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
     * Return included methods in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
     * @return an array of MethodDocImpl for representing the visible
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
     * methods in this class.  Does not include constructors.
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
    public MethodDoc[] methods() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
        return methods(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
     * Return constructors in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
     * @param filter include only the included constructors if filter==true
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
     * @return an array of ConstructorDocImpl for representing the visible
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
     * constructors in this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
    public ConstructorDoc[] constructors(boolean filter) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   649
        Names names = tsym.name.table.names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
        List<ConstructorDocImpl> constructors = List.nil();
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   651
        for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   652
            if (sym != null &&
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   653
                sym.kind == MTH && sym.name == names.init) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   654
                MethodSymbol s = (MethodSymbol)sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
                if (!filter || env.shouldDocument(s)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
                    constructors = constructors.prepend(env.getConstructorDoc(s));
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
        //### Cache constructors here?
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
        return constructors.toArray(new ConstructorDocImpl[constructors.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
     * Return included constructors in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
     * @return an array of ConstructorDocImpl for representing the visible
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
     * constructors in this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
    public ConstructorDoc[] constructors() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
        return constructors(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
     * Adds all inner classes of this class, and their
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
     * inner classes recursively, to the list l.
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
    void addAllClasses(ListBuffer<ClassDocImpl> l, boolean filtered) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
            if (isSynthetic()) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
            // sometimes synthetic classes are not marked synthetic
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
            if (!JavadocTool.isValidClassName(tsym.name.toString())) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
            if (filtered && !env.shouldDocument(tsym)) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
            if (l.contains(this)) return;
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
            l.append(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
            List<ClassDocImpl> more = List.nil();
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   687
            for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   688
                if (sym != null && sym.kind == TYP) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   689
                    ClassSymbol s = (ClassSymbol)sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
                    ClassDocImpl c = env.getClassDoc(s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
                    if (c.isSynthetic()) continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
                    if (c != null) more = more.prepend(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
            // this extra step preserves the ordering from oldjavadoc
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
            for (; more.nonEmpty(); more=more.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
                more.head.addAllClasses(l, filtered);
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
        } catch (CompletionFailure e) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
            // quietly ignore completion failures
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
     * Return inner classes within this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
     * @param filter include only the included inner classes if filter==true.
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
     * @return an array of ClassDocImpl for representing the visible
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
     * classes defined in this class. Anonymous and local classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
     * are not included.
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
    public ClassDoc[] innerClasses(boolean filter) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
   713
        ListBuffer<ClassDocImpl> innerClasses = new ListBuffer<>();
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   714
        for (Symbol sym : tsym.members().getSymbols(NON_RECURSIVE)) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   715
            if (sym != null && sym.kind == TYP) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   716
                ClassSymbol s = (ClassSymbol)sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
                if ((s.flags_field & Flags.SYNTHETIC) != 0) continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
                if (!filter || env.isVisible(s)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
                    innerClasses.prepend(env.getClassDoc(s));
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
        //### Cache classes here?
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
        return innerClasses.toArray(new ClassDocImpl[innerClasses.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
     * Return included inner classes within this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
     * @return an array of ClassDocImpl for representing the visible
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
     * classes defined in this class. Anonymous and local classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
     * are not included.
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
    public ClassDoc[] innerClasses() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
        return innerClasses(true);
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
     * Find a class within the context of this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
     * Search order: qualified name, in this class (inner),
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
     * in this package, in the class imports, in the package
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
     * imports.
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
     * Return the ClassDocImpl if found, null if not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
    //### The specified search order is not the normal rule the
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
    //### compiler would use.  Leave as specified or change it?
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
    public ClassDoc findClass(String className) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
        ClassDoc searchResult = searchClass(className);
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
        if (searchResult == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
            ClassDocImpl enclosingClass = (ClassDocImpl)containingClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
            //Expand search space to include enclosing class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
            while (enclosingClass != null && enclosingClass.containingClass() != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
                enclosingClass = (ClassDocImpl)enclosingClass.containingClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
            searchResult = enclosingClass == null ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
                null : enclosingClass.searchClass(className);
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
        return searchResult;
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
    private ClassDoc searchClass(String className) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
   762
        Names names = tsym.name.table.names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
        // search by qualified name first
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
        ClassDoc cd = env.lookupClass(className);
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
        if (cd != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
            return cd;
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
        // search inner classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
        //### Add private entry point to avoid creating array?
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
        //### Replicate code in innerClasses here to avoid consing?
10203
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 8631
diff changeset
   773
        for (ClassDoc icd : innerClasses()) {
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 8631
diff changeset
   774
            if (icd.name().equals(className) ||
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 8631
diff changeset
   775
                    //### This is from original javadoc but it looks suspicious to me...
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 8631
diff changeset
   776
                    //### I believe it is attempting to compensate for the confused
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 8631
diff changeset
   777
                    //### convention of including the nested class qualifiers in the
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 8631
diff changeset
   778
                    //### 'name' of the inner class, rather than the true simple name.
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 8631
diff changeset
   779
                    icd.name().endsWith("." + className)) {
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 8631
diff changeset
   780
                return icd;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
            } else {
10203
cca843a7d258 7064544: (javadoc) miscellaneous fixes requested by netbeans
ksrini
parents: 8631
diff changeset
   782
                ClassDoc innercd = ((ClassDocImpl) icd).searchClass(className);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
                if (innercd != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
                    return innercd;
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
        // check in this package
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
        cd = containingPackage().findClass(className);
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
        if (cd != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
            return cd;
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
        // make sure that this symbol has been completed
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 27224
diff changeset
   796
        tsym.complete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
        // search imports
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
        if (tsym.sourcefile != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
            //### This information is available only for source classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
            Env<AttrContext> compenv = env.enter.getEnv(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
            if (compenv == null) return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
            Scope s = compenv.toplevel.namedImportScope;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   808
            for (Symbol sym : s.getSymbolsByName(names.fromString(className))) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   809
                if (sym.kind == TYP) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   810
                    ClassDoc c = env.getClassDoc((ClassSymbol)sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
                    return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
            s = compenv.toplevel.starImportScope;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   816
            for (Symbol sym : s.getSymbolsByName(names.fromString(className))) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   817
                if (sym.kind == TYP) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   818
                    ClassDoc c = env.getClassDoc((ClassSymbol)sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
                    return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
        return null; // not found
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
    private boolean hasParameterTypes(MethodSymbol method, String[] argTypes) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
        if (argTypes == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
            // wildcard
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
        int i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
        List<Type> types = method.type.getParameterTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
        if (argTypes.length != types.length()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
        for (Type t : types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
            String argType = argTypes[i++];
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
            // For vararg method, "T..." matches type T[].
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
            if (i == argTypes.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
                argType = argType.replace("...", "[]");
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
            if (!hasTypeName(env.types.erasure(t), argType)) {  //###(gj)
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
    // where
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
    private boolean hasTypeName(Type t, String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
            name.equals(TypeMaker.getTypeName(t, true))
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
            ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
            name.equals(TypeMaker.getTypeName(t, false))
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
            ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
            (qualifiedName() + "." + name).equals(TypeMaker.getTypeName(t, true));
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
     * Find a method in this class scope.
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
     * Search order: this class, interfaces, superclasses, outerclasses.
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
     * Note that this is not necessarily what the compiler would do!
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
     * @param methodName the unqualified name to search for.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   872
     * @param paramTypes the array of Strings for method parameter types.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
     * @return the first MethodDocImpl which matches, null if not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
    public MethodDocImpl findMethod(String methodName, String[] paramTypes) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
        // Use hash table 'searched' to avoid searching same class twice.
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
        //### It is not clear how this could happen.
22165
ec53c8946fc2 8030807: langtools should still build using jdk 7
vromero
parents: 22163
diff changeset
   878
        return searchMethod(methodName, paramTypes, new HashSet<ClassDocImpl>());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
    private MethodDocImpl searchMethod(String methodName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
                                       String[] paramTypes, Set<ClassDocImpl> searched) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
        //### Note that this search is not necessarily what the compiler would do!
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
7071
8bcda461a06a 6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents: 5520
diff changeset
   885
        Names names = tsym.name.table.names;
8bcda461a06a 6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents: 5520
diff changeset
   886
        // do not match constructors
8bcda461a06a 6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents: 5520
diff changeset
   887
        if (names.init.contentEquals(methodName)) {
8bcda461a06a 6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents: 5520
diff changeset
   888
            return null;
8bcda461a06a 6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents: 5520
diff changeset
   889
        }
8bcda461a06a 6551367: javadoc throws ClassCastException when an @link tries to reference constructor.
sundar
parents: 5520
diff changeset
   890
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
        ClassDocImpl cdi;
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
        MethodDocImpl mdi;
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
        if (searched.contains(this)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
        searched.add(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
        //DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
        /*---------------------------------*
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
         System.out.print("searching " + this + " for " + methodName);
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
         if (paramTypes == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
         System.out.println("()");
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
         } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
         System.out.print("(");
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
         for (int k=0; k < paramTypes.length; k++) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
         System.out.print(paramTypes[k]);
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
         if ((k + 1) < paramTypes.length) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
         System.out.print(", ");
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
         }
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
         }
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
         System.out.println(")");
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
         }
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
         *---------------------------------*/
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
        // search current class
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
        //### Using modifier filter here isn't really correct,
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
        //### but emulates the old behavior.  Instead, we should
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
        //### apply the normal rules of visibility and inheritance.
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
        if (paramTypes == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
            // If no parameters specified, we are allowed to return
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
            // any method with a matching name.  In practice, the old
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
            // code returned the first method, which is now the last!
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
            // In order to provide textually identical results, we
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
            // attempt to emulate the old behavior.
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
            MethodSymbol lastFound = null;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   929
            for (Symbol sym : tsym.members().getSymbolsByName(names.fromString(methodName))) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   930
                if (sym.kind == MTH) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
                    //### Should intern methodName as Name.
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   932
                    if (sym.name.toString().equals(methodName)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   933
                        lastFound = (MethodSymbol)sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
            if (lastFound != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
                return env.getMethodDoc(lastFound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
        } else {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   941
            for (Symbol sym : tsym.members().getSymbolsByName(names.fromString(methodName))) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   942
                if (sym != null &&
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
   943
                    sym.kind == MTH) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
                    //### Should intern methodName as Name.
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   945
                    if (hasParameterTypes((MethodSymbol)sym, paramTypes)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
   946
                        return env.getMethodDoc((MethodSymbol)sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
        //### If we found a MethodDoc above, but which did not pass
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
        //### the modifier filter, we should return failure here!
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
        // search superclass
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
        cdi = (ClassDocImpl)superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
        if (cdi != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
            mdi = cdi.searchMethod(methodName, paramTypes, searched);
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
            if (mdi != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
                return mdi;
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
        // search interfaces
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 21020
diff changeset
   965
        for (ClassDoc intf : interfaces()) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 21020
diff changeset
   966
            cdi = (ClassDocImpl) intf;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
            mdi = cdi.searchMethod(methodName, paramTypes, searched);
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
            if (mdi != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
                return mdi;
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
        // search enclosing class
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
        cdi = (ClassDocImpl)containingClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
        if (cdi != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
            mdi = cdi.searchMethod(methodName, paramTypes, searched);
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
            if (mdi != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
                return mdi;
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
        //###(gj) As a temporary measure until type variables are better
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
        //### handled, try again without the parameter types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
        //### This should most often find the right method, and occassionally
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
        //### find the wrong one.
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
        //if (paramTypes != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
        //    return findMethod(methodName, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
        //}
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
     * Find constructor in this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
     * @param constrName the unqualified name to search for.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   997
     * @param paramTypes the array of Strings for constructor parameters.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
     * @return the first ConstructorDocImpl which matches, null if not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
    public ConstructorDoc findConstructor(String constrName,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
                                          String[] paramTypes) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
  1002
        Names names = tsym.name.table.names;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
  1003
        for (Symbol sym : tsym.members().getSymbolsByName(names.fromString("<init>"))) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
  1004
            if (sym.kind == MTH) {
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
  1005
                if (hasParameterTypes((MethodSymbol)sym, paramTypes)) {
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
  1006
                    return env.getConstructorDoc((MethodSymbol)sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
        //###(gj) As a temporary measure until type variables are better
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
        //### handled, try again without the parameter types.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
        //### This will often find the right constructor, and occassionally
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
        //### find the wrong one.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
        //if (paramTypes != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
        //    return findConstructor(constrName, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
        //}
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
     * Find a field in this class scope.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
     * Search order: this class, outerclasses, interfaces,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
     * superclasses. IMP: If see tag is defined in an inner class,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
     * which extends a super class and if outerclass and the super
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
     * class have a visible field in common then Java compiler cribs
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
     * about the ambiguity, but the following code will search in the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
     * above given search order.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
     * @param fieldName the unqualified name to search for.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
     * @return the first FieldDocImpl which matches, null if not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
    public FieldDoc findField(String fieldName) {
22165
ec53c8946fc2 8030807: langtools should still build using jdk 7
vromero
parents: 22163
diff changeset
  1035
        return searchField(fieldName, new HashSet<ClassDocImpl>());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
    private FieldDocImpl searchField(String fieldName, Set<ClassDocImpl> searched) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
  1039
        Names names = tsym.name.table.names;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
        if (searched.contains(this)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
        searched.add(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
  1045
        for (Symbol sym : tsym.members().getSymbolsByName(names.fromString(fieldName))) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
  1046
            if (sym.kind == VAR) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
                //### Should intern fieldName as Name.
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 23799
diff changeset
  1048
                return env.getFieldDoc((VarSymbol)sym);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
        //### If we found a FieldDoc above, but which did not pass
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
        //### the modifier filter, we should return failure here!
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
        ClassDocImpl cdi = (ClassDocImpl)containingClass();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
        if (cdi != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
            FieldDocImpl fdi = cdi.searchField(fieldName, searched);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
            if (fdi != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
                return fdi;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
        // search superclass
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
        cdi = (ClassDocImpl)superclass();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
        if (cdi != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
            FieldDocImpl fdi = cdi.searchField(fieldName, searched);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
            if (fdi != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
                return fdi;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
        // search interfaces
22159
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 21020
diff changeset
  1073
        for (ClassDoc intf : interfaces()) {
682da512ec17 8030253: Update langtools to use strings-in-switch
briangoetz
parents: 21020
diff changeset
  1074
            cdi = (ClassDocImpl) intf;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
            FieldDocImpl fdi = cdi.searchField(fieldName, searched);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
            if (fdi != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
                return fdi;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
     * Get the list of classes declared as imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
     * These are called "single-type-import declarations" in the JLS.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
     * This method is deprecated in the ClassDoc interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
     * @return an array of ClassDocImpl representing the imported classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
     * @deprecated  Import declarations are implementation details that
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
     *          should not be exposed here.  In addition, not all imported
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
     *          classes are imported through single-type-import declarations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
     */
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
  1095
    @Deprecated(since="9", forRemoval=true)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
    public ClassDoc[] importedClasses() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
        // information is not available for binary classfiles
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
        if (tsym.sourcefile == null) return new ClassDoc[0];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
  1100
        ListBuffer<ClassDocImpl> importedClasses = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
        Env<AttrContext> compenv = env.enter.getEnv(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
        if (compenv == null) return new ClassDocImpl[0];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
  1105
        Name asterisk = tsym.name.table.names.asterisk;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
        for (JCTree t : compenv.toplevel.defs) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10203
diff changeset
  1107
            if (t.hasTag(IMPORT)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
                JCTree imp = ((JCImport) t).qualid;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
                if ((TreeInfo.name(imp) != asterisk) &&
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 25874
diff changeset
  1110
                    imp.type.tsym.kind.matches(KindSelector.TYP)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
                    importedClasses.append(
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
                            env.getClassDoc((ClassSymbol)imp.type.tsym));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
        return importedClasses.toArray(new ClassDocImpl[importedClasses.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
06bc494ca11e Initial load
duke
parents:
diff changeset
  1120
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
     * Get the list of packages declared as imported.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
     * These are called "type-import-on-demand declarations" in the JLS.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
     * This method is deprecated in the ClassDoc interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
     * @return an array of PackageDocImpl representing the imported packages.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
     * ###NOTE: the syntax supports importing all inner classes from a class as well.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
     * @deprecated  Import declarations are implementation details that
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
     *          should not be exposed here.  In addition, this method's
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
     *          return type does not allow for all type-import-on-demand
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
     *          declarations to be returned.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
     */
48840
5e2d2067da48 8194651: javadoc: mark the com.sun.javadoc API for removal
ksrini
parents: 47216
diff changeset
  1133
    @Deprecated(since="9", forRemoval=true)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
    public PackageDoc[] importedPackages() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
        // information is not available for binary classfiles
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
        if (tsym.sourcefile == null) return new PackageDoc[0];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22159
diff changeset
  1138
        ListBuffer<PackageDocImpl> importedPackages = new ListBuffer<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
        //### Add the implicit "import java.lang.*" to the result
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 10
diff changeset
  1141
        Names names = tsym.name.table.names;
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 32800
diff changeset
  1142
        importedPackages.append(env.getPackageDoc(env.syms.enterPackage(env.syms.java_base, names.java_lang)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
        Env<AttrContext> compenv = env.enter.getEnv(tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
        if (compenv == null) return new PackageDocImpl[0];
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
        for (JCTree t : compenv.toplevel.defs) {
10950
e87b50888909 6921494: provide way to print javac tree tag values
jjg
parents: 10203
diff changeset
  1148
            if (t.hasTag(IMPORT)) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
                JCTree imp = ((JCImport) t).qualid;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
                if (TreeInfo.name(imp) == names.asterisk) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
                    JCFieldAccess sel = (JCFieldAccess)imp;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
                    Symbol s = sel.selected.type.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
                    PackageDocImpl pdoc = env.getPackageDoc(s.packge());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
                    if (!importedPackages.contains(pdoc))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1155
                        importedPackages.append(pdoc);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
        return importedPackages.toArray(new PackageDocImpl[importedPackages.length()]);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
     * Return the type's dimension information.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1165
     * Always return "", as this is not an array type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
    public String dimension() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
        return "";
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
     * Return this type as a class, which it already is.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
    public ClassDoc asClassDoc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1179
     * Return null (unless overridden), as this is not an annotation type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
    public AnnotationTypeDoc asAnnotationTypeDoc() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
     * Return null, as this is not a class instantiation.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
    public ParameterizedType asParameterizedType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
     * Return null, as this is not a type variable.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
    public TypeVariable asTypeVariable() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
     * Return null, as this is not a wildcard type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
    public WildcardType asWildcardType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
    /**
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14951
diff changeset
  1207
     * Returns null, as this is not an annotated type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14951
diff changeset
  1208
     */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14951
diff changeset
  1209
    public AnnotatedType asAnnotatedType() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14951
diff changeset
  1210
        return null;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14951
diff changeset
  1211
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14951
diff changeset
  1212
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14951
diff changeset
  1213
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
     * Return false, as this is not a primitive type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
    public boolean isPrimitive() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
    //--- Serialization ---
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
06bc494ca11e Initial load
duke
parents:
diff changeset
  1222
    //### These methods ignore modifier filter.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
     * Return true if this class implements <code>java.io.Serializable</code>.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1226
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1227
     * Since <code>java.io.Externalizable</code> extends
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
     * <code>java.io.Serializable</code>,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1229
     * Externalizable objects are also Serializable.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
    public boolean isSerializable() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1233
            return env.types.isSubtype(type, env.syms.serializableType);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
            // quietly ignore completion failures
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
     * Return true if this class implements
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
     * <code>java.io.Externalizable</code>.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
    public boolean isExternalizable() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
        try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
            return env.types.isSubtype(type, env.externalizableSym.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
        } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
            // quietly ignore completion failures
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
     * Return the serialization methods for this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1256
     * @return an array of <code>MethodDocImpl</code> that represents
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
     * the serialization methods for this class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1259
    public MethodDoc[] serializationMethods() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
        if (serializedForm == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
            serializedForm = new SerializedForm(env, tsym, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
        //### Clone this?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
        return serializedForm.methods();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1266
06bc494ca11e Initial load
duke
parents:
diff changeset
  1267
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1268
     * Return the Serializable fields of class.<p>
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
     * Return either a list of default fields documented by
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
     * <code>serial</code> tag<br>
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
     * or return a single <code>FieldDoc</code> for
06bc494ca11e Initial load
duke
parents:
diff changeset
  1273
     * <code>serialPersistentField</code> member.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
     * There should be a <code>serialField</code> tag for
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
     * each Serializable field defined by an <code>ObjectStreamField</code>
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
     * array component of <code>serialPersistentField</code>.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1277
     *
31751
ec251536a004 8080880: some docs cleanup for langtools
avstepan
parents: 30066
diff changeset
  1278
     * @return an array of {@code FieldDoc} for the Serializable fields
ec251536a004 8080880: some docs cleanup for langtools
avstepan
parents: 30066
diff changeset
  1279
     *         of this class.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
     * @see #definesSerializableFields()
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
     * @see SerialFieldTagImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
    public FieldDoc[] serializableFields() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
        if (serializedForm == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
            serializedForm = new SerializedForm(env, tsym, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1287
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
        //### Clone this?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
        return serializedForm.fields();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
06bc494ca11e Initial load
duke
parents:
diff changeset
  1292
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
     * Return true if Serializable fields are explicitly defined with
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
     * the special class member <code>serialPersistentFields</code>.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1295
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1296
     * @see #serializableFields()
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
     * @see SerialFieldTagImpl
06bc494ca11e Initial load
duke
parents:
diff changeset
  1298
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
    public boolean definesSerializableFields() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
        if (!isSerializable() || isExternalizable()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1301
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
            if (serializedForm == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1304
                serializedForm = new SerializedForm(env, tsym, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
            //### Clone this?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1307
            return serializedForm.definesSerializableFields();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1308
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1309
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1310
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
     * Determine if a class is a RuntimeException.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
     * <p>
06bc494ca11e Initial load
duke
parents:
diff changeset
  1314
     * Used only by ThrowsTagImpl.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1315
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1316
    boolean isRuntimeException() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1317
        return tsym.isSubClass(env.syms.runtimeExceptionType.tsym, env.types);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1321
     * Return the source position of the entity, or null if
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
     * no position is available.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
     */
8631
664f84942e74 6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup
jjg
parents: 7681
diff changeset
  1324
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
    public SourcePosition position() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1326
        if (tsym.sourcefile == null) return null;
1869
0e193a8f3520 6794582: javadoc should read files using a FileManager
jjg
parents: 1264
diff changeset
  1327
        return SourcePositionImpl.make(tsym.sourcefile,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1328
                                       (tree==null) ? Position.NOPOS : tree.pos,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
                                       lineMap);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
}