langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
author jjg
Tue, 09 Sep 2008 10:28:21 -0700
changeset 1257 873b053bf757
parent 1045 56f6e84f7825
child 1260 a772ba9ba43d
permissions -rw-r--r--
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
735
372aa565a221 6719955: Update copyright year
xdono
parents: 169
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  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
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.Set;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.util.concurrent.Callable;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import javax.lang.model.element.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import javax.tools.JavaFileObject;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.util.Name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.comp.Attr;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import com.sun.tools.javac.comp.AttrContext;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import com.sun.tools.javac.comp.Env;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
import com.sun.tools.javac.jvm.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import com.sun.tools.javac.model.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import com.sun.tools.javac.tree.JCTree;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import static com.sun.tools.javac.code.Kinds.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
import static com.sun.tools.javac.code.TypeTags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
/** Root class for Java symbols. It contains subclasses
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *  for specific sorts of symbols, such as variables, methods and operators,
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  types, packages. Each subclass is represented as a static inner class
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *  inside Symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
public abstract class Symbol implements Element {
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    // public Throwable debug = new Throwable();
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    /** The kind of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     *  @see Kinds
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    public int kind;
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /** The flags of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    public long flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    /** An accessor method for the flags of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     *  Flags of class symbols should be accessed through the accessor
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     *  method to make sure that the class symbol is loaded.
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    public long flags() { return flags_field; }
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    /** The attributes of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    public List<Attribute.Compound> attributes_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    /** An accessor method for the attributes of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
     *  Attributes of class symbols should be accessed through the accessor
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     *  method to make sure that the class symbol is loaded.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    public List<Attribute.Compound> getAnnotationMirrors() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
        assert attributes_field != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
        return attributes_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    /** Fetch a particular annotation from a symbol. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    public Attribute.Compound attribute(Symbol anno) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        for (Attribute.Compound a : getAnnotationMirrors())
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            if (a.type.tsym == anno) return a;
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /** The name of this symbol in Utf8 representation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
    public Name name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
    /** The type of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    public Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    /** The owner of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    public Symbol owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    /** The completer of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
    public Completer completer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    /** A cache for the type erasure of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    public Type erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    /** Construct a symbol with given kind, flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    public Symbol(int kind, long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
        this.kind = kind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        this.flags_field = flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        this.type = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        this.owner = owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        this.completer = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        this.erasure_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        this.attributes_field = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     *  Legal only for fields and methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    public Symbol clone(Symbol newOwner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
     *  A description of this symbol; overrides Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        return name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    /** A Java source description of the location of this symbol; used for
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   143
     *  error reporting.
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   144
     *
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   145
     * @return null if the symbol is a package or a toplevel class defined in
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   146
     * the default package; otherwise, the owner symbol is returned
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
     */
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   148
    public Symbol location() {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
        if (owner.name == null || (owner.name.len == 0 && owner.kind != PCK)) {
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   150
            return null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   152
        return owner;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   155
    public Symbol location(Type site, Types types) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        if (owner.name == null || owner.name.len == 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
            return location();
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        if (owner.type.tag == CLASS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
            Type ownertype = types.asOuterSuper(site, owner);
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   161
            if (ownertype != null) return ownertype.tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
        }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   163
        return owner;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    /** The symbol's erased type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    public Type erasure(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
        if (erasure_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
            erasure_field = types.erasure(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
        return erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    /** The external type of a symbol. This is the symbol's erased type
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     *  except for constructors of inner classes which get the enclosing
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     *  instance class added as first argument.
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    public Type externalType(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        Type t = erasure(types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        if (name == name.table.init && owner.hasOuterInstance()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
            Type outerThisType = types.erasure(owner.type.getEnclosingType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            return new MethodType(t.getParameterTypes().prepend(outerThisType),
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
                                  t.getReturnType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
                                  t.getThrownTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
                                  t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    public boolean isStatic() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
            (flags() & STATIC) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
            (owner.flags() & INTERFACE) != 0 && kind != MTH;
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
    public boolean isInterface() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        return (flags() & INTERFACE) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    /** Is this symbol declared (directly or indirectly) local
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     *  to a method or variable initializer?
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     *  Also includes fields of inner classes which are in
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     *  turn local to a method or variable initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    public boolean isLocal() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            (owner.kind & (VAR | MTH)) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            (owner.kind == TYP && owner.isLocal());
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    /** Is this symbol a constructor?
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    public boolean isConstructor() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
        return name == name.table.init;
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
    /** The fully qualified name of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     *  This is the same as the symbol's name except for class symbols,
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     *  which are handled separately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
    public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    /** The fully qualified name of this symbol after converting to flat
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     *  representation. This is the same as the symbol's name except for
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     *  class symbols, which are handled separately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    public Name flatName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        return getQualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    /** If this is a class or package, its members, otherwise null.
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    public Scope members() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    /** A class is an inner class if it it has an enclosing instance class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
    public boolean isInner() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        return type.getEnclosingType().tag == CLASS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    /** An inner class has an outer instance if it is not an interface
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     *  it has an enclosing instance class which might be referenced from the class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     *  Nested classes can see instance members of their enclosing class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
     *  Their constructors carry an additional this$n parameter, inserted
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     *  implicitly by the compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     *  @see #isInner
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    public boolean hasOuterInstance() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
            type.getEnclosingType().tag == CLASS && (flags() & (INTERFACE | NOOUTERTHIS)) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    /** The closest enclosing class of this symbol's declaration.
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    public ClassSymbol enclClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
        Symbol c = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
        while (c != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
               ((c.kind & TYP) == 0 || c.type.tag != CLASS)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
            c = c.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        return (ClassSymbol)c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    /** The outermost class which indirectly owns this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
    public ClassSymbol outermostClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        Symbol sym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        Symbol prev = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        while (sym.kind != PCK) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
            prev = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            sym = sym.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        return (ClassSymbol) prev;
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
    /** The package which indirectly owns this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    public PackageSymbol packge() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        Symbol sym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        while (sym.kind != PCK) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
            sym = sym.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        return (PackageSymbol) sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    /** Is this symbol a subclass of `base'? Only defined for ClassSymbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    public boolean isSubClass(Symbol base, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        throw new AssertionError("isSubClass " + this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    /** Fully check membership: hierarchy, protection, and hiding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     *  Does not exclude methods not inherited due to overriding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
    public boolean isMemberOf(TypeSymbol clazz, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
            owner == clazz ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
            clazz.isSubClass(owner, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
            isInheritedIn(clazz, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
            !hiddenIn((ClassSymbol)clazz, types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
    /** Is this symbol the same as or enclosed by the given class? */
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    public boolean isEnclosedBy(ClassSymbol clazz) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        for (Symbol sym = this; sym.kind != PCK; sym = sym.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
            if (sym == clazz) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    /** Check for hiding.  Note that this doesn't handle multiple
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
     *  (interface) inheritance. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    private boolean hiddenIn(ClassSymbol clazz, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        if (kind == MTH && (flags() & STATIC) == 0) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
        while (true) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
            if (owner == clazz) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
            Scope.Entry e = clazz.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
            while (e.scope != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
                if (e.sym == this) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
                if (e.sym.kind == kind &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
                    (kind != MTH ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
                     (e.sym.flags() & STATIC) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
                     types.isSubSignature(e.sym.type, type)))
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
                    return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
                e = e.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
            Type superType = types.supertype(clazz.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
            if (superType.tag != TypeTags.CLASS) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
            clazz = (ClassSymbol)superType.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
    /** Is this symbol inherited into a given class?
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
     *  PRE: If symbol's owner is a interface,
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
     *       it is already assumed that the interface is a superinterface
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
     *       of given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
     *  @param clazz  The class for which we want to establish membership.
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
     *                This must be a subclass of the member's owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
    public boolean isInheritedIn(Symbol clazz, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
        switch ((int)(flags_field & Flags.AccessFlags)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
        default: // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
        case PUBLIC:
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        case PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
            return this.owner == clazz;
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
        case PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
            // we model interfaces as extending Object
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
            return (clazz.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            PackageSymbol thisPackage = this.packge();
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
            for (Symbol sup = clazz;
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
                 sup != null && sup != this.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
                 sup = types.supertype(sup.type).tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
                if (sup.type.isErroneous())
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
                    return true; // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
                if ((sup.flags() & COMPOUND) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
                if (sup.packge() != thisPackage)
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
                    return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
            return (clazz.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    /** The (variable or method) symbol seen as a member of given
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
     *  class type`site' (this might change the symbol's type).
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
     *  This is used exclusively for producing diagnostics.
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
    public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
    /** Does this method symbol override `other' symbol, when both are seen as
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
     *  members of class `origin'?  It is assumed that _other is a member
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
     *  of origin.
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
     *  It is assumed that both symbols have the same name.  The static
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
     *  modifier is ignored for this test.
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
     *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
    /** Complete the elaboration of this symbol's definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
    public void complete() throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        if (completer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
            Completer c = completer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
            completer = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
            c.complete(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    /** True if the symbol represents an entity that exists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
    public boolean exists() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
    public Type asType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
    public Symbol getEnclosingElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
        return owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
    public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        return ElementKind.OTHER;       // most unkind
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
    public Set<Modifier> getModifiers() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        return Flags.asModifierSet(flags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    public Name getSimpleName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
        return name;
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
     * @deprecated this method should never be used by javac internally.
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
    @Deprecated
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
    public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
        return JavacElements.getAnnotation(this, annoType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
    // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
    public java.util.List<Symbol> getEnclosedElements() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
        return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
    public List<TypeSymbol> getTypeParameters() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        ListBuffer<TypeSymbol> l = ListBuffer.lb();
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
        for (Type t : type.getTypeArguments()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
            l.append(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        return l.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
    public static class DelegatedSymbol extends Symbol {
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        protected Symbol other;
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        public DelegatedSymbol(Symbol other) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
            super(other.kind, other.flags_field, other.name, other.type, other.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
            this.other = other;
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        public String toString() { return other.toString(); }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   456
        public Symbol location() { return other.location(); }
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   457
        public Symbol location(Type site, Types types) { return other.location(site, types); }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
        public Type erasure(Types types) { return other.erasure(types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
        public Type externalType(Types types) { return other.externalType(types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        public boolean isLocal() { return other.isLocal(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
        public boolean isConstructor() { return other.isConstructor(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
        public Name getQualifiedName() { return other.getQualifiedName(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        public Name flatName() { return other.flatName(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        public Scope members() { return other.members(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
        public boolean isInner() { return other.isInner(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
        public boolean hasOuterInstance() { return other.hasOuterInstance(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        public ClassSymbol enclClass() { return other.enclClass(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
        public ClassSymbol outermostClass() { return other.outermostClass(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
        public PackageSymbol packge() { return other.packge(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
        public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
        public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
        public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
        public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
        public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
        public void complete() throws CompletionFailure { other.complete(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
            return other.accept(v, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
    /** A class for type symbols. Type variables are represented by instances
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
     *  of this class, classes and packages by instances of subclasses.
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
    public static class TypeSymbol
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
            extends Symbol implements TypeParameterElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        // Implements TypeParameterElement because type parameters don't
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
        // have their own TypeSymbol subclass.
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        // TODO: type parameters should have their own TypeSymbol subclass
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        public TypeSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
            super(TYP, flags, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
        /** form a fully qualified name from a name and an owner
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
        static public Name formFullName(Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
            if (owner == null) return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
            if (((owner.kind != ERR)) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
                ((owner.kind & (VAR | MTH)) != 0
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
                 || (owner.kind == TYP && owner.type.tag == TYPEVAR)
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
                 )) return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
            Name prefix = owner.getQualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
            if (prefix == null || prefix == prefix.table.empty)
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
                return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
            else return prefix.append('.', name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
        /** form a fully qualified name from a name and an owner, after
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
         *  converting to flat representation
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        static public Name formFlatName(Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
            if (owner == null ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
                (owner.kind & (VAR | MTH)) != 0
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
                || (owner.kind == TYP && owner.type.tag == TYPEVAR)
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
                ) return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
            char sep = owner.kind == TYP ? '$' : '.';
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
            Name prefix = owner.flatName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
            if (prefix == null || prefix == prefix.table.empty)
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
                return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
            else return prefix.append(sep, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
         * A total ordering between type symbols that refines the
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
         * class inheritance graph.
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
         * Typevariables always precede other kinds of symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
        public final boolean precedes(TypeSymbol that, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
            if (this == that)
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
            if (this.type.tag == that.type.tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
                if (this.type.tag == CLASS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
                    return
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
                        types.rank(that.type) < types.rank(this.type) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
                        types.rank(that.type) == types.rank(this.type) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
                        that.getQualifiedName().compareTo(this.getQualifiedName()) < 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
                } else if (this.type.tag == TYPEVAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
                    return types.isSubtype(this.type, that.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
            return this.type.tag == TYPEVAR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
        // For type params; overridden in subclasses.
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
            return ElementKind.TYPE_PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        public java.util.List<Symbol> getEnclosedElements() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            List<Symbol> list = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
            for (Scope.Entry e = members().elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
                if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this)
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
                    list = list.prepend(e.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
            return list;
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
        // For type params.
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        // Perhaps not needed if getEnclosingElement can be spec'ed
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
        // to do the same thing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        // TODO: getGenericElement() might not be needed
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        public Symbol getGenericElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
            return owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            assert type.tag == TYPEVAR; // else override will be invoked
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
            return v.visitTypeParameter(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
        public List<Type> getBounds() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
            TypeVar t = (TypeVar)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
            Type bound = t.getUpperBound();
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
            if (!bound.isCompound())
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
                return List.of(bound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
            ClassType ct = (ClassType)bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
            if (!ct.tsym.erasure_field.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
                return ct.interfaces_field.prepend(ct.supertype_field);
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
                // No superclass was given in bounds.
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
                // In this case, supertype is Object, erasure is first interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
                return ct.interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
    /** A class for package symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
    public static class PackageSymbol extends TypeSymbol
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
        implements PackageElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        public Scope members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
        public Name fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
        public ClassSymbol package_info; // see bug 6443073
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
        public PackageSymbol(Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
            super(0, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
            this.kind = PCK;
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
            this.members_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
            this.fullname = formFullName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
        public PackageSymbol(Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
            this(name, null, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
            this.type = new PackageType(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
            return fullname.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
        public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
            return fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
        public boolean isUnnamed() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
            return name.isEmpty() && owner != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
        public Scope members() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
            return members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
        public long flags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
            return flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
        public List<Attribute.Compound> getAnnotationMirrors() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
            assert attributes_field != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
            return attributes_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
        /** A package "exists" if a type or package that exists has
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
         *  been seen within it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
        public boolean exists() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
            return (flags_field & EXISTS) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
            return ElementKind.PACKAGE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
        public Symbol getEnclosingElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
            return v.visitPackage(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
    /** A class for class symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
    public static class ClassSymbol extends TypeSymbol implements TypeElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
        /** a scope for all class members; variables, methods and inner classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
         *  type parameters are not part of this scope
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
        public Scope members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
        /** the fully qualified name of the class, i.e. pck.outer.inner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
         *  null for anonymous classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
        public Name fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
        /** the fully qualified name of the class after converting to flat
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
         *  representation, i.e. pck.outer$inner,
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
         *  set externally for local and anonymous classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
        public Name flatname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
        /** the sourcefile where the class came from
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
        public JavaFileObject sourcefile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
        /** the classfile from where to load this class
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
         *  this will have extension .class or .java
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
        public JavaFileObject classfile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
        /** the constant pool of the class
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
        public Pool pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
        public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
            super(flags, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
            this.members_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
            this.fullname = formFullName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
            this.flatname = formFlatName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
            this.sourcefile = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
            this.classfile = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
            this.pool = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
        public ClassSymbol(long flags, Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
            this(
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
                flags,
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
                name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
                new ClassType(Type.noType, null, null),
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
                owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
            this.type.tsym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
        /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
            return className();
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
        public long flags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
            return flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
        public Scope members() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
            return members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
        public List<Attribute.Compound> getAnnotationMirrors() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
            assert attributes_field != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
            return attributes_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
        public Type erasure(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
            if (erasure_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
                erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
                                              List.<Type>nil(), this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
            return erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
        public String className() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
            if (name.len == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
                return
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
                    Log.getLocalizedString("anonymous.class", flatname);
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
                return fullname.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
        public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
            return fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
        public Name flatName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
            return flatname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
        public boolean isSubClass(Symbol base, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
            if (this == base) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
            } else if ((base.flags() & INTERFACE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
                for (Type t = type; t.tag == CLASS; t = types.supertype(t))
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
                    for (List<Type> is = types.interfaces(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
                         is.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
                         is = is.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
                        if (is.head.tsym.isSubClass(base, types)) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
                for (Type t = type; t.tag == CLASS; t = types.supertype(t))
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
                    if (t.tsym == base) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
        /** Complete the elaboration of this symbol's definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
        public void complete() throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
                super.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
            } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
                // quiet error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
                flags_field |= (PUBLIC|STATIC);
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1045
diff changeset
   779
                this.type = new ErrorType(this, Type.noType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
                throw ex;
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
        public List<Type> getInterfaces() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
            complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
            if (type instanceof ClassType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
                ClassType t = (ClassType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
                if (t.interfaces_field == null) // FIXME: shouldn't be null
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
                    t.interfaces_field = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
                return t.interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
                return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
        public Type getSuperclass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
            complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
            if (type instanceof ClassType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
                ClassType t = (ClassType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
                if (t.supertype_field == null) // FIXME: shouldn't be null
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
                    t.supertype_field = Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
                // An interface has no superclass; its supertype is Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
                return t.isInterface()
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
                    ? Type.noType
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
                    : t.supertype_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
                return Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
            long flags = flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
            if ((flags & ANNOTATION) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
                return ElementKind.ANNOTATION_TYPE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
            else if ((flags & INTERFACE) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
                return ElementKind.INTERFACE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
            else if ((flags & ENUM) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
                return ElementKind.ENUM;
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
                return ElementKind.CLASS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
        public NestingKind getNestingKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
            complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
            if (owner.kind == PCK)
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
                return NestingKind.TOP_LEVEL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
            else if (name.isEmpty())
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
                return NestingKind.ANONYMOUS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
            else if (owner.kind == MTH)
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
                return NestingKind.LOCAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
                return NestingKind.MEMBER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
         * @deprecated this method should never be used by javac internally.
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
        @Override @Deprecated
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
        public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
            return JavacElements.getAnnotation(this, annoType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
            return v.visitType(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
    /** A class for variable symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
    public static class VarSymbol extends Symbol implements VariableElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
        /** The variable's declaration position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
        public int pos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
        /** The variable's address. Used for different purposes during
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
         *  flow analysis, translation and code generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
         *  Flow analysis:
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
         *    If this is a blank final or local variable, its sequence number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
         *  Translation:
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
         *    If this is a private field, its access number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
         *  Code generation:
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
         *    If this is a local variable, its logical slot number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
        public int adr = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
        /** Construct a variable symbol, given its flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
        public VarSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
            super(VAR, flags, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
        /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
        public VarSymbol clone(Symbol newOwner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
            VarSymbol v = new VarSymbol(flags_field, name, type, newOwner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
            v.pos = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
            v.adr = adr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
            v.data = data;
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
//          System.out.println("clone " + v + " in " + newOwner);//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
            return v;
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
            return name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   887
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
        public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
            return new VarSymbol(flags_field, name, types.memberType(site, this), owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
            long flags = flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
            if ((flags & PARAMETER) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
                if (isExceptionParameter())
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
                    return ElementKind.EXCEPTION_PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
                    return ElementKind.PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
            } else if ((flags & ENUM) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
                return ElementKind.ENUM_CONSTANT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
            } else if (owner.kind == TYP || owner.kind == ERR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
                return ElementKind.FIELD;
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
                return ElementKind.LOCAL_VARIABLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
            return v.visitVariable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
        public Object getConstantValue() { // Mirror API
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
            return Constants.decode(getConstValue(), type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
        public void setLazyConstValue(final Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
                                      final Log log,
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
                                      final Attr attr,
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
                                      final JCTree.JCExpression initializer)
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
        {
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
            setData(new Callable<Object>() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
                public Object call() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
                    JavaFileObject source = log.useSource(env.toplevel.sourcefile);
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
                    try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
                        Type itype = attr.attribExpr(initializer, env, type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
                        if (itype.constValue() != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
                            return attr.coerce(itype, type).constValue();
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
                        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
                            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
                    } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
                        log.useSource(source);
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
                    }
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
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
         * The variable's constant value, if this is a constant.
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
         * Before the constant value is evaluated, it points to an
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
         * initalizer environment.  If this is not a constant, it can
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
         * be used for other stuff.
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
        private Object data;
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
        public boolean isExceptionParameter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
            return data == ElementKind.EXCEPTION_PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
        public Object getConstValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
            // TODO: Consider if getConstValue and getConstantValue can be collapsed
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
            if (data == ElementKind.EXCEPTION_PARAMETER) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
            } else if (data instanceof Callable<?>) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
                // In this case, this is final a variable, with an as
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
                // yet unevaluated initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
                Callable<?> eval = (Callable<?>)data;
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
                data = null; // to make sure we don't evaluate this twice.
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
                    data = eval.call();
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
                } catch (Exception ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
                    throw new AssertionError(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
            return data;
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
        public void setData(Object data) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
            assert !(data instanceof Env<?>) : this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
            this.data = data;
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
    /** A class for method symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
    public static class MethodSymbol extends Symbol implements ExecutableElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
        /** The code of the method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
        public Code code = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
        /** The parameters of the method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
        public List<VarSymbol> params = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
        /** The names of the parameters */
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
        public List<Name> savedParameterNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
        /** For an attribute field accessor, its default value if any.
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
         *  The value is null if none appeared in the method
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
         *  declaration.
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
        public Attribute defaultValue = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
        /** Construct a method symbol, given its flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
        public MethodSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
            super(MTH, flags, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   997
            assert owner.type.tag != TYPEVAR : owner + "." + name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
        /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
        public MethodSymbol clone(Symbol newOwner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
            MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
            m.code = code;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
            return m;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
        /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
            if ((flags() & BLOCK) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
                return owner.name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
                String s = (name == name.table.init)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
                    ? owner.name.toString()
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
                    : name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
                if (type != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
                    if (type.tag == FORALL)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
                        s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
                    s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
                return s;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
        /** find a symbol that this (proxy method) symbol implements.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
         *  @param    c       The class whose members are searched for
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
         *                    implementations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
        public Symbol implemented(TypeSymbol c, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
            Symbol impl = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
            for (List<Type> is = types.interfaces(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
                 impl == null && is.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
                 is = is.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
                TypeSymbol i = is.head.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
                for (Scope.Entry e = i.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
                     impl == null && e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
                     e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
                    if (this.overrides(e.sym, (TypeSymbol)owner, types, true) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
                        // FIXME: I suspect the following requires a
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
                        // subst() for a parametric return type.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
                        types.isSameType(type.getReturnType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
                                         types.memberType(owner.type, e.sym).getReturnType())) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
                        impl = e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
                    if (impl == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
                        impl = implemented(i, types);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
            return impl;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
        /** Will the erasure of this method be considered by the VM to
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
         *  override the erasure of the other when seen from class `origin'?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
        public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
            if (isConstructor() || _other.kind != MTH) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
            if (this == _other) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
            MethodSymbol other = (MethodSymbol)_other;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
            // check for a direct implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
            if (other.isOverridableIn((TypeSymbol)owner) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
                types.asSuper(owner.type, other.owner) != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
                types.isSameType(erasure(types), other.erasure(types)))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
            // check for an inherited implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
                (flags() & ABSTRACT) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
                other.isOverridableIn(origin) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
                this.isMemberOf(origin, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
                types.isSameType(erasure(types), other.erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
        /** The implementation of this (abstract) symbol in class origin,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
         *  from the VM's point of view, null if method does not have an
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
         *  implementation in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
         *  @param origin   The class of which the implementation is a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
        public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
            for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
                for (Scope.Entry e = c.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
                     e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
                     e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
                    if (e.sym.kind == MTH &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
                        ((MethodSymbol)e.sym).binaryOverrides(this, origin, types))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
                        return (MethodSymbol)e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
        /** Does this symbol override `other' symbol, when both are seen as
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
         *  members of class `origin'?  It is assumed that _other is a member
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
         *  of origin.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
         *  It is assumed that both symbols have the same name.  The static
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
         *  modifier is ignored for this test.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
         *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
        public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
            if (isConstructor() || _other.kind != MTH) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
            if (this == _other) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
            MethodSymbol other = (MethodSymbol)_other;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
            // check for a direct implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
            if (other.isOverridableIn((TypeSymbol)owner) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
                types.asSuper(owner.type, other.owner) != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
                Type mt = types.memberType(owner.type, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
                Type ot = types.memberType(owner.type, other);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
                if (types.isSubSignature(mt, ot)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
                    if (!checkResult)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
                        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
                    if (types.returnTypeSubstitutable(mt, ot))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
                        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1120
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
            // check for an inherited implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
            if ((flags() & ABSTRACT) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
                (other.flags() & ABSTRACT) == 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
                !other.isOverridableIn(origin) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
                !this.isMemberOf(origin, types))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
            // assert types.asSuper(origin.type, other.owner) != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
            Type mt = types.memberType(origin.type, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
            Type ot = types.memberType(origin.type, other);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
                types.isSubSignature(mt, ot) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
                (!checkResult || types.resultSubtype(mt, ot, Warner.noWarnings));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
        private boolean isOverridableIn(TypeSymbol origin) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
            // JLS3 8.4.6.1
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
            switch ((int)(flags_field & Flags.AccessFlags)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
            case Flags.PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
            case Flags.PUBLIC:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
            case Flags.PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
                return (origin.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
            case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
                // for package private: can only override in the same
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
                // package
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
                return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
                    this.packge() == origin.packge() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
                    (origin.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1155
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
        /** The implementation of this (abstract) symbol in class origin;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
         *  null if none exists. Synthetic methods are not considered
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
         *  as possible implementations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
        public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
            for (Type t = origin.type; t.tag == CLASS; t = types.supertype(t)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
                TypeSymbol c = t.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
                for (Scope.Entry e = c.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1165
                     e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
                     e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
                    if (e.sym.kind == MTH) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
                        MethodSymbol m = (MethodSymbol) e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
                        if (m.overrides(this, origin, types, checkResult) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
                            (m.flags() & SYNTHETIC) == 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
                            return m;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
            // if origin is derived from a raw type, we might have missed
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
            // an implementation because we do not know enough about instantiations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
            // in this case continue with the supertype as origin.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
            if (types.isDerivedRaw(origin.type))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1179
                return implementation(types.supertype(origin.type).tsym, types, checkResult);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
        public List<VarSymbol> params() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
            owner.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
            if (params == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
                List<Name> names = savedParameterNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
                savedParameterNames = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
                if (names == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
                    names = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
                    int i = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
                    for (Type t : type.getParameterTypes())
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
                        names = names.prepend(name.table.fromString("arg" + i++));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
                    names = names.reverse();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
                ListBuffer<VarSymbol> buf = new ListBuffer<VarSymbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
                for (Type t : type.getParameterTypes()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
                    buf.append(new VarSymbol(PARAMETER, names.head, t, this));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
                    names = names.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
                params = buf.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
            return params;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
        public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
            return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1208
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1209
06bc494ca11e Initial load
duke
parents:
diff changeset
  1210
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1211
            if (name == name.table.init)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
                return ElementKind.CONSTRUCTOR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
            else if (name == name.table.clinit)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
                return ElementKind.STATIC_INIT;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
                return ElementKind.METHOD;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
        public Attribute getDefaultValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
            return defaultValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1222
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
        public List<VarSymbol> getParameters() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
            return params();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1226
06bc494ca11e Initial load
duke
parents:
diff changeset
  1227
        public boolean isVarArgs() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
            return (flags() & VARARGS) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1229
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
            return v.visitExecutable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1233
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
        public Type getReturnType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
            return asType().getReturnType();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
        public List<Type> getThrownTypes() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
            return asType().getThrownTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
    /** A class for predefined operators.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
    public static class OperatorSymbol extends MethodSymbol {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
        public int opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
        public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
            super(PUBLIC | STATIC, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
            this.opcode = opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1254
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
06bc494ca11e Initial load
duke
parents:
diff changeset
  1256
    /** Symbol completer interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
    public static interface Completer {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1259
        void complete(Symbol sym) throws CompletionFailure;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
    public static class CompletionFailure extends RuntimeException {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
        public Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1266
        /** A diagnostic object describing the failure
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1267
         */
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1268
        public JCDiagnostic diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1269
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
        /** A localized string describing the failure.
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1271
         * @deprecated Use {@code getDetail()} or {@code getMessage()}
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
         */
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1273
        @Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
        public String errmsg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
        public CompletionFailure(Symbol sym, String errmsg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1277
            this.sym = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1278
            this.errmsg = errmsg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
//          this.printStackTrace();//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1282
        public CompletionFailure(Symbol sym, JCDiagnostic diag) {
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1283
            this.sym = sym;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1284
            this.diag = diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1285
//          this.printStackTrace();//DEBUG
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1286
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1287
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1288
        public JCDiagnostic getDiagnostic() {
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1289
            return diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1290
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1291
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1292
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
        public String getMessage() {
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1294
            if (diag != null)
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1295
                return diag.getMessage(null);
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1296
            else
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1297
                return errmsg;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1298
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1299
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1300
        public Object getDetailValue() {
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1301
            return (diag != null ? diag : errmsg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
06bc494ca11e Initial load
duke
parents:
diff changeset
  1304
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
        public CompletionFailure initCause(Throwable cause) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
            super.initCause(cause);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1307
            return this;
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
}