langtools/src/share/classes/com/sun/tools/javac/code/Type.java
author mcimadamore
Thu, 04 Oct 2012 13:04:53 +0100
changeset 14057 b4b0377b8dba
parent 14052 8b839ae9074b
child 14058 c7ec7facdd20
permissions -rw-r--r--
7177387: Add target-typing support in method context Summary: Add support for deferred types and speculative attribution Reviewed-by: jjg, dlsmith
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
13631
dc1212c348f9 7191449: update copyright year to match last edit in jdk8 langtools repository
jjh
parents: 12915
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: 3890
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: 3890
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: 3890
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3890
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3890
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
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
    28
import java.util.Collections;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
    29
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14048
diff changeset
    30
import com.sun.tools.javac.code.Symbol.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
    33
import java.util.EnumMap;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
    34
import java.util.EnumSet;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
    35
import java.util.Map;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
    36
import java.util.Set;
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14048
diff changeset
    37
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
import javax.lang.model.type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14048
diff changeset
    40
import static com.sun.tools.javac.code.BoundKind.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
import static com.sun.tools.javac.code.Kinds.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
import static com.sun.tools.javac.code.TypeTags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
/** This class represents Java types. The class itself defines the behavior of
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *  the following types:
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *  base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN),
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  type `void' (tag: VOID),
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *  the bottom type (tag: BOT),
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *  the missing type (tag: NONE).
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *  <p>The behavior of the following types is defined in subclasses, which are
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *  all static inner classes of this class:
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *  class types (tag: CLASS, class: ClassType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *  array types (tag: ARRAY, class: ArrayType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *  method types (tag: METHOD, class: MethodType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *  package types (tag: PACKAGE, class: PackageType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 *  type variables (tag: TYPEVAR, class: TypeVar),
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *  type arguments (tag: WILDCARD, class: WildcardType),
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
    62
 *  generic method types (tag: FORALL, class: ForAll),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *  the error type (tag: ERROR, class: ErrorType).
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    66
 *  <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
    67
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *  @see TypeTags
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
public class Type implements PrimitiveType {
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    /** Constant type: no type at all. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    public static final JCNoType noType = new JCNoType(NONE);
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14052
diff changeset
    78
    /** Constant type: special type to be used during recovery of deferred expressions. */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14052
diff changeset
    79
    public static final JCNoType recoveryType = new JCNoType(NONE);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14052
diff changeset
    80
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    /** If this switch is turned on, the names of type variables
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     *  and anonymous classes are printed with hashcodes appended.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    public static boolean moreInfo = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    /** The tag of this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     *  @see TypeTags
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    public int tag;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /** The defining class / interface / package / type variable
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    public TypeSymbol tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * The constant value of this type, null if this type does not
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * have a constant value attribute. Only primitive types and
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     * strings (ClassType) can have a constant value attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     * @return the constant value attribute of this type
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    public Object constValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   106
    /**
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   107
     * Get the representation of this type used for modelling purposes.
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   108
     * By default, this is itself. For ErrorType, a different value
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   109
     * may be provided,
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   110
     */
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   111
    public Type getModelType() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   112
        return this;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   113
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   114
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   115
    public static List<Type> getModelTypes(List<Type> ts) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   116
        ListBuffer<Type> lb = new ListBuffer<Type>();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   117
        for (Type t: ts)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   118
            lb.append(t.getModelType());
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   119
        return lb.toList();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   120
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   121
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    /** Define a type given its tag and type symbol
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    public Type(int tag, TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        this.tag = tag;
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
        this.tsym = tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    /** An abstract class for mappings from types to types
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    public static abstract class Mapping {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        private String name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        public Mapping(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
            this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        public abstract Type apply(Type t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
            return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /** map a type function over all immediate descendants of this type
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    /** map a type function over a list of types
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    public static List<Type> map(List<Type> ts, Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
        if (ts.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
            List<Type> tail1 = map(ts.tail, f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
            Type t = f.apply(ts.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
            if (tail1 != ts.tail || t != ts.head)
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
                return tail1.prepend(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
        return ts;
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    /** Define a constant type, of the same kind as this type
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     *  and with given constant value
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    public Type constType(Object constValue) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
        final Object value = constValue;
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   167
        Assert.check(tag <= BOOLEAN);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
        return new Type(tag, tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
                @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
                public Object constValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
                    return value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
                @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
                public Type baseType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
                    return tsym.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
            };
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * If this is a constant type, return its underlying type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * Otherwise, return the type itself.
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    public Type baseType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
    /** Return the base types of a list of types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    public static List<Type> baseTypes(List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        if (ts.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
            Type t = ts.head.baseType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
            List<Type> baseTypes = baseTypes(ts.tail);
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
            if (t != ts.head || baseTypes != ts.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
                return baseTypes.prepend(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
        return ts;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    /** The Java source which this type represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
        String s = (tsym == null || tsym.name == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
            ? "<none>"
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
            : tsym.name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
        if (moreInfo && tag == TYPEVAR) s = s + hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        return s;
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     * The Java source which this type list represents.  A List is
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     * represented as a comma-spearated listing of the elements in
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     * that list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    public static String toString(List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
        if (ts.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
            return "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
        } else {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   219
            StringBuilder buf = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
            buf.append(ts.head.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
            for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
                buf.append(",").append(l.head.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
            return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     * The constant value of this type, converted to String
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    public String stringValue() {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   231
        Object cv = Assert.checkNonNull(constValue());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        if (tag == BOOLEAN)
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   233
            return ((Integer) cv).intValue() == 0 ? "false" : "true";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        else if (tag == CHAR)
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   235
            return String.valueOf((char) ((Integer) cv).intValue());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        else
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   237
            return cv.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * This method is analogous to isSameType, but weaker, since we
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * never complete classes. Where isSameType would complete a
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     * class, equals assumes that the two types are different.
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    public boolean equals(Object t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        return super.equals(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    public int hashCode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        return super.hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    /** Is this a constant type whose value is false?
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    public boolean isFalse() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
            tag == BOOLEAN &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
            constValue() != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
            ((Integer)constValue()).intValue() == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
    /** Is this a constant type whose value is true?
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
    public boolean isTrue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
            tag == BOOLEAN &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
            constValue() != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
            ((Integer)constValue()).intValue() != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    public String argtypes(boolean varargs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        List<Type> args = getParameterTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
        if (!varargs) return args.toString();
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
   274
        StringBuilder buf = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        while (args.tail.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
            buf.append(args.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
            args = args.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
            buf.append(',');
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
        if (args.head.tag == ARRAY) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
            buf.append(((ArrayType)args.head).elemtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
            buf.append("...");
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
            buf.append(args.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    /** Access methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
    public List<Type>        getTypeArguments()  { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
    public Type              getEnclosingType() { return null; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
    public List<Type>        getParameterTypes() { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    public Type              getReturnType()     { return null; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    public List<Type>        getThrownTypes()    { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    public Type              getUpperBound()     { return null; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
    public Type              getLowerBound()     { return null; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    /** Navigation methods, these will work for classes, type variables,
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     *  foralls, but will return null for arrays and methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
   /** Return all parameters of this type and all its outer types in order
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
    *  outer (first) to inner (last).
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
    */
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
    public List<Type> allparams() { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
    /** Does this type contain "error" elements?
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
    public static boolean isErroneous(List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
        for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
            if (l.head.isErroneous()) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    /** Is this type parameterized?
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
     *  A class type is parameterized if it has some parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     *  An array type is parameterized if its element type is parameterized.
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
     *  All other types are not parameterized.
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
    public boolean isParameterized() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
    /** Is this type a raw type?
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
     *  A class type is a raw type if it misses some of its parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
     *  An array type is a raw type if its element type is raw.
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
     *  All other types are not raw.
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
     *  Type validation will ensure that the only raw types
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
     *  in a program are types that miss all their type variables.
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
    public boolean isRaw() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
    public boolean isCompound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        return tsym.completer == null
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
            // Compound types can't have a completer.  Calling
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
            // flags() will complete the symbol causing the
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
            // compiler to load classes unnecessarily.  This led
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
            // to regression 6180021.
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
            && (tsym.flags() & COMPOUND) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
    public boolean isInterface() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        return (tsym.flags() & INTERFACE) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
6353
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   353
    public boolean isFinal() {
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   354
        return (tsym.flags() & FINAL) != 0;
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   355
    }
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   356
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
    public boolean isPrimitive() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        return tag < VOID;
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
     * Does this type contain occurrences of type t?
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
    public boolean contains(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
        return t == this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
    public static boolean contains(List<Type> ts, Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
        for (List<Type> l = ts;
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
             l.tail != null /*inlined: l.nonEmpty()*/;
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
             l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
            if (l.head.contains(t)) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   376
    /** Does this type contain an occurrence of some type in 'ts'?
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
     */
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   378
    public boolean containsAny(List<Type> ts) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   379
        for (Type t : ts)
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   380
            if (this.contains(t)) return true;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   381
        return false;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   382
    }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   383
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   384
    public static boolean containsAny(List<Type> ts1, List<Type> ts2) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   385
        for (Type t : ts1)
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   386
            if (t.containsAny(ts2)) return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   390
    public static List<Type> filter(List<Type> ts, Filter<Type> tf) {
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   391
        ListBuffer<Type> buf = ListBuffer.lb();
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   392
        for (Type t : ts) {
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   393
            if (tf.accepts(t)) {
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   394
                buf.append(t);
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   395
            }
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   396
        }
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   397
        return buf.toList();
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   398
    }
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   399
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
    public boolean isSuperBound() { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    public boolean isExtendsBound() { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
    public boolean isUnbound() { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    public Type withTypeVar(Type t) { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
    /** The underlying method type of this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
    public MethodType asMethodType() { throw new AssertionError(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
    /** Complete loading all classes in this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
    public void complete() {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
    public TypeSymbol asElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        return tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
    public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
        switch (tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
        case BYTE:      return TypeKind.BYTE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
        case CHAR:      return TypeKind.CHAR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        case SHORT:     return TypeKind.SHORT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
        case INT:       return TypeKind.INT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
        case LONG:      return TypeKind.LONG;
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
        case FLOAT:     return TypeKind.FLOAT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
        case DOUBLE:    return TypeKind.DOUBLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        case BOOLEAN:   return TypeKind.BOOLEAN;
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        case VOID:      return TypeKind.VOID;
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        case BOT:       return TypeKind.NULL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
        case NONE:      return TypeKind.NONE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
        default:        return TypeKind.OTHER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
        }
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 <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
        if (isPrimitive())
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
            return v.visitPrimitive(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
    public static class WildcardType extends Type
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
            implements javax.lang.model.type.WildcardType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        public Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        public BoundKind kind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        public TypeVar bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
            return v.visitWildcardType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
        public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
            super(WILDCARD, tsym);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   455
            this.type = Assert.checkNonNull(type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
            this.kind = kind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
        public WildcardType(WildcardType t, TypeVar bound) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
            this(t.type, t.kind, t.tsym, bound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
        public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, TypeVar bound) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
            this(type, kind, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
            this.bound = bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   467
        public boolean contains(Type t) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   468
            return kind != UNBOUND && type.contains(t);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   469
        }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   470
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
        public boolean isSuperBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
            return kind == SUPER ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
                kind == UNBOUND;
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
        public boolean isExtendsBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
            return kind == EXTENDS ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
                kind == UNBOUND;
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        public boolean isUnbound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
            return kind == UNBOUND;
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
        public Type withTypeVar(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
            //-System.err.println(this+".withTypeVar("+t+");");//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
            if (bound == t)
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
                return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
            bound = (TypeVar)t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        boolean isPrintingBound = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        public String toString() {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   493
            StringBuilder s = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
            s.append(kind.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
            if (kind != UNBOUND)
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
                s.append(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
            if (moreInfo && bound != null && !isPrintingBound)
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
                    isPrintingBound = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
                    s.append("{:").append(bound.bound).append(":}");
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
                } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
                    isPrintingBound = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
            return s.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
            //- System.err.println("   (" + this + ").map(" + f + ")");//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
            Type t = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
            if (t != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
                t = f.apply(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
            if (t == type)
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
                return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
                return new WildcardType(t, kind, tsym, bound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        public Type getExtendsBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
            if (kind == EXTENDS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
                return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
        public Type getSuperBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
            if (kind == SUPER)
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
                return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
            return TypeKind.WILDCARD;
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
            return v.visitWildcard(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
    public static class ClassType extends Type implements DeclaredType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        /** The enclosing type of this type. If this is the type of an inner
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
         *  class, outer_field refers to the type of its enclosing
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
         *  instance class, in all other cases it referes to noType.
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        private Type outer_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
        /** The type parameters of this type (to be set once class is loaded).
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        public List<Type> typarams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        /** A cache variable for the type parameters of this type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
         *  appended to all parameters of its enclosing class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
         *  @see #allparams
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
        public List<Type> allparams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        /** The supertype of this class (to be set once class is loaded).
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        public Type supertype_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        /** The interfaces of this class (to be set once class is loaded).
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
        public List<Type> interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   567
        /** All the interfaces of this class, including missing ones.
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   568
         */
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   569
        public List<Type> all_interfaces_field;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   570
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
        public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
            super(CLASS, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
            this.outer_field = outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
            this.typarams_field = typarams;
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
            this.allparams_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
            this.supertype_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
            this.interfaces_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
            /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
            // this can happen during error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
            assert
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
                outer.isParameterized() ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
                typarams.length() == tsym.type.typarams().length() :
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
                outer.isRaw() ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
                typarams.length() == 0 :
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
                true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
            */
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
            return v.visitClassType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        public Type constType(Object constValue) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
            final Object value = constValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
            return new ClassType(getEnclosingType(), typarams_field, tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
                    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
                    public Object constValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
                        return value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
                    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
                    public Type baseType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
                        return tsym.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
                };
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
        /** The Java source which this type represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
        public String toString() {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   611
            StringBuilder buf = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
            if (getEnclosingType().tag == CLASS && tsym.owner.kind == TYP) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
                buf.append(getEnclosingType().toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
                buf.append(".");
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
                buf.append(className(tsym, false));
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
                buf.append(className(tsym, true));
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
            if (getTypeArguments().nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
                buf.append('<');
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
                buf.append(getTypeArguments().toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
                buf.append(">");
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
            return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
//where
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
            private String className(Symbol sym, boolean longform) {
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   628
                if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   629
                    StringBuilder s = new StringBuilder(supertype_field.toString());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
                    for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
                        s.append("&");
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
                        s.append(is.head.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
                    return s.toString();
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   635
                } else if (sym.name.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
                    String s;
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
                    ClassType norm = (ClassType) tsym.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
                    if (norm == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   639
                        s = Log.getLocalizedString("anonymous.class", (Object)null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   640
                    } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   641
                        s = Log.getLocalizedString("anonymous.class",
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
                                                   norm.interfaces_field.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
                        s = Log.getLocalizedString("anonymous.class",
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
                                                   norm.supertype_field);
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
                    if (moreInfo)
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
                        s += String.valueOf(sym.hashCode());
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
                    return s;
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
                } else if (longform) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
                    return sym.getQualifiedName().toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
                    return sym.name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
        public List<Type> getTypeArguments() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
            if (typarams_field == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
                complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
                if (typarams_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
                    typarams_field = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
            return typarams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
514
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   666
        public boolean hasErasedSupertypes() {
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   667
            return isRaw();
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   668
        }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   669
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
        public Type getEnclosingType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
            return outer_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
        public void setEnclosingType(Type outer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
            outer_field = outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
        public List<Type> allparams() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
            if (allparams_field == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
                allparams_field = getTypeArguments().prependList(getEnclosingType().allparams());
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
            return allparams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   683
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
        public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
                getEnclosingType().isErroneous() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
                isErroneous(getTypeArguments()) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
                this != tsym.type && tsym.type.isErroneous();
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
        public boolean isParameterized() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
            return allparams().tail != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
            // optimization, was: allparams().nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
        /** A cache for the rank. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
        int rank_field = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
06bc494ca11e Initial load
duke
parents:
diff changeset
   700
        /** A class type is raw if it misses some
06bc494ca11e Initial load
duke
parents:
diff changeset
   701
         *  of its type parameter sections.
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
         *  After validation, this is equivalent to:
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13631
diff changeset
   703
         *  {@code allparams.isEmpty() && tsym.type.allparams.nonEmpty(); }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
        public boolean isRaw() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   707
                this != tsym.type && // necessary, but not sufficient condition
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
                tsym.type.allparams().nonEmpty() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
                allparams().isEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
        public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
            Type outer = getEnclosingType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
            Type outer1 = f.apply(outer);
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
            List<Type> typarams = getTypeArguments();
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
            List<Type> typarams1 = map(typarams, f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
            if (outer1 == outer && typarams1 == typarams) return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
            else return new ClassType(outer1, typarams1, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
        public boolean contains(Type elem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
                elem == this
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
                || (isParameterized()
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   725
                    && (getEnclosingType().contains(elem) || contains(getTypeArguments(), elem)))
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   726
                || (isCompound()
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   727
                    && (supertype_field.contains(elem) || contains(interfaces_field, elem)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
            if (tsym.completer != null) tsym.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
            return TypeKind.DECLARED;
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
06bc494ca11e Initial load
duke
parents:
diff changeset
   738
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   739
            return v.visitDeclared(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   740
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   741
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
514
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   743
    public static class ErasedClassType extends ClassType {
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   744
        public ErasedClassType(Type outer, TypeSymbol tsym) {
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   745
            super(outer, List.<Type>nil(), tsym);
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   746
        }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   747
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   748
        @Override
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   749
        public boolean hasErasedSupertypes() {
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   750
            return true;
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   751
        }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   752
    }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   753
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   754
    // a clone of a ClassType that knows about the alternatives of a union type.
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   755
    public static class UnionClassType extends ClassType implements UnionType {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   756
        final List<? extends Type> alternatives_field;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   757
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   758
        public UnionClassType(ClassType ct, List<? extends Type> alternatives) {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   759
            super(ct.outer_field, ct.typarams_field, ct.tsym);
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   760
            allparams_field = ct.allparams_field;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   761
            supertype_field = ct.supertype_field;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   762
            interfaces_field = ct.interfaces_field;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   763
            all_interfaces_field = ct.interfaces_field;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   764
            alternatives_field = alternatives;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   765
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   766
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   767
        public Type getLub() {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   768
            return tsym.type;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   769
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   770
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   771
        public java.util.List<? extends TypeMirror> getAlternatives() {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   772
            return Collections.unmodifiableList(alternatives_field);
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   773
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   774
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   775
        @Override
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   776
        public TypeKind getKind() {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   777
            return TypeKind.UNION;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   778
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   779
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   780
        @Override
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   781
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   782
            return v.visitUnion(this, p);
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   783
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   784
    }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   785
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
    public static class ArrayType extends Type
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
            implements javax.lang.model.type.ArrayType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
        public Type elemtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
        public ArrayType(Type elemtype, TypeSymbol arrayClass) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
            super(ARRAY, arrayClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
            this.elemtype = elemtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   797
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   798
            return v.visitArrayType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   799
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
            return elemtype + "[]";
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
        public boolean equals(Object obj) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
                this == obj ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
                (obj instanceof ArrayType &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
                 this.elemtype.equals(((ArrayType)obj).elemtype));
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
        public int hashCode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
            return (ARRAY << 5) + elemtype.hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   816
        public boolean isVarargs() {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   817
            return false;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   818
        }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   819
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
        public List<Type> allparams() { return elemtype.allparams(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
        public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
            return elemtype.isErroneous();
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 boolean isParameterized() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
            return elemtype.isParameterized();
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   829
06bc494ca11e Initial load
duke
parents:
diff changeset
   830
        public boolean isRaw() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   831
            return elemtype.isRaw();
06bc494ca11e Initial load
duke
parents:
diff changeset
   832
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   833
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   834
        public ArrayType makeVarargs() {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   835
            return new ArrayType(elemtype, tsym) {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   836
                @Override
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   837
                public boolean isVarargs() {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   838
                    return true;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   839
                }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   840
            };
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   841
        }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   842
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   843
        public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   844
            Type elemtype1 = f.apply(elemtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   845
            if (elemtype1 == elemtype) return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
            else return new ArrayType(elemtype1, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   847
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
        public boolean contains(Type elem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   850
            return elem == this || elemtype.contains(elem);
06bc494ca11e Initial load
duke
parents:
diff changeset
   851
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   852
06bc494ca11e Initial load
duke
parents:
diff changeset
   853
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   854
            elemtype.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   855
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
        public Type getComponentType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   858
            return elemtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   859
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   860
06bc494ca11e Initial load
duke
parents:
diff changeset
   861
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   862
            return TypeKind.ARRAY;
06bc494ca11e Initial load
duke
parents:
diff changeset
   863
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   864
06bc494ca11e Initial load
duke
parents:
diff changeset
   865
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   866
            return v.visitArray(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   867
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8044
diff changeset
   870
    public static class MethodType extends Type implements ExecutableType {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
        public List<Type> argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
        public Type restype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
        public List<Type> thrown;
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
        public MethodType(List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
                          Type restype,
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
                          List<Type> thrown,
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
                          TypeSymbol methodClass) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   880
            super(METHOD, methodClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   881
            this.argtypes = argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   882
            this.restype = restype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   883
            this.thrown = thrown;
06bc494ca11e Initial load
duke
parents:
diff changeset
   884
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   885
06bc494ca11e Initial load
duke
parents:
diff changeset
   886
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   887
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   888
            return v.visitMethodType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   889
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   890
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
        /** The Java source which this type represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
         *  XXX 06/09/99 iris This isn't correct Java syntax, but it probably
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
         *  should be.
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
            return "(" + argtypes + ")" + restype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
06bc494ca11e Initial load
duke
parents:
diff changeset
   900
        public boolean equals(Object obj) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
            if (this == obj)
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
                return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
            if (!(obj instanceof MethodType))
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
            MethodType m = (MethodType)obj;
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
            List<Type> args1 = argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
            List<Type> args2 = m.argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
            while (!args1.isEmpty() && !args2.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
                if (!args1.head.equals(args2.head))
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
                    return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
                args1 = args1.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
                args2 = args2.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
            if (!args1.isEmpty() || !args2.isEmpty())
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
                return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
            return restype.equals(m.restype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
        public int hashCode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
            int h = METHOD;
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
            for (List<Type> thisargs = this.argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
                 thisargs.tail != null; /*inlined: thisargs.nonEmpty()*/
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
                 thisargs = thisargs.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
                h = (h << 5) + thisargs.head.hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
            return (h << 5) + this.restype.hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
        public List<Type>        getParameterTypes() { return argtypes; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
        public Type              getReturnType()     { return restype; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
        public List<Type>        getThrownTypes()    { return thrown; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
        public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   933
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
                isErroneous(argtypes) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
                restype != null && restype.isErroneous();
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
        public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
            List<Type> argtypes1 = map(argtypes, f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
            Type restype1 = f.apply(restype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
            List<Type> thrown1 = map(thrown, f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
            if (argtypes1 == argtypes &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
                restype1 == restype &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
                thrown1 == thrown) return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
            else return new MethodType(argtypes1, restype1, thrown1, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
        public boolean contains(Type elem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
            return elem == this || contains(argtypes, elem) || restype.contains(elem);
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
        public MethodType asMethodType() { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
            for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
                l.head.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
            restype.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
            for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
                l.head.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
        public List<TypeVar> getTypeVariables() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
            return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
        public TypeSymbol asElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
            return TypeKind.EXECUTABLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
            return v.visitExecutable(this, p);
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
    public static class PackageType extends Type implements NoType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
        PackageType(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
            super(PACKAGE, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
            return v.visitPackageType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   991
            return tsym.getQualifiedName().toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   992
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   993
06bc494ca11e Initial load
duke
parents:
diff changeset
   994
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
            return TypeKind.PACKAGE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   997
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
            return v.visitNoType(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
    public static class TypeVar extends Type implements TypeVariable {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1005
        /** The upper bound of this type variable; set from outside.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
         *  Must be nonempty once it is set.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
         *  For a bound, `bound' is the bound type itself.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
         *  Multiple bounds are expressed as a single class type which has the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
         *  individual bounds as superclass, respectively interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
         *  The class type then has as `tsym' a compiler generated class `c',
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
         *  which has a flag COMPOUND and whose owner is the type variable
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
         *  itself. Furthermore, the erasure_field of the class
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
         *  points to the first class or interface bound.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
        public Type bound = null;
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1016
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1017
        /** The lower bound of this type variable.
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1018
         *  TypeVars don't normally have a lower bound, so it is normally set
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1019
         *  to syms.botType.
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1020
         *  Subtypes, such as CapturedType, may provide a different value.
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1021
         */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
        public Type lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
        public TypeVar(Name name, Symbol owner, Type lower) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
            super(TYPEVAR, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
            tsym = new TypeSymbol(0, name, this, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
            this.lower = lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1028
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
        public TypeVar(TypeSymbol tsym, Type bound, Type lower) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
            super(TYPEVAR, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
            this.bound = bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
            this.lower = lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
            return v.visitTypeVar(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1041
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
        public Type getUpperBound() { return bound; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
        int rank_field = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1046
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
        public Type getLowerBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
            return lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
            return TypeKind.TYPEVAR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
938
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1055
        public boolean isCaptured() {
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1056
            return false;
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1057
        }
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1058
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
            return v.visitTypeVariable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
    /** A captured type variable comes from wildcards which can have
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
     *  both upper and lower bound.  CapturedType extends TypeVar with
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
     *  a lower bound.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
    public static class CapturedType extends TypeVar {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
        public WildcardType wildcard;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
        public CapturedType(Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
                            Symbol owner,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
                            Type upper,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
                            Type lower,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
                            WildcardType wildcard) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
            super(name, owner, lower);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
  1078
            this.lower = Assert.checkNonNull(lower);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
            this.bound = upper;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
            this.wildcard = wildcard;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
            return v.visitCapturedType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
        @Override
938
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1089
        public boolean isCaptured() {
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1090
            return true;
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1091
        }
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1092
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1093
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
            return "capture#"
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 1527
diff changeset
  1096
                + (hashCode() & 0xFFFFFFFFL) % Printer.PRIME
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
                + " of "
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
                + wildcard;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
    public static abstract class DelegatedType extends Type {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
        public Type qtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
        public DelegatedType(int tag, Type qtype) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
            super(tag, qtype.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
            this.qtype = qtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
        public String toString() { return qtype.toString(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
        public List<Type> getTypeArguments() { return qtype.getTypeArguments(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
        public Type getEnclosingType() { return qtype.getEnclosingType(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
        public List<Type> getParameterTypes() { return qtype.getParameterTypes(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
        public Type getReturnType() { return qtype.getReturnType(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
        public List<Type> getThrownTypes() { return qtype.getThrownTypes(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
        public List<Type> allparams() { return qtype.allparams(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
        public Type getUpperBound() { return qtype.getUpperBound(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
        public boolean isErroneous() { return qtype.isErroneous(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1119
    /**
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1120
     * The type of a generic method type. It consists of a method type and
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1121
     * a list of method type-parameters that are used within the method
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1122
     * type.
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1123
     */
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8044
diff changeset
  1124
    public static class ForAll extends DelegatedType implements ExecutableType {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
        public List<Type> tvars;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
        public ForAll(List<Type> tvars, Type qtype) {
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1128
            super(FORALL, (MethodType)qtype);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
            this.tvars = tvars;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
            return v.visitForAll(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
            return "<" + tvars + ">" + qtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
        public List<Type> getTypeArguments()   { return tvars; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
        public boolean isErroneous()  {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
            return qtype.isErroneous();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
        public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
            return f.apply(qtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
        public boolean contains(Type elem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
            return qtype.contains(elem);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1153
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
06bc494ca11e Initial load
duke
parents:
diff changeset
  1155
        public MethodType asMethodType() {
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1156
            return (MethodType)qtype;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
            for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
                ((TypeVar)l.head).bound.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
            qtype.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1165
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
        public List<TypeVar> getTypeVariables() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
            return List.convert(TypeVar.class, getTypeArguments());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
            return TypeKind.EXECUTABLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1175
            return v.visitExecutable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1179
    /** A class for inference variables, for use during method/diamond type
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1180
     *  inference. An inference variable has upper/lower bounds and a set
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1181
     *  of equality constraints. Such bounds are set during subtyping, type-containment,
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1182
     *  type-equality checks, when the types being tested contain inference variables.
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1183
     *  A change listener can be attached to an inference variable, to receive notifications
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1184
     *  whenever the bounds of an inference variable change.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1186
    public static class UndetVar extends DelegatedType {
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1187
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1188
        /** Inference variable change listener. The listener method is called
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1189
         *  whenever a change to the inference variable's bounds occurs
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1190
         */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1191
        public interface UndetVarListener {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1192
            /** called when some inference variable bounds (of given kinds ibs) change */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1193
            void varChanged(UndetVar uv, Set<InferenceBound> ibs);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1194
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1195
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1196
        /**
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1197
         * Inference variable bound kinds
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1198
         */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1199
        public enum InferenceBound {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1200
            /** upper bounds */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1201
            UPPER,
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1202
            /** lower bounds */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1203
            LOWER,
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1204
            /** equality constraints */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1205
            EQ;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1206
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1207
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1208
        /** inference variable bounds */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1209
        private Map<InferenceBound, List<Type>> bounds;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1210
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1211
        /** inference variable's inferred type (set from Infer.java) */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
        public Type inst = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1214
        /** inference variable's change listener */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1215
        public UndetVarListener listener = null;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1216
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1217
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1218
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1219
            return v.visitUndetVar(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1220
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1221
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1222
        public UndetVar(TypeVar origin, Types types) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
            super(UNDETVAR, origin);
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1224
            bounds = new EnumMap<InferenceBound, List<Type>>(InferenceBound.class);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1225
            bounds.put(InferenceBound.UPPER, types.getBounds(origin));
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1226
            bounds.put(InferenceBound.LOWER, List.<Type>nil());
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1227
            bounds.put(InferenceBound.EQ, List.<Type>nil());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1229
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
            if (inst != null) return inst.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
            else return qtype + "?";
06bc494ca11e Initial load
duke
parents:
diff changeset
  1233
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1234
06bc494ca11e Initial load
duke
parents:
diff changeset
  1235
        public Type baseType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
            if (inst != null) return inst.baseType();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
            else return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
        }
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1239
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1240
        /** get all bounds of a given kind */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1241
        public List<Type> getBounds(InferenceBound ib) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1242
            return bounds.get(ib);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1243
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1244
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1245
        /** add a bound of a given kind - this might trigger listener notification */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1246
        public void addBound(InferenceBound ib, Type bound, Types types) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1247
            List<Type> prevBounds = bounds.get(ib);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1248
            for (Type b : prevBounds) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1249
                if (types.isSameType(b, bound)) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1250
                    return;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1251
                }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1252
            }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1253
            bounds.put(ib, prevBounds.prepend(bound));
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1254
            notifyChange(EnumSet.of(ib));
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1255
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1256
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1257
        /** replace types in all bounds - this might trigger listener notification */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1258
        public void substBounds(List<Type> from, List<Type> to, Types types) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1259
            EnumSet<InferenceBound> changed = EnumSet.noneOf(InferenceBound.class);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1260
            Map<InferenceBound, List<Type>> bounds2 = new EnumMap<InferenceBound, List<Type>>(InferenceBound.class);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1261
            for (Map.Entry<InferenceBound, List<Type>> _entry : bounds.entrySet()) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1262
                InferenceBound ib = _entry.getKey();
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1263
                List<Type> prevBounds = _entry.getValue();
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1264
                List<Type> newBounds = types.subst(prevBounds, from, to);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1265
                bounds2.put(ib, newBounds);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1266
                if (prevBounds != newBounds) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1267
                    changed.add(ib);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1268
                }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1269
            }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1270
            if (!changed.isEmpty()) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1271
                bounds = bounds2;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1272
                notifyChange(changed);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1273
            }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1274
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1275
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1276
        private void notifyChange(EnumSet<InferenceBound> ibs) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1277
            if (listener != null) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1278
                listener.varChanged(this, ibs);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1279
            }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1280
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1281
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1282
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
    /** Represents VOID or NONE.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1285
    static class JCNoType extends Type implements NoType {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1286
        public JCNoType(int tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1287
            super(tag, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1292
            switch (tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
            case VOID:  return TypeKind.VOID;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1294
            case NONE:  return TypeKind.NONE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1295
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1296
                throw new AssertionError("Unexpected tag: " + tag);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1297
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1298
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1299
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1301
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
            return v.visitNoType(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1303
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1304
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1305
06bc494ca11e Initial load
duke
parents:
diff changeset
  1306
    static class BottomType extends Type implements NullType {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1307
        public BottomType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1308
            super(TypeTags.BOT, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1309
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1310
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1312
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1313
            return TypeKind.NULL;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1314
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1315
06bc494ca11e Initial load
duke
parents:
diff changeset
  1316
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1317
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
            return v.visitNull(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
06bc494ca11e Initial load
duke
parents:
diff changeset
  1321
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
        public Type constType(Object value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
06bc494ca11e Initial load
duke
parents:
diff changeset
  1326
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
        public String stringValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1328
            return "null";
06bc494ca11e Initial load
duke
parents:
diff changeset
  1329
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1330
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
06bc494ca11e Initial load
duke
parents:
diff changeset
  1332
    public static class ErrorType extends ClassType
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
            implements javax.lang.model.type.ErrorType {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1334
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1335
        private Type originalType = null;
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1336
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1337
        public ErrorType(Type originalType, TypeSymbol tsym) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1338
            super(noType, List.<Type>nil(), null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
            tag = ERROR;
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1340
            this.tsym = tsym;
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1341
            this.originalType = (originalType == null ? noType : originalType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1342
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1343
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1344
        public ErrorType(ClassSymbol c, Type originalType) {
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1345
            this(originalType, c);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1346
            c.type = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1347
            c.kind = ERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1348
            c.members_field = new Scope.ErrorScope(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1349
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1350
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1351
        public ErrorType(Name name, TypeSymbol container, Type originalType) {
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1352
            this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1353
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1354
06bc494ca11e Initial load
duke
parents:
diff changeset
  1355
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1356
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
            return v.visitErrorType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1358
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
06bc494ca11e Initial load
duke
parents:
diff changeset
  1360
        public Type constType(Object constValue) { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
        public Type getEnclosingType()          { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
        public Type getReturnType()              { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1363
        public Type asSub(Symbol sym)            { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1364
        public Type map(Mapping f)               { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1365
06bc494ca11e Initial load
duke
parents:
diff changeset
  1366
        public boolean isGenType(Type t)         { return true; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1367
        public boolean isErroneous()             { return true; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1368
        public boolean isCompound()              { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1369
        public boolean isInterface()             { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1370
06bc494ca11e Initial load
duke
parents:
diff changeset
  1371
        public List<Type> allparams()            { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1372
        public List<Type> getTypeArguments()     { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1373
06bc494ca11e Initial load
duke
parents:
diff changeset
  1374
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1375
            return TypeKind.ERROR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1376
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1377
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1378
        public Type getOriginalType() {
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1379
            return originalType;
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1380
        }
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1381
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1382
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1383
            return v.visitError(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1384
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1385
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1386
06bc494ca11e Initial load
duke
parents:
diff changeset
  1387
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
     * A visitor for types.  A visitor is used to implement operations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
     * (or relations) on types.  Most common operations on types are
06bc494ca11e Initial load
duke
parents:
diff changeset
  1390
     * binary relations and this interface is designed for binary
06bc494ca11e Initial load
duke
parents:
diff changeset
  1391
     * relations, that is, operations on the form
06bc494ca11e Initial load
duke
parents:
diff changeset
  1392
     * Type&nbsp;&times;&nbsp;S&nbsp;&rarr;&nbsp;R.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1393
     * <!-- In plain text: Type x S -> R -->
06bc494ca11e Initial load
duke
parents:
diff changeset
  1394
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1395
     * @param <R> the return type of the operation implemented by this
06bc494ca11e Initial load
duke
parents:
diff changeset
  1396
     * visitor; use Void if no return type is needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1397
     * @param <S> the type of the second argument (the first being the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1398
     * type itself) of the operation implemented by this visitor; use
06bc494ca11e Initial load
duke
parents:
diff changeset
  1399
     * Void if a second argument is not needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1400
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1401
    public interface Visitor<R,S> {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1402
        R visitClassType(ClassType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1403
        R visitWildcardType(WildcardType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1404
        R visitArrayType(ArrayType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1405
        R visitMethodType(MethodType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1406
        R visitPackageType(PackageType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1407
        R visitTypeVar(TypeVar t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1408
        R visitCapturedType(CapturedType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1409
        R visitForAll(ForAll t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1410
        R visitUndetVar(UndetVar t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1411
        R visitErrorType(ErrorType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
        R visitType(Type t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1413
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
}