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