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