langtools/src/share/classes/com/sun/tools/javac/code/Type.java
author mcimadamore
Tue, 12 Mar 2013 16:02:43 +0000
changeset 16341 cc4b4e3c0f12
parent 15705 c4124695db0c
child 16556 f4adc5bb4652
permissions -rw-r--r--
8009545: Graph inference: dependencies between inference variables should be set during incorporation Summary: Move all transitivity checks into the incorporation round Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
     2
 * Copyright (c) 1999, 2013, 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;
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
    29
import java.util.EnumMap;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
    30
import java.util.EnumSet;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
    31
import java.util.Map;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
    32
import java.util.Set;
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14048
diff changeset
    33
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
    34
import javax.lang.model.element.AnnotationMirror;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import javax.lang.model.type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14058
diff changeset
    37
import com.sun.tools.javac.code.Symbol.*;
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14058
diff changeset
    38
import com.sun.tools.javac.util.*;
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14048
diff changeset
    39
import static com.sun.tools.javac.code.BoundKind.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
import static com.sun.tools.javac.code.Kinds.*;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    42
import static com.sun.tools.javac.code.TypeTag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
/** This class represents Java types. The class itself defines the behavior of
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *  the following types:
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *  base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN),
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *  type `void' (tag: VOID),
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  the bottom type (tag: BOT),
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *  the missing type (tag: NONE).
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *  <p>The behavior of the following types is defined in subclasses, which are
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *  all static inner classes of this class:
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *  class types (tag: CLASS, class: ClassType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *  array types (tag: ARRAY, class: ArrayType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *  method types (tag: METHOD, class: MethodType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *  package types (tag: PACKAGE, class: PackageType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *  type variables (tag: TYPEVAR, class: TypeVar),
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 *  type arguments (tag: WILDCARD, class: WildcardType),
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
    61
 *  generic method types (tag: FORALL, class: ForAll),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *  the error type (tag: ERROR, class: ErrorType).
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    65
 *  <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
    66
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 *
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    70
 *  @see TypeTag
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
public class Type implements PrimitiveType {
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    /** Constant type: no type at all. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    public static final JCNoType noType = new JCNoType(NONE);
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14052
diff changeset
    77
    /** 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
    78
    public static final JCNoType recoveryType = new JCNoType(NONE);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14052
diff changeset
    79
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /** If this switch is turned on, the names of type variables
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     *  and anonymous classes are printed with hashcodes appended.
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    public static boolean moreInfo = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    /** The tag of this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     *
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    87
     *  @see TypeTag
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     */
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    89
    protected TypeTag tag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
    91
    /** The defining class / interface / package / type variable.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    public TypeSymbol tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /**
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    96
     * Checks if the current type tag is equal to the given tag.
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    97
     * @return true if tag is equal to the current type tag.
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    98
     */
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    99
    public boolean hasTag(TypeTag tag) {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   100
        return this.tag == tag;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   101
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   102
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   103
    /**
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   104
     * Returns the current type tag.
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   105
     * @return the value of the current type tag.
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   106
     */
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   107
    public TypeTag getTag() {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   108
        return tag;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   109
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   110
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   111
    public boolean isNumeric() {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   112
        switch (tag) {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   113
            case BYTE: case CHAR:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   114
            case SHORT:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   115
            case INT: case LONG:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   116
            case FLOAT: case DOUBLE:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   117
                return true;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   118
            default:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   119
                return false;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   120
        }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   121
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   122
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   123
    public boolean isPrimitive() {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   124
        return (isNumeric() || tag == BOOLEAN);
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   125
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   126
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   127
    public boolean isPrimitiveOrVoid() {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   128
        return (isPrimitive() || tag == VOID);
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   129
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   130
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   131
    public boolean isReference() {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   132
        switch (tag) {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   133
        case CLASS:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   134
        case ARRAY:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   135
        case TYPEVAR:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   136
        case WILDCARD:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   137
        case ERROR:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   138
            return true;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   139
        default:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   140
            return false;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   141
        }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   142
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   143
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   144
    public boolean isNullOrReference() {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   145
        return (tag == BOT || isReference());
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   146
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   147
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   148
    public boolean isPartial() {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   149
        switch(tag) {
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   150
            case ERROR: case UNKNOWN: case UNDETVAR:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   151
                return true;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   152
            default:
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   153
                return false;
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   154
        }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   155
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   156
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   157
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     * The constant value of this type, null if this type does not
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     * have a constant value attribute. Only primitive types and
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     * strings (ClassType) can have a constant value attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     * @return the constant value attribute of this type
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    public Object constValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   167
    /**
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   168
     * Get the representation of this type used for modelling purposes.
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   169
     * By default, this is itself. For ErrorType, a different value
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   170
     * may be provided.
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   171
     */
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   172
    public Type getModelType() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   173
        return this;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   174
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   175
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   176
    public static List<Type> getModelTypes(List<Type> ts) {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   177
        ListBuffer<Type> lb = new ListBuffer<Type>();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   178
        for (Type t: ts)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   179
            lb.append(t.getModelType());
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   180
        return lb.toList();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   181
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   182
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    /** Define a type given its tag and type symbol
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     */
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   187
    public Type(TypeTag tag, TypeSymbol tsym) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
        this.tag = tag;
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        this.tsym = tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    /** An abstract class for mappings from types to types
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
    public static abstract class Mapping {
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        private String name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
        public Mapping(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
            this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
        public abstract Type apply(Type t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
            return name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
    /** map a type function over all immediate descendants of this type
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
    public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
    /** map a type function over a list of types
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    public static List<Type> map(List<Type> ts, Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        if (ts.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
            List<Type> tail1 = map(ts.tail, f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
            Type t = f.apply(ts.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
            if (tail1 != ts.tail || t != ts.head)
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
                return tail1.prepend(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
        return ts;
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    /** Define a constant type, of the same kind as this type
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     *  and with given constant value
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    public Type constType(Object constValue) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        final Object value = constValue;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   228
        Assert.check(isPrimitive());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        return new Type(tag, tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
                @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
                public Object constValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
                    return value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
                @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
                public Type baseType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                    return tsym.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
                }
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
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * If this is a constant type, return its underlying type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     * Otherwise, return the type itself.
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    public Type baseType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   249
    /**
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   250
     * If this is an annotated type, return the underlying type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   251
     * Otherwise, return the type itself.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   252
     */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   253
    public Type unannotatedType() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   254
        return this;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   255
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   256
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
    /** Return the base types of a list of types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
    public static List<Type> baseTypes(List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
        if (ts.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
            Type t = ts.head.baseType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
            List<Type> baseTypes = baseTypes(ts.tail);
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
            if (t != ts.head || baseTypes != ts.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
                return baseTypes.prepend(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        return ts;
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
    /** The Java source which this type represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
    public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
        String s = (tsym == null || tsym.name == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
            ? "<none>"
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
            : tsym.name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
        if (moreInfo && tag == TYPEVAR) s = s + hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
        return s;
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     * The Java source which this type list represents.  A List is
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     * represented as a comma-spearated listing of the elements in
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     * that list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    public static String toString(List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        if (ts.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
            return "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        } else {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   288
            StringBuilder buf = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
            buf.append(ts.head.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
            for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
                buf.append(",").append(l.head.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
            return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     * The constant value of this type, converted to String
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
    public String stringValue() {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   300
        Object cv = Assert.checkNonNull(constValue());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
        if (tag == BOOLEAN)
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   302
            return ((Integer) cv).intValue() == 0 ? "false" : "true";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
        else if (tag == CHAR)
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   304
            return String.valueOf((char) ((Integer) cv).intValue());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
        else
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   306
            return cv.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
     * This method is analogous to isSameType, but weaker, since we
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
     * never complete classes. Where isSameType would complete a
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
     * class, equals assumes that the two types are different.
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
     */
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14725
diff changeset
   314
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
    public boolean equals(Object t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
        return super.equals(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
14949
45f43822bbde 8000518: Javac generates duplicate name_and_type constant pool entry for class BinaryOpValueExp.java
vromero
parents: 14725
diff changeset
   319
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
    public int hashCode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
        return super.hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
    /** Is this a constant type whose value is false?
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    public boolean isFalse() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
            tag == BOOLEAN &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
            constValue() != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
            ((Integer)constValue()).intValue() == 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
    /** Is this a constant type whose value is true?
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
    public boolean isTrue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        return
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
            tag == BOOLEAN &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
            constValue() != null &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
            ((Integer)constValue()).intValue() != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
    public String argtypes(boolean varargs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
        List<Type> args = getParameterTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
        if (!varargs) return args.toString();
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
   345
        StringBuilder buf = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
        while (args.tail.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
            buf.append(args.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
            args = args.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
            buf.append(',');
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   351
        if (args.head.unannotatedType().tag == ARRAY) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   352
            buf.append(((ArrayType)args.head.unannotatedType()).elemtype);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   353
            if (args.head.getAnnotations().nonEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   354
                buf.append(args.head.getAnnotations());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   355
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
            buf.append("...");
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
            buf.append(args.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
    /** Access methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
     */
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   365
    public List<? extends AnnotationMirror> getAnnotations() { return List.nil(); }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
    public List<Type>        getTypeArguments()  { return List.nil(); }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   367
    public Type              getEnclosingType()  { return null; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
    public List<Type>        getParameterTypes() { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
    public Type              getReturnType()     { return null; }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   370
    public Type              getReceiverType()   { return null; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
    public List<Type>        getThrownTypes()    { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
    public Type              getUpperBound()     { return null; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
    public Type              getLowerBound()     { return null; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
    /** Navigation methods, these will work for classes, type variables,
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
     *  foralls, but will return null for arrays and methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
   /** Return all parameters of this type and all its outer types in order
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
    *  outer (first) to inner (last).
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
    */
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
    public List<Type> allparams() { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
    /** Does this type contain "error" elements?
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
    public boolean isErroneous() {
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
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
    public static boolean isErroneous(List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
        for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
            if (l.head.isErroneous()) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
    /** Is this type parameterized?
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
     *  A class type is parameterized if it has some parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
     *  An array type is parameterized if its element type is parameterized.
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
     *  All other types are not parameterized.
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
    public boolean isParameterized() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
    /** Is this type a raw type?
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
     *  A class type is a raw type if it misses some of its parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
     *  An array type is a raw type if its element type is raw.
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
     *  All other types are not raw.
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
     *  Type validation will ensure that the only raw types
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
     *  in a program are types that miss all their type variables.
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
    public boolean isRaw() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
    public boolean isCompound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        return tsym.completer == null
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
            // Compound types can't have a completer.  Calling
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            // flags() will complete the symbol causing the
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
            // compiler to load classes unnecessarily.  This led
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
            // to regression 6180021.
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
            && (tsym.flags() & COMPOUND) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
    public boolean isInterface() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        return (tsym.flags() & INTERFACE) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
6353
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   429
    public boolean isFinal() {
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   430
        return (tsym.flags() & FINAL) != 0;
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   431
    }
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   432
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
     * Does this type contain occurrences of type t?
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
    public boolean contains(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        return t == this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
    public static boolean contains(List<Type> ts, Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        for (List<Type> l = ts;
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
             l.tail != null /*inlined: l.nonEmpty()*/;
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
             l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
            if (l.head.contains(t)) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   448
    /** Does this type contain an occurrence of some type in 'ts'?
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
     */
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   450
    public boolean containsAny(List<Type> ts) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   451
        for (Type t : ts)
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   452
            if (this.contains(t)) return true;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   453
        return false;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   454
    }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   455
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   456
    public static boolean containsAny(List<Type> ts1, List<Type> ts2) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   457
        for (Type t : ts1)
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   458
            if (t.containsAny(ts2)) return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   462
    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
   463
        ListBuffer<Type> buf = ListBuffer.lb();
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   464
        for (Type t : ts) {
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   465
            if (tf.accepts(t)) {
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   466
                buf.append(t);
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   467
            }
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   468
        }
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   469
        return buf.toList();
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   470
    }
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   471
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
    public boolean isSuperBound() { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
    public boolean isExtendsBound() { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
    public boolean isUnbound() { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
    public Type withTypeVar(Type t) { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
    /** The underlying method type of this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
    public MethodType asMethodType() { throw new AssertionError(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    /** Complete loading all classes in this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
    public void complete() {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
    public TypeSymbol asElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
        return tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
    public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        switch (tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        case BYTE:      return TypeKind.BYTE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        case CHAR:      return TypeKind.CHAR;
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
        case SHORT:     return TypeKind.SHORT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
        case INT:       return TypeKind.INT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
        case LONG:      return TypeKind.LONG;
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
        case FLOAT:     return TypeKind.FLOAT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
        case DOUBLE:    return TypeKind.DOUBLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
        case BOOLEAN:   return TypeKind.BOOLEAN;
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
        case VOID:      return TypeKind.VOID;
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
        case BOT:       return TypeKind.NULL;
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
        case NONE:      return TypeKind.NONE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
        default:        return TypeKind.OTHER;
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
    public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        if (isPrimitive())
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
            return v.visitPrimitive(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
        else
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
            throw new AssertionError();
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
    public static class WildcardType extends Type
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
            implements javax.lang.model.type.WildcardType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
        public Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        public BoundKind kind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        public TypeVar bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
            return v.visitWildcardType(this, s);
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 WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
            super(WILDCARD, tsym);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   527
            this.type = Assert.checkNonNull(type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
            this.kind = kind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
        public WildcardType(WildcardType t, TypeVar bound) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
            this(t.type, t.kind, t.tsym, bound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
        public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, TypeVar bound) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
            this(type, kind, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
            this.bound = bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   539
        public boolean contains(Type t) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   540
            return kind != UNBOUND && type.contains(t);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   541
        }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   542
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        public boolean isSuperBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
            return kind == SUPER ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
                kind == UNBOUND;
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        public boolean isExtendsBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
            return kind == EXTENDS ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
                kind == UNBOUND;
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        public boolean isUnbound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
            return kind == UNBOUND;
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
        public Type withTypeVar(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
            //-System.err.println(this+".withTypeVar("+t+");");//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
            if (bound == t)
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
                return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
            bound = (TypeVar)t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        boolean isPrintingBound = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        public String toString() {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   565
            StringBuilder s = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
            s.append(kind.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
            if (kind != UNBOUND)
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
                s.append(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
            if (moreInfo && bound != null && !isPrintingBound)
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
                    isPrintingBound = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
                    s.append("{:").append(bound.bound).append(":}");
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
                } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
                    isPrintingBound = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
            return s.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
            //- System.err.println("   (" + this + ").map(" + f + ")");//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
            Type t = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
            if (t != null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
                t = f.apply(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
            if (t == type)
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
                return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
                return new WildcardType(t, kind, tsym, bound);
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
        public Type getExtendsBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
            if (kind == EXTENDS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
                return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
        public Type getSuperBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
            if (kind == SUPER)
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
                return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
            return TypeKind.WILDCARD;
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
            return v.visitWildcard(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
    public static class ClassType extends Type implements DeclaredType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
        /** The enclosing type of this type. If this is the type of an inner
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
         *  class, outer_field refers to the type of its enclosing
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   617
         *  instance class, in all other cases it refers to noType.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
        private Type outer_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
        /** The type parameters of this type (to be set once class is loaded).
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        public List<Type> typarams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
        /** A cache variable for the type parameters of this type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
         *  appended to all parameters of its enclosing class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
         *  @see #allparams
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
        public List<Type> allparams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
        /** The supertype of this class (to be set once class is loaded).
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
        public Type supertype_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
        /** The interfaces of this class (to be set once class is loaded).
06bc494ca11e Initial load
duke
parents:
diff changeset
   636
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   637
        public List<Type> interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   638
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   639
        /** All the interfaces of this class, including missing ones.
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   640
         */
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   641
        public List<Type> all_interfaces_field;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   642
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
        public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
            super(CLASS, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   645
            this.outer_field = outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   646
            this.typarams_field = typarams;
06bc494ca11e Initial load
duke
parents:
diff changeset
   647
            this.allparams_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   648
            this.supertype_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   649
            this.interfaces_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   650
            /*
06bc494ca11e Initial load
duke
parents:
diff changeset
   651
            // this can happen during error recovery
06bc494ca11e Initial load
duke
parents:
diff changeset
   652
            assert
06bc494ca11e Initial load
duke
parents:
diff changeset
   653
                outer.isParameterized() ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   654
                typarams.length() == tsym.type.typarams().length() :
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
                outer.isRaw() ?
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
                typarams.length() == 0 :
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
                true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
            */
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
            return v.visitClassType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
        public Type constType(Object constValue) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
            final Object value = constValue;
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
            return new ClassType(getEnclosingType(), typarams_field, tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
                    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
                    public Object constValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
                        return value;
06bc494ca11e Initial load
duke
parents:
diff changeset
   672
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
                    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   674
                    public Type baseType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   675
                        return tsym.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   676
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   677
                };
06bc494ca11e Initial load
duke
parents:
diff changeset
   678
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   679
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
        /** The Java source which this type represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   682
        public String toString() {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   683
            StringBuilder buf = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   684
            if (getEnclosingType().tag == CLASS && tsym.owner.kind == TYP) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   685
                buf.append(getEnclosingType().toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   686
                buf.append(".");
06bc494ca11e Initial load
duke
parents:
diff changeset
   687
                buf.append(className(tsym, false));
06bc494ca11e Initial load
duke
parents:
diff changeset
   688
            } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   689
                buf.append(className(tsym, true));
06bc494ca11e Initial load
duke
parents:
diff changeset
   690
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   691
            if (getTypeArguments().nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   692
                buf.append('<');
06bc494ca11e Initial load
duke
parents:
diff changeset
   693
                buf.append(getTypeArguments().toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   694
                buf.append(">");
06bc494ca11e Initial load
duke
parents:
diff changeset
   695
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   696
            return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   697
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   698
//where
06bc494ca11e Initial load
duke
parents:
diff changeset
   699
            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
   700
                if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   701
                    StringBuilder s = new StringBuilder(supertype_field.toString());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   702
                    for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   703
                        s.append("&");
06bc494ca11e Initial load
duke
parents:
diff changeset
   704
                        s.append(is.head.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   705
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   706
                    return s.toString();
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   707
                } else if (sym.name.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   708
                    String s;
06bc494ca11e Initial load
duke
parents:
diff changeset
   709
                    ClassType norm = (ClassType) tsym.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   710
                    if (norm == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   711
                        s = Log.getLocalizedString("anonymous.class", (Object)null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   712
                    } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   713
                        s = Log.getLocalizedString("anonymous.class",
06bc494ca11e Initial load
duke
parents:
diff changeset
   714
                                                   norm.interfaces_field.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   715
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   716
                        s = Log.getLocalizedString("anonymous.class",
06bc494ca11e Initial load
duke
parents:
diff changeset
   717
                                                   norm.supertype_field);
06bc494ca11e Initial load
duke
parents:
diff changeset
   718
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   719
                    if (moreInfo)
06bc494ca11e Initial load
duke
parents:
diff changeset
   720
                        s += String.valueOf(sym.hashCode());
06bc494ca11e Initial load
duke
parents:
diff changeset
   721
                    return s;
06bc494ca11e Initial load
duke
parents:
diff changeset
   722
                } else if (longform) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   723
                    return sym.getQualifiedName().toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   724
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   725
                    return sym.name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   726
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   727
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   728
06bc494ca11e Initial load
duke
parents:
diff changeset
   729
        public List<Type> getTypeArguments() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   730
            if (typarams_field == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   731
                complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   732
                if (typarams_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   733
                    typarams_field = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   734
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   735
            return typarams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   736
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   737
514
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   738
        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
   739
            return isRaw();
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   740
        }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   741
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   742
        public Type getEnclosingType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   743
            return outer_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   744
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   745
06bc494ca11e Initial load
duke
parents:
diff changeset
   746
        public void setEnclosingType(Type outer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   747
            outer_field = outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   748
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   749
06bc494ca11e Initial load
duke
parents:
diff changeset
   750
        public List<Type> allparams() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   751
            if (allparams_field == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   752
                allparams_field = getTypeArguments().prependList(getEnclosingType().allparams());
06bc494ca11e Initial load
duke
parents:
diff changeset
   753
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
   754
            return allparams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   755
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   756
06bc494ca11e Initial load
duke
parents:
diff changeset
   757
        public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   758
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   759
                getEnclosingType().isErroneous() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   760
                isErroneous(getTypeArguments()) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   761
                this != tsym.type && tsym.type.isErroneous();
06bc494ca11e Initial load
duke
parents:
diff changeset
   762
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   763
06bc494ca11e Initial load
duke
parents:
diff changeset
   764
        public boolean isParameterized() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   765
            return allparams().tail != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   766
            // optimization, was: allparams().nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   767
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   768
06bc494ca11e Initial load
duke
parents:
diff changeset
   769
        /** A cache for the rank. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   770
        int rank_field = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   771
06bc494ca11e Initial load
duke
parents:
diff changeset
   772
        /** A class type is raw if it misses some
06bc494ca11e Initial load
duke
parents:
diff changeset
   773
         *  of its type parameter sections.
06bc494ca11e Initial load
duke
parents:
diff changeset
   774
         *  After validation, this is equivalent to:
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13631
diff changeset
   775
         *  {@code allparams.isEmpty() && tsym.type.allparams.nonEmpty(); }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   776
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   777
        public boolean isRaw() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   778
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   779
                this != tsym.type && // necessary, but not sufficient condition
06bc494ca11e Initial load
duke
parents:
diff changeset
   780
                tsym.type.allparams().nonEmpty() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   781
                allparams().isEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
   782
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   783
06bc494ca11e Initial load
duke
parents:
diff changeset
   784
        public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   785
            Type outer = getEnclosingType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   786
            Type outer1 = f.apply(outer);
06bc494ca11e Initial load
duke
parents:
diff changeset
   787
            List<Type> typarams = getTypeArguments();
06bc494ca11e Initial load
duke
parents:
diff changeset
   788
            List<Type> typarams1 = map(typarams, f);
06bc494ca11e Initial load
duke
parents:
diff changeset
   789
            if (outer1 == outer && typarams1 == typarams) return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   790
            else return new ClassType(outer1, typarams1, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   791
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   792
06bc494ca11e Initial load
duke
parents:
diff changeset
   793
        public boolean contains(Type elem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   794
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   795
                elem == this
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
                || (isParameterized()
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   797
                    && (getEnclosingType().contains(elem) || contains(getTypeArguments(), elem)))
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   798
                || (isCompound()
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   799
                    && (supertype_field.contains(elem) || contains(interfaces_field, elem)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   800
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   801
06bc494ca11e Initial load
duke
parents:
diff changeset
   802
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   803
            if (tsym.completer != null) tsym.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   804
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   805
06bc494ca11e Initial load
duke
parents:
diff changeset
   806
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   807
            return TypeKind.DECLARED;
06bc494ca11e Initial load
duke
parents:
diff changeset
   808
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   809
06bc494ca11e Initial load
duke
parents:
diff changeset
   810
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
            return v.visitDeclared(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   812
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   813
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
514
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   815
    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
   816
        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
   817
            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
   818
        }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   819
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   820
        @Override
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   821
        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
   822
            return true;
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   823
        }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   824
    }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
   825
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   826
    // 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
   827
    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
   828
        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
   829
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   830
        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
   831
            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
   832
            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
   833
            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
   834
            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
   835
            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
   836
            alternatives_field = alternatives;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   837
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   838
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   839
        public Type getLub() {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   840
            return tsym.type;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   841
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   842
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   843
        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
   844
            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
   845
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   846
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   847
        @Override
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   848
        public TypeKind getKind() {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   849
            return TypeKind.UNION;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   850
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   851
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   852
        @Override
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   853
        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
   854
            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
   855
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   856
    }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
   857
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   858
    // a clone of a ClassType that knows about the bounds of an intersection type.
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   859
    public static class IntersectionClassType extends ClassType implements IntersectionType {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   860
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   861
        public boolean allInterfaces;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   862
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   863
        public enum IntersectionKind {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   864
            EXPLICIT,
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   865
            IMPLICT;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   866
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   867
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   868
        public IntersectionKind intersectionKind;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   869
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   870
        public IntersectionClassType(List<Type> bounds, ClassSymbol csym, boolean allInterfaces) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   871
            super(Type.noType, List.<Type>nil(), csym);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   872
            this.allInterfaces = allInterfaces;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   873
            Assert.check((csym.flags() & COMPOUND) != 0);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   874
            supertype_field = bounds.head;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   875
            interfaces_field = bounds.tail;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   876
            Assert.check(supertype_field.tsym.completer != null ||
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   877
                    !supertype_field.isInterface(), supertype_field);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   878
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   879
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   880
        public java.util.List<? extends TypeMirror> getBounds() {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   881
            return Collections.unmodifiableList(getComponents());
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   882
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   883
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   884
        public List<Type> getComponents() {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   885
            return interfaces_field.prepend(supertype_field);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   886
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   887
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   888
        @Override
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   889
        public TypeKind getKind() {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   890
            return TypeKind.INTERSECTION;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   891
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   892
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   893
        @Override
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   894
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   895
            return intersectionKind == IntersectionKind.EXPLICIT ?
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   896
                v.visitIntersection(this, p) :
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   897
                v.visitDeclared(this, p);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   898
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   899
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
   900
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
    public static class ArrayType extends Type
06bc494ca11e Initial load
duke
parents:
diff changeset
   902
            implements javax.lang.model.type.ArrayType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   903
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
        public Type elemtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
        public ArrayType(Type elemtype, TypeSymbol arrayClass) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
            super(ARRAY, arrayClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
            this.elemtype = elemtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
            return v.visitArrayType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   917
            return elemtype + "[]";
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
        public boolean equals(Object obj) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
                this == obj ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
                (obj instanceof ArrayType &&
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
                 this.elemtype.equals(((ArrayType)obj).elemtype));
06bc494ca11e Initial load
duke
parents:
diff changeset
   925
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
        public int hashCode() {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   928
            return (ARRAY.ordinal() << 5) + elemtype.hashCode();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   931
        public boolean isVarargs() {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   932
            return false;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   933
        }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   934
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
        public List<Type> allparams() { return elemtype.allparams(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
        public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   938
            return elemtype.isErroneous();
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
        public boolean isParameterized() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
            return elemtype.isParameterized();
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
        public boolean isRaw() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
            return elemtype.isRaw();
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   948
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   949
        public ArrayType makeVarargs() {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   950
            return new ArrayType(elemtype, tsym) {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   951
                @Override
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   952
                public boolean isVarargs() {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   953
                    return true;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   954
                }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   955
            };
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   956
        }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
   957
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
        public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
            Type elemtype1 = f.apply(elemtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
            if (elemtype1 == elemtype) return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
            else return new ArrayType(elemtype1, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
        public boolean contains(Type elem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
            return elem == this || elemtype.contains(elem);
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
            elemtype.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
   970
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   971
06bc494ca11e Initial load
duke
parents:
diff changeset
   972
        public Type getComponentType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   973
            return elemtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   975
06bc494ca11e Initial load
duke
parents:
diff changeset
   976
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   977
            return TypeKind.ARRAY;
06bc494ca11e Initial load
duke
parents:
diff changeset
   978
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   979
06bc494ca11e Initial load
duke
parents:
diff changeset
   980
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
            return v.visitArray(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8044
diff changeset
   985
    public static class MethodType extends Type implements ExecutableType {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
        public List<Type> argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
        public Type restype;
06bc494ca11e Initial load
duke
parents:
diff changeset
   989
        public List<Type> thrown;
06bc494ca11e Initial load
duke
parents:
diff changeset
   990
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   991
        /** The type annotations on the method receiver.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   992
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   993
        public Type recvtype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   994
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   995
        public MethodType(List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   996
                          Type restype,
06bc494ca11e Initial load
duke
parents:
diff changeset
   997
                          List<Type> thrown,
06bc494ca11e Initial load
duke
parents:
diff changeset
   998
                          TypeSymbol methodClass) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   999
            super(METHOD, methodClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1000
            this.argtypes = argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1001
            this.restype = restype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
            this.thrown = thrown;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
            return v.visitMethodType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1008
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
        /** The Java source which this type represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
         *  XXX 06/09/99 iris This isn't correct Java syntax, but it probably
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
         *  should be.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
            return "(" + argtypes + ")" + restype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
        public List<Type>        getParameterTypes() { return argtypes; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
        public Type              getReturnType()     { return restype; }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1021
        public Type              getReceiverType()   { return recvtype; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1022
        public List<Type>        getThrownTypes()    { return thrown; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
06bc494ca11e Initial load
duke
parents:
diff changeset
  1024
        public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1025
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
                isErroneous(argtypes) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
                restype != null && restype.isErroneous();
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 Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1031
            List<Type> argtypes1 = map(argtypes, f);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
            Type restype1 = f.apply(restype);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
            List<Type> thrown1 = map(thrown, f);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1034
            if (argtypes1 == argtypes &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
                restype1 == restype &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
                thrown1 == thrown) return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
            else return new MethodType(argtypes1, restype1, thrown1, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
        public boolean contains(Type elem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
            return elem == this || contains(argtypes, elem) || restype.contains(elem);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
06bc494ca11e Initial load
duke
parents:
diff changeset
  1044
        public MethodType asMethodType() { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1045
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
            for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
                l.head.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
            restype.complete();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1050
            recvtype.complete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1051
            for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
                l.head.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1053
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
        public List<TypeVar> getTypeVariables() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
            return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
        public TypeSymbol asElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
            return TypeKind.EXECUTABLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
            return v.visitExecutable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
    public static class PackageType extends Type implements NoType {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1073
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
        PackageType(TypeSymbol tsym) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
            super(PACKAGE, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
            return v.visitPackageType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
06bc494ca11e Initial load
duke
parents:
diff changeset
  1083
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1084
            return tsym.getQualifiedName().toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1085
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1086
06bc494ca11e Initial load
duke
parents:
diff changeset
  1087
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
            return TypeKind.PACKAGE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1090
06bc494ca11e Initial load
duke
parents:
diff changeset
  1091
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1092
            return v.visitNoType(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1094
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1095
06bc494ca11e Initial load
duke
parents:
diff changeset
  1096
    public static class TypeVar extends Type implements TypeVariable {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1098
        /** The upper bound of this type variable; set from outside.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
         *  Must be nonempty once it is set.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
         *  For a bound, `bound' is the bound type itself.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
         *  Multiple bounds are expressed as a single class type which has the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
         *  individual bounds as superclass, respectively interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
         *  The class type then has as `tsym' a compiler generated class `c',
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
         *  which has a flag COMPOUND and whose owner is the type variable
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
         *  itself. Furthermore, the erasure_field of the class
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
         *  points to the first class or interface bound.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1107
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
        public Type bound = null;
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1109
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1110
        /** The lower bound of this type variable.
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1111
         *  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
  1112
         *  to syms.botType.
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1113
         *  Subtypes, such as CapturedType, may provide a different value.
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1114
         */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1115
        public Type lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1116
06bc494ca11e Initial load
duke
parents:
diff changeset
  1117
        public TypeVar(Name name, Symbol owner, Type lower) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1118
            super(TYPEVAR, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1119
            tsym = new TypeSymbol(0, name, this, owner);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1120
            this.lower = lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1121
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1122
06bc494ca11e Initial load
duke
parents:
diff changeset
  1123
        public TypeVar(TypeSymbol tsym, Type bound, Type lower) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1124
            super(TYPEVAR, tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
            this.bound = bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
            this.lower = lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1131
            return v.visitTypeVar(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1134
        @Override
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1135
        public Type getUpperBound() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1136
            if ((bound == null || bound.tag == NONE) && this != tsym.type)
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1137
                bound = tsym.type.getUpperBound();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1138
            return bound;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1139
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
        int rank_field = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1142
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1143
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1144
        public Type getLowerBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1145
            return lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1146
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
            return TypeKind.TYPEVAR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1150
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
938
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1152
        public boolean isCaptured() {
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1153
            return false;
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1154
        }
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1155
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
            return v.visitTypeVariable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1158
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
    /** A captured type variable comes from wildcards which can have
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
     *  both upper and lower bound.  CapturedType extends TypeVar with
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
     *  a lower bound.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1164
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1165
    public static class CapturedType extends TypeVar {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1166
06bc494ca11e Initial load
duke
parents:
diff changeset
  1167
        public WildcardType wildcard;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1168
06bc494ca11e Initial load
duke
parents:
diff changeset
  1169
        public CapturedType(Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1170
                            Symbol owner,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1171
                            Type upper,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1172
                            Type lower,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1173
                            WildcardType wildcard) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1174
            super(name, owner, lower);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
  1175
            this.lower = Assert.checkNonNull(lower);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1176
            this.bound = upper;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1177
            this.wildcard = wildcard;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1178
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1179
06bc494ca11e Initial load
duke
parents:
diff changeset
  1180
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1181
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1182
            return v.visitCapturedType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1183
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1184
06bc494ca11e Initial load
duke
parents:
diff changeset
  1185
        @Override
938
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1186
        public boolean isCaptured() {
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1187
            return true;
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1188
        }
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1189
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1190
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1191
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1192
            return "capture#"
2984
e15ff3a34054 6722234: javac diagnostics need better integration with the type-system
mcimadamore
parents: 1527
diff changeset
  1193
                + (hashCode() & 0xFFFFFFFFL) % Printer.PRIME
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1194
                + " of "
06bc494ca11e Initial load
duke
parents:
diff changeset
  1195
                + wildcard;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1196
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1197
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1198
06bc494ca11e Initial load
duke
parents:
diff changeset
  1199
    public static abstract class DelegatedType extends Type {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1200
        public Type qtype;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
  1201
        public DelegatedType(TypeTag tag, Type qtype) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1202
            super(tag, qtype.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1203
            this.qtype = qtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1204
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1205
        public String toString() { return qtype.toString(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1206
        public List<Type> getTypeArguments() { return qtype.getTypeArguments(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1207
        public Type getEnclosingType() { return qtype.getEnclosingType(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1208
        public List<Type> getParameterTypes() { return qtype.getParameterTypes(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1209
        public Type getReturnType() { return qtype.getReturnType(); }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1210
        public Type getReceiverType() { return qtype.getReceiverType(); }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1211
        public List<Type> getThrownTypes() { return qtype.getThrownTypes(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1212
        public List<Type> allparams() { return qtype.allparams(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1213
        public Type getUpperBound() { return qtype.getUpperBound(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1214
        public boolean isErroneous() { return qtype.isErroneous(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1215
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1216
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1217
    /**
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1218
     * 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
  1219
     * 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
  1220
     * type.
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1221
     */
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8044
diff changeset
  1222
    public static class ForAll extends DelegatedType implements ExecutableType {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1223
        public List<Type> tvars;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1224
06bc494ca11e Initial load
duke
parents:
diff changeset
  1225
        public ForAll(List<Type> tvars, Type qtype) {
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1226
            super(FORALL, (MethodType)qtype);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1227
            this.tvars = tvars;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1228
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1229
06bc494ca11e Initial load
duke
parents:
diff changeset
  1230
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1231
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1232
            return v.visitForAll(this, s);
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 String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1236
            return "<" + tvars + ">" + qtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1237
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1238
06bc494ca11e Initial load
duke
parents:
diff changeset
  1239
        public List<Type> getTypeArguments()   { return tvars; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1240
06bc494ca11e Initial load
duke
parents:
diff changeset
  1241
        public boolean isErroneous()  {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1242
            return qtype.isErroneous();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1243
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1244
06bc494ca11e Initial load
duke
parents:
diff changeset
  1245
        public Type map(Mapping f) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1246
            return f.apply(qtype);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1247
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1248
06bc494ca11e Initial load
duke
parents:
diff changeset
  1249
        public boolean contains(Type elem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1250
            return qtype.contains(elem);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1251
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1252
06bc494ca11e Initial load
duke
parents:
diff changeset
  1253
        public MethodType asMethodType() {
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1254
            return (MethodType)qtype;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1255
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1256
06bc494ca11e Initial load
duke
parents:
diff changeset
  1257
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1258
            for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1259
                ((TypeVar)l.head).bound.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1260
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1261
            qtype.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1262
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1263
06bc494ca11e Initial load
duke
parents:
diff changeset
  1264
        public List<TypeVar> getTypeVariables() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1265
            return List.convert(TypeVar.class, getTypeArguments());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1266
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1267
06bc494ca11e Initial load
duke
parents:
diff changeset
  1268
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1269
            return TypeKind.EXECUTABLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1270
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1271
06bc494ca11e Initial load
duke
parents:
diff changeset
  1272
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1273
            return v.visitExecutable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1274
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1275
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1276
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1277
    /** 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
  1278
     *  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
  1279
     *  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
  1280
     *  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
  1281
     *  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
  1282
     *  whenever the bounds of an inference variable change.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1283
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1284
    public static class UndetVar extends DelegatedType {
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1285
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1286
        /** 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
  1287
         *  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
  1288
         */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1289
        public interface UndetVarListener {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1290
            /** 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
  1291
            void varChanged(UndetVar uv, Set<InferenceBound> ibs);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1292
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1293
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1294
        /**
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1295
         * Inference variable bound kinds
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1296
         */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1297
        public enum InferenceBound {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1298
            /** upper bounds */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1299
            UPPER,
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1300
            /** lower bounds */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1301
            LOWER,
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1302
            /** equality constraints */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1303
            EQ;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1304
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1305
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1306
        /** inference variable bounds */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1307
        private Map<InferenceBound, List<Type>> bounds;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1308
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1309
        /** inference variable's inferred type (set from Infer.java) */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1310
        public Type inst = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1311
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1312
        /** number of declared (upper) bounds */
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1313
        public int declaredCount;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1314
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1315
        /** inference variable's change listener */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1316
        public UndetVarListener listener = null;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1317
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1318
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1319
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1320
            return v.visitUndetVar(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1321
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1323
        public UndetVar(TypeVar origin, Types types) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
            super(UNDETVAR, origin);
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1325
            bounds = new EnumMap<InferenceBound, List<Type>>(InferenceBound.class);
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1326
            List<Type> declaredBounds = types.getBounds(origin);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1327
            declaredCount = declaredBounds.length();
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1328
            bounds.put(InferenceBound.UPPER, declaredBounds);
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1329
            bounds.put(InferenceBound.LOWER, List.<Type>nil());
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1330
            bounds.put(InferenceBound.EQ, List.<Type>nil());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1331
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1332
06bc494ca11e Initial load
duke
parents:
diff changeset
  1333
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1334
            if (inst != null) return inst.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1335
            else return qtype + "?";
06bc494ca11e Initial load
duke
parents:
diff changeset
  1336
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1337
06bc494ca11e Initial load
duke
parents:
diff changeset
  1338
        public Type baseType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1339
            if (inst != null) return inst.baseType();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1340
            else return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1341
        }
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1342
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1343
        /** get all bounds of a given kind */
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1344
        public List<Type> getBounds(InferenceBound... ibs) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1345
            ListBuffer<Type> buf = ListBuffer.lb();
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1346
            for (InferenceBound ib : ibs) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1347
                buf.appendList(bounds.get(ib));
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1348
            }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1349
            return buf.toList();
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1350
        }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1351
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1352
        /** get the list of declared (upper) bounds */
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1353
        public List<Type> getDeclaredBounds() {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1354
            ListBuffer<Type> buf = ListBuffer.lb();
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1355
            int count = 0;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1356
            for (Type b : getBounds(InferenceBound.UPPER)) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1357
                if (count++ == declaredCount) break;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1358
                buf.append(b);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1359
            }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1360
            return buf.toList();
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1361
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1362
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1363
        /** 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
  1364
        public void addBound(InferenceBound ib, Type bound, Types types) {
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1365
            Type bound2 = toTypeVarMap.apply(bound);
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1366
            List<Type> prevBounds = bounds.get(ib);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1367
            for (Type b : prevBounds) {
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1368
                //check for redundancy - use strict version of isSameType on tvars
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1369
                //(as the standard version will lead to false positives w.r.t. clones ivars)
16341
cc4b4e3c0f12 8009545: Graph inference: dependencies between inference variables should be set during incorporation
mcimadamore
parents: 15705
diff changeset
  1370
                if (types.isSameType(b, bound2, true) || bound == qtype) return;
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1371
            }
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1372
            bounds.put(ib, prevBounds.prepend(bound2));
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1373
            notifyChange(EnumSet.of(ib));
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1374
        }
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1375
        //where
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1376
            Type.Mapping toTypeVarMap = new Mapping("toTypeVarMap") {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1377
                @Override
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1378
                public Type apply(Type t) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1379
                    if (t.hasTag(UNDETVAR)) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1380
                        UndetVar uv = (UndetVar)t;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1381
                        return uv.qtype;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1382
                    } else {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1383
                        return t.map(this);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1384
                    }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1385
                }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1386
            };
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1387
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1388
        /** 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
  1389
        public void substBounds(List<Type> from, List<Type> to, Types types) {
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1390
            List<Type> instVars = from.diff(to);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1391
            //if set of instantiated ivars is empty, there's nothing to do!
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1392
            if (instVars.isEmpty()) return;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1393
            final EnumSet<InferenceBound> boundsChanged = EnumSet.noneOf(InferenceBound.class);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1394
            UndetVarListener prevListener = listener;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1395
            try {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1396
                //setup new listener for keeping track of changed bounds
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1397
                listener = new UndetVarListener() {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1398
                    public void varChanged(UndetVar uv, Set<InferenceBound> ibs) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1399
                        boundsChanged.addAll(ibs);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1400
                    }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1401
                };
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1402
                for (Map.Entry<InferenceBound, List<Type>> _entry : bounds.entrySet()) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1403
                    InferenceBound ib = _entry.getKey();
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1404
                    List<Type> prevBounds = _entry.getValue();
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1405
                    ListBuffer<Type> newBounds = ListBuffer.lb();
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1406
                    ListBuffer<Type> deps = ListBuffer.lb();
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1407
                    //step 1 - re-add bounds that are not dependent on ivars
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1408
                    for (Type t : prevBounds) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1409
                        if (!t.containsAny(instVars)) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1410
                            newBounds.append(t);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1411
                        } else {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1412
                            deps.append(t);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1413
                        }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1414
                    }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1415
                    //step 2 - replace bounds
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1416
                    bounds.put(ib, newBounds.toList());
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1417
                    //step 3 - for each dependency, add new replaced bound
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1418
                    for (Type dep : deps) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1419
                        addBound(ib, types.subst(dep, from, to), types);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1420
                    }
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1421
                }
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1422
            } finally {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1423
                listener = prevListener;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1424
                if (!boundsChanged.isEmpty()) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1425
                    notifyChange(boundsChanged);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1426
                }
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1427
            }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1428
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1429
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1430
        private void notifyChange(EnumSet<InferenceBound> ibs) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1431
            if (listener != null) {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1432
                listener.varChanged(this, ibs);
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1433
            }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1434
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1435
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1436
06bc494ca11e Initial load
duke
parents:
diff changeset
  1437
    /** Represents VOID or NONE.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1438
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1439
    static class JCNoType extends Type implements NoType {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
  1440
        public JCNoType(TypeTag tag) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1441
            super(tag, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1442
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1443
06bc494ca11e Initial load
duke
parents:
diff changeset
  1444
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1445
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1446
            switch (tag) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1447
            case VOID:  return TypeKind.VOID;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1448
            case NONE:  return TypeKind.NONE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1449
            default:
06bc494ca11e Initial load
duke
parents:
diff changeset
  1450
                throw new AssertionError("Unexpected tag: " + tag);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1451
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1452
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1453
06bc494ca11e Initial load
duke
parents:
diff changeset
  1454
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1455
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1456
            return v.visitNoType(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1457
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1458
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1459
06bc494ca11e Initial load
duke
parents:
diff changeset
  1460
    static class BottomType extends Type implements NullType {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1461
        public BottomType() {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
  1462
            super(BOT, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1463
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1464
06bc494ca11e Initial load
duke
parents:
diff changeset
  1465
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1466
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1467
            return TypeKind.NULL;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1468
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1469
06bc494ca11e Initial load
duke
parents:
diff changeset
  1470
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1471
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1472
            return v.visitNull(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1473
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1474
06bc494ca11e Initial load
duke
parents:
diff changeset
  1475
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1476
        public Type constType(Object value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1477
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1478
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1479
06bc494ca11e Initial load
duke
parents:
diff changeset
  1480
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1481
        public String stringValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1482
            return "null";
06bc494ca11e Initial load
duke
parents:
diff changeset
  1483
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1484
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1485
06bc494ca11e Initial load
duke
parents:
diff changeset
  1486
    public static class ErrorType extends ClassType
06bc494ca11e Initial load
duke
parents:
diff changeset
  1487
            implements javax.lang.model.type.ErrorType {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1488
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
  1489
        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
  1490
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1491
        public ErrorType(Type originalType, TypeSymbol tsym) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1492
            super(noType, List.<Type>nil(), null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1493
            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
  1494
            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
  1495
            this.originalType = (originalType == null ? noType : originalType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1496
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1497
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
  1498
        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
  1499
            this(originalType, c);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1500
            c.type = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1501
            c.kind = ERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1502
            c.members_field = new Scope.ErrorScope(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1503
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1504
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
  1505
        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
  1506
            this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1507
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1508
06bc494ca11e Initial load
duke
parents:
diff changeset
  1509
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1510
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1511
            return v.visitErrorType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1512
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1513
06bc494ca11e Initial load
duke
parents:
diff changeset
  1514
        public Type constType(Object constValue) { return this; }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1515
        public Type getEnclosingType()           { return this; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1516
        public Type getReturnType()              { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1517
        public Type asSub(Symbol sym)            { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1518
        public Type map(Mapping f)               { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1519
06bc494ca11e Initial load
duke
parents:
diff changeset
  1520
        public boolean isGenType(Type t)         { return true; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1521
        public boolean isErroneous()             { return true; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1522
        public boolean isCompound()              { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1523
        public boolean isInterface()             { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1524
06bc494ca11e Initial load
duke
parents:
diff changeset
  1525
        public List<Type> allparams()            { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1526
        public List<Type> getTypeArguments()     { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1527
06bc494ca11e Initial load
duke
parents:
diff changeset
  1528
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1529
            return TypeKind.ERROR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1530
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1531
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
  1532
        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
  1533
            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
  1534
        }
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  1535
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1536
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1537
            return v.visitError(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1538
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1539
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1540
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1541
    public static class AnnotatedType extends Type
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1542
            implements javax.lang.model.type.AnnotatedType {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1543
        /** The type annotations on this type.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1544
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1545
        public List<Attribute.TypeCompound> typeAnnotations;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1546
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1547
        /** The underlying type that is annotated.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1548
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1549
        public Type underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1550
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1551
        public AnnotatedType(Type underlyingType) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1552
            super(underlyingType.tag, underlyingType.tsym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1553
            this.typeAnnotations = List.nil();
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1554
            this.underlyingType = underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1555
            Assert.check(underlyingType.getKind() != TypeKind.ANNOTATED,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1556
                    "Can't annotate already annotated type: " + underlyingType);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1557
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1558
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1559
        public AnnotatedType(List<Attribute.TypeCompound> typeAnnotations,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1560
                Type underlyingType) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1561
            super(underlyingType.tag, underlyingType.tsym);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1562
            this.typeAnnotations = typeAnnotations;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1563
            this.underlyingType = underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1564
            Assert.check(underlyingType.getKind() != TypeKind.ANNOTATED,
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1565
                    "Can't annotate already annotated type: " + underlyingType +
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1566
                    "; adding: " + typeAnnotations);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1567
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1568
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1569
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1570
        public TypeKind getKind() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1571
            return TypeKind.ANNOTATED;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1572
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1573
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1574
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1575
        public List<? extends AnnotationMirror> getAnnotations() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1576
            return typeAnnotations;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1577
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1578
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1579
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1580
        public TypeMirror getUnderlyingType() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1581
            return underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1582
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1583
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1584
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1585
        public Type unannotatedType() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1586
            return underlyingType;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1587
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1588
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1589
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1590
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1591
            return v.visitAnnotatedType(this, s);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1592
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1593
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1594
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1595
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1596
            return v.visitAnnotated(this, p);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1597
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1598
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1599
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1600
        public Type map(Mapping f) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1601
            underlyingType.map(f);
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1602
            return this;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1603
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1604
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1605
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1606
        public Type constType(Object constValue) { return underlyingType.constType(constValue); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1607
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1608
        public Type getEnclosingType()           { return underlyingType.getEnclosingType(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1609
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1610
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1611
        public Type getReturnType()              { return underlyingType.getReturnType(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1612
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1613
        public List<Type> getTypeArguments()     { return underlyingType.getTypeArguments(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1614
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1615
        public List<Type> getParameterTypes()    { return underlyingType.getParameterTypes(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1616
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1617
        public Type getReceiverType()            { return underlyingType.getReceiverType(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1618
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1619
        public List<Type> getThrownTypes()       { return underlyingType.getThrownTypes(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1620
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1621
        public Type getUpperBound()              { return underlyingType.getUpperBound(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1622
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1623
        public Type getLowerBound()              { return underlyingType.getLowerBound(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1624
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1625
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1626
        public boolean isErroneous()             { return underlyingType.isErroneous(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1627
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1628
        public boolean isCompound()              { return underlyingType.isCompound(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1629
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1630
        public boolean isInterface()             { return underlyingType.isInterface(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1631
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1632
        public List<Type> allparams()            { return underlyingType.allparams(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1633
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1634
        public boolean isNumeric()               { return underlyingType.isNumeric(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1635
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1636
        public boolean isReference()             { return underlyingType.isReference(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1637
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1638
        public boolean isParameterized()         { return underlyingType.isParameterized(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1639
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1640
        public boolean isRaw()                   { return underlyingType.isRaw(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1641
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1642
        public boolean isFinal()                 { return underlyingType.isFinal(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1643
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1644
        public boolean isSuperBound()            { return underlyingType.isSuperBound(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1645
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1646
        public boolean isExtendsBound()          { return underlyingType.isExtendsBound(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1647
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1648
        public boolean isUnbound()               { return underlyingType.isUnbound(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1649
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1650
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1651
        public String toString() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1652
            // TODO more logic for arrays, etc.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1653
            if (typeAnnotations != null &&
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1654
                    !typeAnnotations.isEmpty()) {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1655
                return "(" + typeAnnotations.toString() + " :: " + underlyingType.toString() + ")";
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1656
            } else {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1657
                return "({} :: " + underlyingType.toString() +")";
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1658
            }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1659
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1660
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1661
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1662
        public boolean contains(Type t)          { return underlyingType.contains(t); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1663
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1664
        // TODO: attach annotations?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1665
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1666
        public Type withTypeVar(Type t)          { return underlyingType.withTypeVar(t); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1667
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1668
        // TODO: attach annotations?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1669
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1670
        public TypeSymbol asElement()            { return underlyingType.asElement(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1671
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1672
        // TODO: attach annotations?
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1673
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1674
        public MethodType asMethodType()         { return underlyingType.asMethodType(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1675
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1676
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1677
        public void complete()                   { underlyingType.complete(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1678
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1679
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1680
        public TypeMirror getComponentType()     { return ((ArrayType)underlyingType).getComponentType(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1681
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1682
        // The result is an ArrayType, but only in the model sense, not the Type sense.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1683
        public AnnotatedType makeVarargs() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1684
            AnnotatedType atype = new AnnotatedType(((ArrayType)underlyingType).makeVarargs());
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1685
            atype.typeAnnotations = this.typeAnnotations;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1686
            return atype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1687
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1688
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1689
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1690
        public TypeMirror getExtendsBound()      { return ((WildcardType)underlyingType).getExtendsBound(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1691
        @Override
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1692
        public TypeMirror getSuperBound()        { return ((WildcardType)underlyingType).getSuperBound(); }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1693
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1694
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1695
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  1696
     * A visitor for types.  A visitor is used to implement operations
06bc494ca11e Initial load
duke
parents:
diff changeset
  1697
     * (or relations) on types.  Most common operations on types are
06bc494ca11e Initial load
duke
parents:
diff changeset
  1698
     * binary relations and this interface is designed for binary
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1699
     * relations, that is, operations of the form
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1700
     * Type&nbsp;&times;&nbsp;S&nbsp;&rarr;&nbsp;R.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
     * <!-- In plain text: Type x S -> R -->
06bc494ca11e Initial load
duke
parents:
diff changeset
  1702
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1703
     * @param <R> the return type of the operation implemented by this
06bc494ca11e Initial load
duke
parents:
diff changeset
  1704
     * visitor; use Void if no return type is needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1705
     * @param <S> the type of the second argument (the first being the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1706
     * type itself) of the operation implemented by this visitor; use
06bc494ca11e Initial load
duke
parents:
diff changeset
  1707
     * Void if a second argument is not needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1708
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1709
    public interface Visitor<R,S> {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1710
        R visitClassType(ClassType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1711
        R visitWildcardType(WildcardType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1712
        R visitArrayType(ArrayType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1713
        R visitMethodType(MethodType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1714
        R visitPackageType(PackageType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1715
        R visitTypeVar(TypeVar t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1716
        R visitCapturedType(CapturedType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1717
        R visitForAll(ForAll t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1718
        R visitUndetVar(UndetVar t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1719
        R visitErrorType(ErrorType t, S s);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1720
        R visitAnnotatedType(AnnotatedType t, S s);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1721
        R visitType(Type t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1722
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1723
}