langtools/src/share/classes/com/sun/tools/javac/code/Symbol.java
author mcimadamore
Wed, 26 Sep 2012 14:22:41 +0100
changeset 14051 9097cec96212
parent 14046 8ef5d5b19998
child 14062 b7439971a094
permissions -rw-r--r--
7188968: New instance creation expression using diamond is checked twice Summary: Unify method and constructor check logic Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
     2
 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5321
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5321
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5321
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5321
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5321
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.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
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    52
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    53
 *  If you write code that depends on this, you do so at your own risk.
10
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
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
    75
    /** The attributes of this symbol are contained in this
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
    76
     * Annotations. The Annotations instance is NOT immutable.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     */
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
    78
    public final Annotations annotations = new Annotations(this);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /** An accessor method for the attributes of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     *  Attributes of class symbols should be accessed through the accessor
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     *  method to make sure that the class symbol is loaded.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    public List<Attribute.Compound> getAnnotationMirrors() {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
    85
        return Assert.checkNonNull(annotations.getAttributes());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    /** Fetch a particular annotation from a symbol. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
    public Attribute.Compound attribute(Symbol anno) {
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
    90
        for (Attribute.Compound a : getAnnotationMirrors()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            if (a.type.tsym == anno) return a;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
    92
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    /** The name of this symbol in Utf8 representation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    public Name name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /** The type of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    public Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    /** The owner of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    public Symbol owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    /** The completer of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    public Completer completer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    /** A cache for the type erasure of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    public Type erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    /** Construct a symbol with given kind, flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    public Symbol(int kind, long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        this.kind = kind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        this.flags_field = flags;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        this.type = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        this.owner = owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        this.completer = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        this.erasure_field = null;
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
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   135
    public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   136
        return v.visitSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   137
    }
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   138
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
     *  A description of this symbol; overrides Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
        return name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    /** 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
   147
     *  error reporting.
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   148
     *
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   149
     * @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
   150
     * the default package; otherwise, the owner symbol is returned
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
    public Symbol location() {
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
   153
        if (owner.name == null || (owner.name.isEmpty() &&
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
   154
                (owner.flags() & BLOCK) == 0 && owner.kind != PCK && owner.kind != TYP)) {
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   155
            return null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
        }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   157
        return owner;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   160
    public Symbol location(Type site, Types types) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   161
        if (owner.name == null || owner.name.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
            return location();
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        if (owner.type.tag == CLASS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
            Type ownertype = types.asOuterSuper(site, owner);
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   166
            if (ownertype != null) return ownertype.tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
        }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   168
        return owner;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
14051
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   171
    public Symbol baseSymbol() {
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   172
        return this;
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   173
    }
9097cec96212 7188968: New instance creation expression using diamond is checked twice
mcimadamore
parents: 14046
diff changeset
   174
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    /** The symbol's erased type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    public Type erasure(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
        if (erasure_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
            erasure_field = types.erasure(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
        return erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    /** The external type of a symbol. This is the symbol's erased type
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     *  except for constructors of inner classes which get the enclosing
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     *  instance class added as first argument.
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    public Type externalType(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        Type t = erasure(types);
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   189
        if (name == name.table.names.init && owner.hasOuterInstance()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
            Type outerThisType = types.erasure(owner.type.getEnclosingType());
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
            return new MethodType(t.getParameterTypes().prepend(outerThisType),
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
                                  t.getReturnType(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
                                  t.getThrownTypes(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
                                  t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
            return t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    public boolean isStatic() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
            (flags() & STATIC) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
            (owner.flags() & INTERFACE) != 0 && kind != MTH;
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    public boolean isInterface() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        return (flags() & INTERFACE) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    /** Is this symbol declared (directly or indirectly) local
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     *  to a method or variable initializer?
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     *  Also includes fields of inner classes which are in
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     *  turn local to a method or variable initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    public boolean isLocal() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
            (owner.kind & (VAR | MTH)) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
            (owner.kind == TYP && owner.isLocal());
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   221
    /** Has this symbol an empty name? This includes anonymous
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   222
     *  inner classses.
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   223
     */
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   224
    public boolean isAnonymous() {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   225
        return name.isEmpty();
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   226
    }
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5006
diff changeset
   227
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
    /** Is this symbol a constructor?
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    public boolean isConstructor() {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   231
        return name == name.table.names.init;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    /** The fully qualified name of this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
     *  This is the same as the symbol's name except for class symbols,
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
     *  which are handled separately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
    /** The fully qualified name of this symbol after converting to flat
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     *  representation. This is the same as the symbol's name except for
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     *  class symbols, which are handled separately.
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    public Name flatName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
        return getQualifiedName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
    /** If this is a class or package, its members, otherwise null.
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
    public Scope members() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    /** A class is an inner class if it it has an enclosing instance class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    public boolean isInner() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
        return type.getEnclosingType().tag == CLASS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
    /** An inner class has an outer instance if it is not an interface
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     *  it has an enclosing instance class which might be referenced from the class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     *  Nested classes can see instance members of their enclosing class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     *  Their constructors carry an additional this$n parameter, inserted
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     *  implicitly by the compiler.
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     *  @see #isInner
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    public boolean hasOuterInstance() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
            type.getEnclosingType().tag == CLASS && (flags() & (INTERFACE | NOOUTERTHIS)) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    /** The closest enclosing class of this symbol's declaration.
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    public ClassSymbol enclClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
        Symbol c = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        while (c != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
               ((c.kind & TYP) == 0 || c.type.tag != CLASS)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            c = c.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        return (ClassSymbol)c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
    /** The outermost class which indirectly owns this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
    public ClassSymbol outermostClass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
        Symbol sym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
        Symbol prev = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
        while (sym.kind != PCK) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
            prev = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
            sym = sym.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        return (ClassSymbol) prev;
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    /** The package which indirectly owns this symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
    public PackageSymbol packge() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        Symbol sym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
        while (sym.kind != PCK) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
            sym = sym.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        return (PackageSymbol) sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    /** Is this symbol a subclass of `base'? Only defined for ClassSymbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    public boolean isSubClass(Symbol base, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        throw new AssertionError("isSubClass " + this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    /** Fully check membership: hierarchy, protection, and hiding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
     *  Does not exclude methods not inherited due to overriding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    public boolean isMemberOf(TypeSymbol clazz, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
            owner == clazz ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
            clazz.isSubClass(owner, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
            isInheritedIn(clazz, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
            !hiddenIn((ClassSymbol)clazz, types);
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    /** Is this symbol the same as or enclosed by the given class? */
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    public boolean isEnclosedBy(ClassSymbol clazz) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
        for (Symbol sym = this; sym.kind != PCK; sym = sym.owner)
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            if (sym == clazz) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
    /** Check for hiding.  Note that this doesn't handle multiple
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
     *  (interface) inheritance. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    private boolean hiddenIn(ClassSymbol clazz, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        if (kind == MTH && (flags() & STATIC) == 0) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        while (true) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
            if (owner == clazz) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            Scope.Entry e = clazz.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            while (e.scope != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                if (e.sym == this) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
                if (e.sym.kind == kind &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                    (kind != MTH ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                     (e.sym.flags() & STATIC) != 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                     types.isSubSignature(e.sym.type, type)))
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
                    return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
                e = e.next();
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            Type superType = types.supertype(clazz.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
            if (superType.tag != TypeTags.CLASS) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
            clazz = (ClassSymbol)superType.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
    /** Is this symbol inherited into a given class?
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
     *  PRE: If symbol's owner is a interface,
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     *       it is already assumed that the interface is a superinterface
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
     *       of given class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
     *  @param clazz  The class for which we want to establish membership.
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
     *                This must be a subclass of the member's owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
    public boolean isInheritedIn(Symbol clazz, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        switch ((int)(flags_field & Flags.AccessFlags)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        default: // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        case PUBLIC:
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
            return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        case PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
            return this.owner == clazz;
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        case PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
            // we model interfaces as extending Object
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
            return (clazz.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
            PackageSymbol thisPackage = this.packge();
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
            for (Symbol sup = clazz;
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
                 sup != null && sup != this.owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
                 sup = types.supertype(sup.type).tsym) {
1528
441d4ec466de 6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents: 1357
diff changeset
   376
                while (sup.type.tag == TYPEVAR)
441d4ec466de 6711619: javac doesn't allow access to protected members in intersection types
mcimadamore
parents: 1357
diff changeset
   377
                    sup = sup.type.getUpperBound().tsym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
                if (sup.type.isErroneous())
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
                    return true; // error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
                if ((sup.flags() & COMPOUND) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
                    continue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
                if (sup.packge() != thisPackage)
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
                    return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
            return (clazz.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
    /** The (variable or method) symbol seen as a member of given
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
     *  class type`site' (this might change the symbol's type).
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
     *  This is used exclusively for producing diagnostics.
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
    public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
    /** Does this method symbol override `other' symbol, when both are seen as
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
     *  members of class `origin'?  It is assumed that _other is a member
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
     *  of origin.
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
     *  It is assumed that both symbols have the same name.  The static
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
     *  modifier is ignored for this test.
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
    public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
    /** Complete the elaboration of this symbol's definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
    public void complete() throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
        if (completer != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
            Completer c = completer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
            completer = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
            c.complete(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
    /** True if the symbol represents an entity that exists.
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
    public boolean exists() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
    public Type asType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
    public Symbol getEnclosingElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
        return owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
    public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
        return ElementKind.OTHER;       // most unkind
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
    public Set<Modifier> getModifiers() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
        return Flags.asModifierSet(flags());
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
    public Name getSimpleName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
        return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
     * @deprecated this method should never be used by javac internally.
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
    @Deprecated
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
    public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        return JavacElements.getAnnotation(this, annoType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
    // TODO: getEnclosedElements should return a javac List, fix in FilteredMemberList
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
    public java.util.List<Symbol> getEnclosedElements() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
    public List<TypeSymbol> getTypeParameters() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        ListBuffer<TypeSymbol> l = ListBuffer.lb();
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
        for (Type t : type.getTypeArguments()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
            l.append(t.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        return l.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
    public static class DelegatedSymbol extends Symbol {
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
        protected Symbol other;
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
        public DelegatedSymbol(Symbol other) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
            super(other.kind, other.flags_field, other.name, other.type, other.owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
            this.other = other;
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
        public String toString() { return other.toString(); }
939
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   474
        public Symbol location() { return other.location(); }
38e24969c7e9 6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents: 735
diff changeset
   475
        public Symbol location(Type site, Types types) { return other.location(site, types); }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
        public Type erasure(Types types) { return other.erasure(types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
        public Type externalType(Types types) { return other.externalType(types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        public boolean isLocal() { return other.isLocal(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        public boolean isConstructor() { return other.isConstructor(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
        public Name getQualifiedName() { return other.getQualifiedName(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
        public Name flatName() { return other.flatName(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
        public Scope members() { return other.members(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
        public boolean isInner() { return other.isInner(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        public boolean hasOuterInstance() { return other.hasOuterInstance(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        public ClassSymbol enclClass() { return other.enclClass(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        public ClassSymbol outermostClass() { return other.outermostClass(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        public PackageSymbol packge() { return other.packge(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
        public boolean isSubClass(Symbol base, Types types) { return other.isSubClass(base, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        public boolean isMemberOf(TypeSymbol clazz, Types types) { return other.isMemberOf(clazz, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        public boolean isEnclosedBy(ClassSymbol clazz) { return other.isEnclosedBy(clazz); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        public boolean isInheritedIn(Symbol clazz, Types types) { return other.isInheritedIn(clazz, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        public Symbol asMemberOf(Type site, Types types) { return other.asMemberOf(site, types); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
        public void complete() throws CompletionFailure { other.complete(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
            return other.accept(v, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   498
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   499
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   500
            return v.visitSymbol(other, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   501
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
    /** A class for type symbols. Type variables are represented by instances
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
     *  of this class, classes and packages by instances of subclasses.
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
    public static class TypeSymbol
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
            extends Symbol implements TypeParameterElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
        // Implements TypeParameterElement because type parameters don't
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
        // have their own TypeSymbol subclass.
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
        // TODO: type parameters should have their own TypeSymbol subclass
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
        public TypeSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
            super(TYP, flags, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        /** form a fully qualified name from a name and an owner
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
        static public Name formFullName(Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
            if (owner == null) return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
            if (((owner.kind != ERR)) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
                ((owner.kind & (VAR | MTH)) != 0
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
                 || (owner.kind == TYP && owner.type.tag == TYPEVAR)
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
                 )) return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            Name prefix = owner.getQualifiedName();
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   526
            if (prefix == null || prefix == prefix.table.names.empty)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
                return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
            else return prefix.append('.', name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
        /** form a fully qualified name from a name and an owner, after
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
         *  converting to flat representation
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
        static public Name formFlatName(Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
            if (owner == null ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
                (owner.kind & (VAR | MTH)) != 0
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
                || (owner.kind == TYP && owner.type.tag == TYPEVAR)
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
                ) return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
            char sep = owner.kind == TYP ? '$' : '.';
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
            Name prefix = owner.flatName();
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   541
            if (prefix == null || prefix == prefix.table.names.empty)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
                return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
            else return prefix.append(sep, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
         * A total ordering between type symbols that refines the
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
         * class inheritance graph.
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
         * Typevariables always precede other kinds of symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
        public final boolean precedes(TypeSymbol that, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
            if (this == that)
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
            if (this.type.tag == that.type.tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
                if (this.type.tag == CLASS) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
                    return
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
                        types.rank(that.type) < types.rank(this.type) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
                        types.rank(that.type) == types.rank(this.type) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
                        that.getQualifiedName().compareTo(this.getQualifiedName()) < 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
                } else if (this.type.tag == TYPEVAR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
                    return types.isSubtype(this.type, that.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
            return this.type.tag == TYPEVAR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
        // For type params; overridden in subclasses.
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
            return ElementKind.TYPE_PARAMETER;
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 java.util.List<Symbol> getEnclosedElements() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
            List<Symbol> list = List.nil();
6584
c3d25d0ad536 6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents: 6148
diff changeset
   575
            if (kind == TYP && type.tag == TYPEVAR) {
c3d25d0ad536 6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents: 6148
diff changeset
   576
                return list;
c3d25d0ad536 6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
sundar
parents: 6148
diff changeset
   577
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
            for (Scope.Entry e = members().elems; e != null; e = e.sibling) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
                if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this)
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
                    list = list.prepend(e.sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
            return list;
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
        // For type params.
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        // Perhaps not needed if getEnclosingElement can be spec'ed
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        // to do the same thing.
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        // TODO: getGenericElement() might not be needed
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
        public Symbol getGenericElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
            return owner;
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
   594
            Assert.check(type.tag == TYPEVAR); // else override will be invoked
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
            return v.visitTypeParameter(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   598
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   599
            return v.visitTypeSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   600
        }
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   601
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
        public List<Type> getBounds() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
            TypeVar t = (TypeVar)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
            Type bound = t.getUpperBound();
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
            if (!bound.isCompound())
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
                return List.of(bound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
            ClassType ct = (ClassType)bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
            if (!ct.tsym.erasure_field.isInterface()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
                return ct.interfaces_field.prepend(ct.supertype_field);
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
                // No superclass was given in bounds.
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
                // In this case, supertype is Object, erasure is first interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
                return ct.interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
    /** A class for package symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
    public static class PackageSymbol extends TypeSymbol
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
        implements PackageElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        public Scope members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
        public Name fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
        public ClassSymbol package_info; // see bug 6443073
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
        public PackageSymbol(Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
            super(0, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
            this.kind = PCK;
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
            this.members_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
            this.fullname = formFullName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
        public PackageSymbol(Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
            this(name, null, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
            this.type = new PackageType(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
            return fullname.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
            return fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
        public boolean isUnnamed() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
            return name.isEmpty() && owner != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
        public Scope members() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
            return members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
        public long flags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
            return flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
        public List<Attribute.Compound> getAnnotationMirrors() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
            if (completer != null) complete();
4871
655bba719625 6499119: Created package-info class file modeled improperly
jjg
parents: 4077
diff changeset
   663
            if (package_info != null && package_info.completer != null) {
655bba719625 6499119: Created package-info class file modeled improperly
jjg
parents: 4077
diff changeset
   664
                package_info.complete();
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   665
                if (annotations.isEmpty()) {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   666
                    annotations.setAttributes(package_info.annotations);
4871
655bba719625 6499119: Created package-info class file modeled improperly
jjg
parents: 4077
diff changeset
   667
            }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   668
            }
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   669
            return Assert.checkNonNull(annotations.getAttributes());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
        /** A package "exists" if a type or package that exists has
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
         *  been seen within it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
        public boolean exists() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
            return (flags_field & EXISTS) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
            return ElementKind.PACKAGE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
        public Symbol getEnclosingElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
            return v.visitPackage(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   690
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   691
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   692
            return v.visitPackageSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   693
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
    /** A class for class symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
    public static class ClassSymbol extends TypeSymbol implements TypeElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
        /** a scope for all class members; variables, methods and inner classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
         *  type parameters are not part of this scope
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
        public Scope members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
        /** the fully qualified name of the class, i.e. pck.outer.inner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
         *  null for anonymous classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
        public Name fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
        /** the fully qualified name of the class after converting to flat
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
         *  representation, i.e. pck.outer$inner,
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
         *  set externally for local and anonymous classes
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
        public Name flatname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
        /** the sourcefile where the class came from
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
        public JavaFileObject sourcefile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
        /** the classfile from where to load this class
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
         *  this will have extension .class or .java
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
        public JavaFileObject classfile;
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
10627
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
   725
        /** the list of translated local classes (used for generating
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
   726
         * InnerClasses attribute)
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
   727
         */
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
   728
        public List<ClassSymbol> trans_local;
d8e900b62e02 7003595: IncompatibleClassChangeError with unreferenced local class with subclass
mcimadamore
parents: 10626
diff changeset
   729
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
        /** the constant pool of the class
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
        public Pool pool;
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
        public ClassSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
            super(flags, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
            this.members_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
            this.fullname = formFullName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
            this.flatname = formFlatName(name, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
            this.sourcefile = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
            this.classfile = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
            this.pool = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
        public ClassSymbol(long flags, Name name, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
            this(
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
                flags,
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
                name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
                new ClassType(Type.noType, null, null),
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
                owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
            this.type.tsym = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
        /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
            return className();
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
        public long flags() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
            return flags_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
        public Scope members() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
            if (completer != null) complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
            return members_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
        public List<Attribute.Compound> getAnnotationMirrors() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
            if (completer != null) complete();
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   771
            return Assert.checkNonNull(annotations.getAttributes());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
        public Type erasure(Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   775
            if (erasure_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
                erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
                                              List.<Type>nil(), this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
            return erasure_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
        public String className() {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   782
            if (name.isEmpty())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
                return
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
                    Log.getLocalizedString("anonymous.class", flatname);
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
                return fullname.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
        public Name getQualifiedName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
            return fullname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
        public Name flatName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
            return flatname;
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
        public boolean isSubClass(Symbol base, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
            if (this == base) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
            } else if ((base.flags() & INTERFACE) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
                for (Type t = type; t.tag == CLASS; t = types.supertype(t))
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
                    for (List<Type> is = types.interfaces(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
                         is.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
                         is = is.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
                        if (is.head.tsym.isSubClass(base, types)) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
                for (Type t = type; t.tag == CLASS; t = types.supertype(t))
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
                    if (t.tsym == base) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
            return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
        /** Complete the elaboration of this symbol's definition.
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
        public void complete() throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
            try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
                super.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
            } catch (CompletionFailure ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
                // quiet error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
                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
   821
                this.type = new ErrorType(this, Type.noType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
                throw ex;
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
        public List<Type> getInterfaces() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
            complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
            if (type instanceof ClassType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
                ClassType t = (ClassType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
                if (t.interfaces_field == null) // FIXME: shouldn't be null
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
                    t.interfaces_field = List.nil();
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8427
diff changeset
   832
                if (t.all_interfaces_field != null)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8427
diff changeset
   833
                    return Type.getModelTypes(t.all_interfaces_field);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   834
                return t.interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   835
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   836
                return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   837
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   838
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   839
06bc494ca11e Initial load
duke
parents:
diff changeset
   840
        public Type getSuperclass() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   841
            complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   842
            if (type instanceof ClassType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
                ClassType t = (ClassType)type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
                if (t.supertype_field == null) // FIXME: shouldn't be null
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
                    t.supertype_field = Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
                // An interface has no superclass; its supertype is Object.
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
                return t.isInterface()
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
                    ? Type.noType
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8427
diff changeset
   849
                    : t.supertype_field.getModelType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
                return Type.noType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
            long flags = flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
            if ((flags & ANNOTATION) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
                return ElementKind.ANNOTATION_TYPE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
            else if ((flags & INTERFACE) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
                return ElementKind.INTERFACE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
            else if ((flags & ENUM) != 0)
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
                return ElementKind.ENUM;
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
                return ElementKind.CLASS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
        public NestingKind getNestingKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
            complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
            if (owner.kind == PCK)
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
                return NestingKind.TOP_LEVEL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
            else if (name.isEmpty())
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
                return NestingKind.ANONYMOUS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
            else if (owner.kind == MTH)
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
                return NestingKind.LOCAL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
                return NestingKind.MEMBER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
         * @deprecated this method should never be used by javac internally.
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
        @Override @Deprecated
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
        public <A extends java.lang.annotation.Annotation> A getAnnotation(Class<A> annoType) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
            return JavacElements.getAnnotation(this, annoType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
06bc494ca11e Initial load
duke
parents:
diff changeset
   887
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
            return v.visitType(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   890
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   891
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   892
            return v.visitClassSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
   893
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
    /** A class for variable symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
    public static class VarSymbol extends Symbol implements VariableElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
        /** The variable's declaration position.
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
        public int pos = Position.NOPOS;
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
        /** The variable's address. Used for different purposes during
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
         *  flow analysis, translation and code generation.
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
         *  Flow analysis:
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
         *    If this is a blank final or local variable, its sequence number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
         *  Translation:
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
         *    If this is a private field, its access number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
         *  Code generation:
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
         *    If this is a local variable, its logical slot number.
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
        public int adr = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
        /** Construct a variable symbol, given its flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
        public VarSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
            super(VAR, flags, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
        /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
        public VarSymbol clone(Symbol newOwner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
            VarSymbol v = new VarSymbol(flags_field, name, type, newOwner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
            v.pos = pos;
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
            v.adr = adr;
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
            v.data = data;
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
//          System.out.println("clone " + v + " in " + newOwner);//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
            return v;
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
            return name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
        public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
            return new VarSymbol(flags_field, name, types.memberType(site, this), owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
        public ElementKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
            long flags = flags();
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
            if ((flags & PARAMETER) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
                if (isExceptionParameter())
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
                    return ElementKind.EXCEPTION_PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
                else
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
                    return ElementKind.PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
            } else if ((flags & ENUM) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
                return ElementKind.ENUM_CONSTANT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
            } else if (owner.kind == TYP || owner.kind == ERR) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
                return ElementKind.FIELD;
6718
56ed1962d369 6967842: Element not returned from tree API for ARM resource variables.
sundar
parents: 6592
diff changeset
   952
            } else if (isResourceVariable()) {
56ed1962d369 6967842: Element not returned from tree API for ARM resource variables.
sundar
parents: 6592
diff changeset
   953
                return ElementKind.RESOURCE_VARIABLE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
                return ElementKind.LOCAL_VARIABLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
            return v.visitVariable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
        public Object getConstantValue() { // Mirror API
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
            return Constants.decode(getConstValue(), type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
        public void setLazyConstValue(final Env<AttrContext> env,
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
                                      final Attr attr,
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
                                      final JCTree.JCExpression initializer)
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
        {
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
            setData(new Callable<Object>() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
                public Object call() {
8225
e9e5670e6a71 6554097: "final" confuses @SuppressWarnings
jjg
parents: 8032
diff changeset
   973
                    return attr.attribLazyConstantValue(env, initializer, type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
            });
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
         * The variable's constant value, if this is a constant.
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
         * Before the constant value is evaluated, it points to an
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
         * initalizer environment.  If this is not a constant, it can
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
         * be used for other stuff.
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
        private Object data;
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
        public boolean isExceptionParameter() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
            return data == ElementKind.EXCEPTION_PARAMETER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   990
        public boolean isResourceVariable() {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   991
            return data == ElementKind.RESOURCE_VARIABLE;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   992
        }
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   993
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
        public Object getConstValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
            // TODO: Consider if getConstValue and getConstantValue can be collapsed
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   996
            if (data == ElementKind.EXCEPTION_PARAMETER ||
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
   997
                data == ElementKind.RESOURCE_VARIABLE) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
            } else if (data instanceof Callable<?>) {
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5847
diff changeset
  1000
                // In this case, this is a final variable, with an as
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
                // yet unevaluated initializer.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
                Callable<?> eval = (Callable<?>)data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
                data = null; // to make sure we don't evaluate this twice.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
                    data = eval.call();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
                } catch (Exception ex) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
                    throw new AssertionError(ex);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
            return data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
        public void setData(Object data) {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1014
            Assert.check(!(data instanceof Env<?>), this);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
            this.data = data;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1017
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1018
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1019
            return v.visitVarSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1020
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
    /** A class for method symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
    public static class MethodSymbol extends Symbol implements ExecutableElement {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
        /** The code of the method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
        public Code code = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
        /** The parameters of the method. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
        public List<VarSymbol> params = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
        /** The names of the parameters */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
        public List<Name> savedParameterNames;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
        /** For an attribute field accessor, its default value if any.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
         *  The value is null if none appeared in the method
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
         *  declaration.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
        public Attribute defaultValue = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
        /** Construct a method symbol, given its flags, name, type and owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
        public MethodSymbol(long flags, Name name, Type type, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
            super(MTH, flags, name, type, owner);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 8031
diff changeset
  1046
            if (owner.type.tag == TYPEVAR) Assert.error(owner + "." + name);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
        /** Clone this symbol with new owner.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
        public MethodSymbol clone(Symbol newOwner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
            MethodSymbol m = new MethodSymbol(flags_field, name, type, newOwner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
            m.code = code;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
            return m;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
        /** The Java source which this symbol represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
            if ((flags() & BLOCK) != 0) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
                return owner.name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
            } else {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1063
                String s = (name == name.table.names.init)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
                    ? owner.name.toString()
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
                    : name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
                if (type != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
                    if (type.tag == FORALL)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
                        s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
                    s += "(" + type.argtypes((flags() & VARARGS) != 0) + ")";
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
                return s;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1075
        public boolean isDynamic() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1076
            return false;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1077
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1078
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
        /** find a symbol that this (proxy method) symbol implements.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
         *  @param    c       The class whose members are searched for
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
         *                    implementations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
        public Symbol implemented(TypeSymbol c, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
            Symbol impl = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
            for (List<Type> is = types.interfaces(c.type);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
                 impl == null && is.nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
                 is = is.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
                TypeSymbol i = is.head.tsym;
7628
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1089
                impl = implementedIn(i, types);
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1090
                if (impl == null)
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1091
                    impl = implemented(i, types);
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1092
            }
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1093
            return impl;
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1094
        }
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1095
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1096
        public Symbol implementedIn(TypeSymbol c, Types types) {
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1097
            Symbol impl = null;
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1098
            for (Scope.Entry e = c.members().lookup(name);
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1099
                 impl == null && e.scope != null;
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1100
                 e = e.next()) {
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1101
                if (this.overrides(e.sym, (TypeSymbol)owner, types, true) &&
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1102
                    // FIXME: I suspect the following requires a
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1103
                    // subst() for a parametric return type.
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1104
                    types.isSameType(type.getReturnType(),
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1105
                                     types.memberType(owner.type, e.sym).getReturnType())) {
e7baeb97d164 6476118: compiler bug causes runtime ClassCastException for generics overloading
mcimadamore
parents: 6718
diff changeset
  1106
                    impl = e.sym;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
            return impl;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
        /** Will the erasure of this method be considered by the VM to
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
         *  override the erasure of the other when seen from class `origin'?
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
        public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
            if (isConstructor() || _other.kind != MTH) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
            if (this == _other) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
            MethodSymbol other = (MethodSymbol)_other;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1120
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
            // check for a direct implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
            if (other.isOverridableIn((TypeSymbol)owner) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
                types.asSuper(owner.type, other.owner) != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
                types.isSameType(erasure(types), other.erasure(types)))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
            // check for an inherited implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
                (flags() & ABSTRACT) == 0 &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
                other.isOverridableIn(origin) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
                this.isMemberOf(origin, types) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
                types.isSameType(erasure(types), other.erasure(types));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
        /** The implementation of this (abstract) symbol in class origin,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
         *  from the VM's point of view, null if method does not have an
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
         *  implementation in class.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
         *  @param origin   The class of which the implementation is a member.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
        public MethodSymbol binaryImplementation(ClassSymbol origin, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
            for (TypeSymbol c = origin; c != null; c = types.supertype(c.type).tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
                for (Scope.Entry e = c.members().lookup(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
                     e.scope != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
                     e = e.next()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
                    if (e.sym.kind == MTH &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
                        ((MethodSymbol)e.sym).binaryOverrides(this, origin, types))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
                        return (MethodSymbol)e.sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
        /** Does this symbol override `other' symbol, when both are seen as
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
         *  members of class `origin'?  It is assumed that _other is a member
06bc494ca11e Initial load
duke
parents:
diff changeset
  1155
         *  of origin.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
         *  It is assumed that both symbols have the same name.  The static
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
         *  modifier is ignored for this test.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
         *  See JLS 8.4.6.1 (without transitivity) and 8.4.6.4
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
        public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
            if (isConstructor() || _other.kind != MTH) return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
06bc494ca11e Initial load
duke
parents:
diff changeset
  1165
            if (this == _other) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
            MethodSymbol other = (MethodSymbol)_other;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
            // check for a direct implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
            if (other.isOverridableIn((TypeSymbol)owner) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
                types.asSuper(owner.type, other.owner) != null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
                Type mt = types.memberType(owner.type, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
                Type ot = types.memberType(owner.type, other);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
                if (types.isSubSignature(mt, ot)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
                    if (!checkResult)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
                        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
                    if (types.returnTypeSubstitutable(mt, ot))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
                        return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1179
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
            // check for an inherited implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
            if ((flags() & ABSTRACT) != 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
                (other.flags() & ABSTRACT) == 0 ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
                !other.isOverridableIn(origin) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
                !this.isMemberOf(origin, types))
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1187
06bc494ca11e Initial load
duke
parents:
diff changeset
  1188
            // assert types.asSuper(origin.type, other.owner) != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1189
            Type mt = types.memberType(origin.type, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1190
            Type ot = types.memberType(origin.type, other);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
                types.isSubSignature(mt, ot) &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1193
                (!checkResult || types.resultSubtype(mt, ot, Warner.noWarnings));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
        private boolean isOverridableIn(TypeSymbol origin) {
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8625
diff changeset
  1197
            // JLS 8.4.6.1
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
            switch ((int)(flags_field & Flags.AccessFlags)) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
            case Flags.PRIVATE:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1201
            case Flags.PUBLIC:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
            case Flags.PROTECTED:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
                return (origin.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
            case 0:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
                // for package private: can only override in the same
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
                // package
06bc494ca11e Initial load
duke
parents:
diff changeset
  1208
                return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1209
                    this.packge() == origin.packge() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1210
                    (origin.flags() & INTERFACE) == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1211
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
        /** The implementation of this (abstract) symbol in class origin;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
         *  null if none exists. Synthetic methods are not considered
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
         *  as possible implementations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
        public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult) {
6591
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1221
            return implementation(origin, types, checkResult, implementation_filter);
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1222
        }
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1223
        // where
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1224
            private static final Filter<Symbol> implementation_filter = new Filter<Symbol>() {
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1225
                public boolean accepts(Symbol s) {
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1226
                    return s.kind == Kinds.MTH &&
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1227
                            (s.flags() & SYNTHETIC) == 0;
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1228
                }
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1229
            };
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1230
a953c8c6b85e 6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents: 6584
diff changeset
  1231
        public MethodSymbol implementation(TypeSymbol origin, Types types, boolean checkResult, Filter<Symbol> implFilter) {
8242
3873b4aaf4a8 7007615: java_util/generics/phase2/NameClashTest02 fails since jdk7/pit/b123.
mcimadamore
parents: 8225
diff changeset
  1232
            MethodSymbol res = types.implementation(this, origin, checkResult, implFilter);
3539
3c265cb6f4e0 6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents: 3149
diff changeset
  1233
            if (res != null)
3c265cb6f4e0 6827648: Extremely slow compilation time for visitor pattern code + generics
mcimadamore
parents: 3149
diff changeset
  1234
                return res;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
            // if origin is derived from a raw type, we might have missed
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
            // an implementation because we do not know enough about instantiations.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
            // in this case continue with the supertype as origin.
12083
c9d98f7e59e8 7148556: Implementing a generic interface causes a public clone() to become inaccessible
mcimadamore
parents: 10627
diff changeset
  1238
            if (types.isDerivedRaw(origin.type) && !origin.isInterface())
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
                return implementation(types.supertype(origin.type).tsym, types, checkResult);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
        public List<VarSymbol> params() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
            owner.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
            if (params == null) {
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1247
                // If ClassReader.saveParameterNames has been set true, then
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1248
                // savedParameterNames will be set to a list of names that
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1249
                // matches the types in type.getParameterTypes().  If any names
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1250
                // were not found in the class file, those names in the list will
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1251
                // be set to the empty name.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1252
                // If ClassReader.saveParameterNames has been set false, then
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1253
                // savedParameterNames will be null.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1254
                List<Name> paramNames = savedParameterNames;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
                savedParameterNames = null;
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1256
                // discard the provided names if the list of names is the wrong size.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1257
                if (paramNames == null || paramNames.size() != type.getParameterTypes().size())
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1258
                    paramNames = List.nil();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1259
                ListBuffer<VarSymbol> buf = new ListBuffer<VarSymbol>();
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1260
                List<Name> remaining = paramNames;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1261
                // assert: remaining and paramNames are both empty or both
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1262
                // have same cardinality as type.getParameterTypes()
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1263
                int i = 0;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
                for (Type t : type.getParameterTypes()) {
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1265
                    Name paramName;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1266
                    if (remaining.isEmpty()) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1267
                        // no names for any parameters available
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1268
                        paramName = createArgName(i, paramNames);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1269
                    } else {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1270
                        paramName = remaining.head;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1271
                        remaining = remaining.tail;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1272
                        if (paramName.isEmpty()) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1273
                            // no name for this specific parameter
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1274
                            paramName = createArgName(i, paramNames);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1275
                        }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1276
                    }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1277
                    buf.append(new VarSymbol(PARAMETER, paramName, t, this));
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1278
                    i++;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1279
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1280
                params = buf.toList();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
            return params;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
4077
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1285
        // Create a name for the argument at position 'index' that is not in
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1286
        // the exclude list. In normal use, either no names will have been
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1287
        // provided, in which case the exclude list is empty, or all the names
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1288
        // will have been provided, in which case this method will not be called.
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1289
        private Name createArgName(int index, List<Name> exclude) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1290
            String prefix = "arg";
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1291
            while (true) {
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1292
                Name argName = name.table.fromString(prefix + index);
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1293
                if (!exclude.contains(argName))
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1294
                    return argName;
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1295
                prefix += "$";
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1296
            }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1297
        }
0096541a388e 6889255: javac MethodSymbol throws NPE if ClassReader does not read parameter names correctly
jjg
parents: 3539
diff changeset
  1298
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
        public Symbol asMemberOf(Type site, Types types) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
            return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1301
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
        public ElementKind getKind() {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1304
            if (name == name.table.names.init)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
                return ElementKind.CONSTRUCTOR;
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1306
            else if (name == name.table.names.clinit)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1307
                return ElementKind.STATIC_INIT;
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1308
            else if ((flags() & BLOCK) != 0)
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1309
                return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1310
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
                return ElementKind.METHOD;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
10626
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1314
        public boolean isStaticOrInstanceInit() {
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1315
            return getKind() == ElementKind.STATIC_INIT ||
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1316
                    getKind() == ElementKind.INSTANCE_INIT;
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1317
        }
83f0c2860f5b 7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents: 9812
diff changeset
  1318
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1319
        /**
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1320
         * A polymorphic signature method (JLS SE 7, 8.4.1) is a method that
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1321
         * (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1322
         * a single variable arity parameter (iii) whose declared type is Object[],
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1323
         * (iv) has a return type of Object and (v) is native.
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1324
         */
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1325
        public boolean isSignaturePolymorphic(Types types) {
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1326
            List<Type> argtypes = type.getParameterTypes();
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1327
            Type firstElemType = argtypes.nonEmpty() ?
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1328
                    types.elemtype(argtypes.head) :
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1329
                    null;
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1330
            return owner == types.syms.methodHandleType.tsym &&
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1331
                    argtypes.length() == 1 &&
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1332
                    firstElemType != null &&
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1333
                    types.isSameType(firstElemType, types.syms.objectType) &&
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1334
                    types.isSameType(type.getReturnType(), types.syms.objectType) &&
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1335
                    (flags() & NATIVE) != 0;
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1336
        }
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12083
diff changeset
  1337
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1338
        public Attribute getDefaultValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
            return defaultValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1340
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1341
06bc494ca11e Initial load
duke
parents:
diff changeset
  1342
        public List<VarSymbol> getParameters() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1343
            return params();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1344
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1345
06bc494ca11e Initial load
duke
parents:
diff changeset
  1346
        public boolean isVarArgs() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1347
            return (flags() & VARARGS) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1348
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1349
06bc494ca11e Initial load
duke
parents:
diff changeset
  1350
        public <R, P> R accept(ElementVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1351
            return v.visitExecutable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1352
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1353
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1354
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1355
            return v.visitMethodSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1356
        }
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1357
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
        public Type getReturnType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
            return asType().getReturnType();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
        public List<Type> getThrownTypes() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1363
            return asType().getThrownTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1364
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1367
    /** A class for invokedynamic method calls.
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1368
     */
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1369
    public static class DynamicMethodSymbol extends MethodSymbol {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1370
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1371
        public Object[] staticArgs;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1372
        public Symbol bsm;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1373
        public int bsmKind;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1374
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1375
        public DynamicMethodSymbol(Name name, Symbol owner, int bsmKind, MethodSymbol bsm, Type type, Object[] staticArgs) {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1376
            super(0, name, type, owner);
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1377
            this.bsm = bsm;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1378
            this.bsmKind = bsmKind;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1379
            this.staticArgs = staticArgs;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1380
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1381
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1382
        @Override
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1383
        public boolean isDynamic() {
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1384
            return true;
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1385
        }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1386
    }
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13689
diff changeset
  1387
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
    /** A class for predefined operators.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1390
    public static class OperatorSymbol extends MethodSymbol {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1391
06bc494ca11e Initial load
duke
parents:
diff changeset
  1392
        public int opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1393
06bc494ca11e Initial load
duke
parents:
diff changeset
  1394
        public OperatorSymbol(Name name, Type type, int opcode, Symbol owner) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1395
            super(PUBLIC | STATIC, name, type, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1396
            this.opcode = opcode;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1397
        }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1398
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1399
        public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1400
            return v.visitOperatorSymbol(this, p);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1401
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1402
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1403
06bc494ca11e Initial load
duke
parents:
diff changeset
  1404
    /** Symbol completer interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1405
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1406
    public static interface Completer {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1407
        void complete(Symbol sym) throws CompletionFailure;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1408
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1409
06bc494ca11e Initial load
duke
parents:
diff changeset
  1410
    public static class CompletionFailure extends RuntimeException {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1411
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
        public Symbol sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1413
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1414
        /** A diagnostic object describing the failure
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1415
         */
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1416
        public JCDiagnostic diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1417
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1418
        /** A localized string describing the failure.
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1419
         * @deprecated Use {@code getDetail()} or {@code getMessage()}
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1420
         */
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1421
        @Deprecated
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
        public String errmsg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1423
06bc494ca11e Initial load
duke
parents:
diff changeset
  1424
        public CompletionFailure(Symbol sym, String errmsg) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1425
            this.sym = sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1426
            this.errmsg = errmsg;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1427
//          this.printStackTrace();//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
  1428
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1429
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1430
        public CompletionFailure(Symbol sym, JCDiagnostic diag) {
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1431
            this.sym = sym;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1432
            this.diag = diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1433
//          this.printStackTrace();//DEBUG
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1434
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1435
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1436
        public JCDiagnostic getDiagnostic() {
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1437
            return diag;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1438
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1439
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1440
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1441
        public String getMessage() {
169
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1442
            if (diag != null)
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1443
                return diag.getMessage(null);
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1444
            else
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1445
                return errmsg;
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1446
        }
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1447
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1448
        public Object getDetailValue() {
ff76730e430e 6668794: javac puts localized text in raw diagnostics
jjg
parents: 10
diff changeset
  1449
            return (diag != null ? diag : errmsg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1451
06bc494ca11e Initial load
duke
parents:
diff changeset
  1452
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1453
        public CompletionFailure initCause(Throwable cause) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1454
            super.initCause(cause);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1455
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1456
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1457
06bc494ca11e Initial load
duke
parents:
diff changeset
  1458
    }
1357
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1459
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1460
    /**
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1461
     * A visitor for symbols.  A visitor is used to implement operations
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1462
     * (or relations) on symbols.  Most common operations on types are
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1463
     * binary relations and this interface is designed for binary
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1464
     * relations, that is, operations on the form
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1465
     * Symbol&nbsp;&times;&nbsp;P&nbsp;&rarr;&nbsp;R.
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1466
     * <!-- In plain text: Type x P -> R -->
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1467
     *
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1468
     * @param <R> the return type of the operation implemented by this
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1469
     * visitor; use Void if no return type is needed.
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1470
     * @param <P> the type of the second argument (the first being the
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1471
     * symbol itself) of the operation implemented by this visitor; use
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1472
     * Void if a second argument is not needed.
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1473
     */
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1474
    public interface Visitor<R,P> {
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1475
        R visitClassSymbol(ClassSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1476
        R visitMethodSymbol(MethodSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1477
        R visitPackageSymbol(PackageSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1478
        R visitOperatorSymbol(OperatorSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1479
        R visitVarSymbol(VarSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1480
        R visitTypeSymbol(TypeSymbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1481
        R visitSymbol(Symbol s, P arg);
e2d4f3e1f805 6735840: Need a type/symbol visitor printer
mcimadamore
parents: 1260
diff changeset
  1482
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1483
}