langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java
author mcimadamore
Fri, 16 Dec 2016 15:27:47 +0000
changeset 42828 cce89649f958
parent 42827 36468b5fa7f4
child 44186 fe848a208b20
permissions -rw-r--r--
8171371: Remove redundant type-arguments from generic method calls Reviewed-by: jjg, rfield, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 37003
diff changeset
     2
 * Copyright (c) 1999, 2016, 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;
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
    29
import java.util.ArrayDeque;
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
    30
import java.util.Collections;
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
    31
import java.util.EnumMap;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
    32
import java.util.Map;
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
    33
import java.util.function.Function;
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.*;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
    38
import com.sun.tools.javac.code.TypeMetadata.Entry;
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
    39
import com.sun.tools.javac.comp.Infer.IncorporationAction;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14058
diff changeset
    40
import com.sun.tools.javac.util.*;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    41
import com.sun.tools.javac.util.DefinedBy.Api;
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
    42
14052
8b839ae9074b 8000233: Fix issues in recent push
mcimadamore
parents: 14048
diff changeset
    43
import static com.sun.tools.javac.code.BoundKind.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
import static com.sun.tools.javac.code.Flags.*;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
    45
import static com.sun.tools.javac.code.Kinds.Kind.*;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    46
import static com.sun.tools.javac.code.TypeTag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
/** This class represents Java types. The class itself defines the behavior of
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 *  the following types:
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 *  base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN),
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *  type `void' (tag: VOID),
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *  the bottom type (tag: BOT),
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *  the missing type (tag: NONE).
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *  <p>The behavior of the following types is defined in subclasses, which are
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *  all static inner classes of this class:
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *  <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *  class types (tag: CLASS, class: ClassType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 *  array types (tag: ARRAY, class: ArrayType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *  method types (tag: METHOD, class: MethodType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *  package types (tag: PACKAGE, class: PackageType),
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *  type variables (tag: TYPEVAR, class: TypeVar),
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *  type arguments (tag: WILDCARD, class: WildcardType),
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
    65
 *  generic method types (tag: FORALL, class: ForAll),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 *  the error type (tag: ERROR, class: ErrorType).
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 *  </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    69
 *  <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
    70
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 *
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    74
 *  @see TypeTag
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 */
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20606
diff changeset
    76
public abstract class Type extends AnnoConstruct implements TypeMirror {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    78
    /**
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    79
     * Type metadata,  Should be {@code null} for the default value.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    80
     *
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    81
     * Note: it is an invariant that for any {@code TypeMetadata}
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    82
     * class, a given {@code Type} may have at most one metadata array
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    83
     * entry of that class.
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    84
     */
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    85
    protected final TypeMetadata metadata;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    86
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    87
    public TypeMetadata getMetadata() {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    88
        return metadata;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    89
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    90
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
    91
    public Entry getMetadataOfKind(final Entry.Kind kind) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    92
        return metadata != null ? metadata.get(kind) : null;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    93
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
    94
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
    /** Constant type: no type at all. */
24794
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
    96
    public static final JCNoType noType = new JCNoType() {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    97
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
24794
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
    98
        public String toString() {
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
    99
            return "none";
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   100
        }
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   101
    };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14052
diff changeset
   103
    /** Constant type: special type to be used during recovery of deferred expressions. */
24794
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   104
    public static final JCNoType recoveryType = new JCNoType(){
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   105
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
24794
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   106
        public String toString() {
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   107
            return "recovery";
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   108
        }
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   109
    };
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14052
diff changeset
   110
18902
972298345a83 8016059: Cannot compile following lambda
mcimadamore
parents: 18646
diff changeset
   111
    /** Constant type: special type to be used for marking stuck trees. */
24794
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   112
    public static final JCNoType stuckType = new JCNoType() {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   113
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
24794
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   114
        public String toString() {
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   115
            return "stuck";
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   116
        }
22946bb4c27d 8041713: Type inference of non-existent method references crashes the compiler
vromero
parents: 24396
diff changeset
   117
    };
18902
972298345a83 8016059: Cannot compile following lambda
mcimadamore
parents: 18646
diff changeset
   118
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    /** If this switch is turned on, the names of type variables
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     *  and anonymous classes are printed with hashcodes appended.
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    public static boolean moreInfo = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   124
    /** The defining class / interface / package / type variable.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    public TypeSymbol tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    /**
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   129
     * 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
   130
     * @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
   131
     */
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   132
    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
   133
        return tag == getTag();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   134
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   135
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   136
    /**
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   137
     * Returns the current type tag.
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   138
     * @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
   139
     */
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   140
    public abstract TypeTag getTag();
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   141
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   142
    public boolean isNumeric() {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   143
        return false;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   144
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   145
33018
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   146
    public boolean isIntegral() {
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   147
        return false;
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   148
    }
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   149
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   150
    public boolean isPrimitive() {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   151
        return false;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   152
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   153
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   154
    public boolean isPrimitiveOrVoid() {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   155
        return false;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   156
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   157
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   158
    public boolean isReference() {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   159
        return false;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   160
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   161
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   162
    public boolean isNullOrReference() {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   163
        return false;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   164
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   165
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   166
    public boolean isPartial() {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   167
        return false;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   168
    }
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   169
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
   170
    /**
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * The constant value of this type, null if this type does not
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * have a constant value attribute. Only primitive types and
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * strings (ClassType) can have a constant value attribute.
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * @return the constant value attribute of this type
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    public Object constValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   180
    /** 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
   181
     */
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   182
    public boolean isFalse() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   183
        return false;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   184
    }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   185
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   186
    /** 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
   187
     */
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   188
    public boolean isTrue() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   189
        return false;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   190
    }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   191
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   192
    /**
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   193
     * Get the representation of this type used for modelling purposes.
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   194
     * By default, this is itself. For ErrorType, a different value
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   195
     * may be provided.
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   196
     */
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   197
    public Type getModelType() {
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   198
        return this;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   199
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   200
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   201
    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
   202
        ListBuffer<Type> lb = new ListBuffer<>();
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   203
        for (Type t: ts)
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   204
            lb.append(t.getModelType());
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   205
        return lb.toList();
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   206
    }
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   207
21015
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 21007
diff changeset
   208
    /**For ErrorType, returns the original type, otherwise returns the type itself.
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 21007
diff changeset
   209
     */
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 21007
diff changeset
   210
    public Type getOriginalType() {
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 21007
diff changeset
   211
        return this;
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 21007
diff changeset
   212
    }
f3bec12a63e7 6278240: Exception from AnnotationValue.getValue() should list the found type not the required type
jlahoda
parents: 21007
diff changeset
   213
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   216
    /** Define a type given its tag, type symbol, and type annotations
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     */
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   218
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   219
    public Type(TypeSymbol tsym, TypeMetadata metadata) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   220
        Assert.checkNonNull(metadata);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
        this.tsym = tsym;
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   222
        this.metadata = metadata;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    /** An abstract class for mappings from types to types
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     */
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   227
    public static abstract class TypeMapping<S> extends Types.MapVisitor<S> implements Function<Type, Type> {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   228
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   229
        @Override
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   230
        public Type apply(Type type) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   231
            return visit(type);
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   232
        }
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   233
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   234
        List<Type> visit(List<Type> ts, S s) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   235
            return ts.map(t -> visit(t, s));
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   236
        }
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   237
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   238
        @Override
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   239
        public Type visitClassType(ClassType t, S s) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   240
            Type outer = t.getEnclosingType();
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   241
            Type outer1 = visit(outer, s);
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   242
            List<Type> typarams = t.getTypeArguments();
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   243
            List<Type> typarams1 = visit(typarams, s);
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   244
            if (outer1 == outer && typarams1 == typarams) return t;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   245
            else return new ClassType(outer1, typarams1, t.tsym, t.metadata) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   246
                @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   247
                protected boolean needsStripping() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   248
                    return true;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   249
                }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   250
            };
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   251
        }
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   252
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   253
        @Override
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   254
        public Type visitWildcardType(WildcardType wt, S s) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   255
            Type t = wt.type;
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   256
            if (t != null)
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   257
                t = visit(t, s);
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   258
            if (t == wt.type)
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   259
                return wt;
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   260
            else
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   261
                return new WildcardType(t, wt.kind, wt.tsym, wt.bound, wt.metadata) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   262
                    @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   263
                    protected boolean needsStripping() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   264
                        return true;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   265
                    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   266
                };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        }
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   268
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   269
        @Override
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   270
        public Type visitArrayType(ArrayType t, S s) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   271
            Type elemtype = t.elemtype;
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   272
            Type elemtype1 = visit(elemtype, s);
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   273
            if (elemtype1 == elemtype) return t;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   274
            else return new ArrayType(elemtype1, t.tsym, t.metadata) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   275
                @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   276
                protected boolean needsStripping() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   277
                    return true;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   278
                }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   279
            };
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   280
        }
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   281
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   282
        @Override
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   283
        public Type visitMethodType(MethodType t, S s) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   284
            List<Type> argtypes = t.argtypes;
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   285
            Type restype = t.restype;
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   286
            List<Type> thrown = t.thrown;
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   287
            List<Type> argtypes1 = visit(argtypes, s);
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   288
            Type restype1 = visit(restype, s);
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   289
            List<Type> thrown1 = visit(thrown, s);
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   290
            if (argtypes1 == argtypes &&
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   291
                restype1 == restype &&
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   292
                thrown1 == thrown) return t;
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   293
            else return new MethodType(argtypes1, restype1, thrown1, t.tsym) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   294
                @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   295
                protected boolean needsStripping() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   296
                    return true;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   297
                }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   298
            };
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   299
        }
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   300
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   301
        @Override
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   302
        public Type visitCapturedType(CapturedType t, S s) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   303
            return visitTypeVar(t, s);
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   304
        }
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   305
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   306
        @Override
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   307
        public Type visitForAll(ForAll t, S s) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   308
            return visit(t.qtype, s);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
    /** map a type function over all immediate descendants of this type
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
     */
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   314
    public <Z> Type map(TypeMapping<Z> mapping, Z arg) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   315
        return mapping.visit(this, arg);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   318
    /** map a type function over all immediate descendants of this type (no arg version)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
     */
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   320
    public <Z> Type map(TypeMapping<Z> mapping) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   321
        return mapping.visit(this, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
    /** Define a constant type, of the same kind as this type
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
     *  and with given constant value
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
    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
   328
        throw new AssertionError();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
     * If this is a constant type, return its underlying type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
     * Otherwise, return the type itself.
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
    public Type baseType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   339
    /**
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   340
     * Returns the original version of this type, before metadata were added. This routine is meant
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   341
     * for internal use only (i.e. {@link Type#equalsIgnoreMetadata(Type)}, {@link Type#stripMetadata});
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   342
     * it should not be used outside this class.
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   343
     */
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   344
    protected Type typeNoMetadata() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   345
        return metadata == TypeMetadata.EMPTY ? this : baseType();
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   346
    }
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   347
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   348
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   349
     * Create a new copy of this type but with the specified TypeMetadata.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   350
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   351
    public abstract Type cloneWithMetadata(TypeMetadata metadata);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   352
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   353
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   354
     * Does this type require annotation stripping for API clients?
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   355
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   356
    protected boolean needsStripping() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   357
        return false;
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   358
    }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   359
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   360
    /**
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   361
     * Strip all metadata associated with this type - this could return a new clone of the type.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   362
     * This routine is only used to present the correct annotated types back to the users when types
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   363
     * are accessed through compiler APIs; it should not be used anywhere in the compiler internals
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   364
     * as doing so might result in performance penalties.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   365
     */
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   366
    public Type stripMetadataIfNeeded() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   367
        return needsStripping() ?
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   368
                accept(stripMetadata, null) :
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   369
                this;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   370
    }
35348
95a9b9409b50 8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents: 33917
diff changeset
   371
95a9b9409b50 8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents: 33917
diff changeset
   372
    public Type stripMetadata() {
95a9b9409b50 8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents: 33917
diff changeset
   373
        return accept(stripMetadata, null);
95a9b9409b50 8144580: java.lang.AssertionError: Missing type variable in where clause: T
sadayapalam
parents: 33917
diff changeset
   374
    }
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   375
    //where
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   376
        private final static TypeMapping<Void> stripMetadata = new TypeMapping<Void>() {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   377
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   378
            public Type visitClassType(ClassType t, Void aVoid) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   379
                return super.visitClassType((ClassType)t.typeNoMetadata(), aVoid);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   380
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   381
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   382
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   383
            public Type visitArrayType(ArrayType t, Void aVoid) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   384
                return super.visitArrayType((ArrayType)t.typeNoMetadata(), aVoid);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   385
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   386
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   387
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   388
            public Type visitTypeVar(TypeVar t, Void aVoid) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   389
                return super.visitTypeVar((TypeVar)t.typeNoMetadata(), aVoid);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   390
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   391
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   392
            @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   393
            public Type visitWildcardType(WildcardType wt, Void aVoid) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   394
                return super.visitWildcardType((WildcardType)wt.typeNoMetadata(), aVoid);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   395
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   396
        };
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   397
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   398
    public Type annotatedType(final List<Attribute.TypeCompound> annos) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   399
        final Entry annoMetadata = new TypeMetadata.Annotations(annos);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   400
        return cloneWithMetadata(metadata.combine(annoMetadata));
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   401
    }
21041
99f5e5e97425 8026564: import changes from type-annotations forest
jjg
parents: 21015
diff changeset
   402
16556
f4adc5bb4652 8008425: Remove interim new javax.lang.model API for type-annotations
jjg
parents: 16341
diff changeset
   403
    public boolean isAnnotated() {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   404
        final TypeMetadata.Annotations metadata =
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   405
            (TypeMetadata.Annotations)getMetadataOfKind(Entry.Kind.ANNOTATIONS);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   406
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   407
        return null != metadata && !metadata.getAnnotations().isEmpty();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   408
    }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   409
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   410
    @Override @DefinedBy(Api.LANGUAGE_MODEL)
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20606
diff changeset
   411
    public List<Attribute.TypeCompound> getAnnotationMirrors() {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   412
        final TypeMetadata.Annotations metadata =
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   413
            (TypeMetadata.Annotations)getMetadataOfKind(Entry.Kind.ANNOTATIONS);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   414
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   415
        return metadata == null ? List.nil() : metadata.getAnnotations();
16557
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   416
    }
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   417
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20606
diff changeset
   418
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   419
    @Override @DefinedBy(Api.LANGUAGE_MODEL)
16557
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   420
    public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   421
        return null;
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   422
    }
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   423
21007
484c9d902861 8021237: clean up JavacAnnotatedConstruct
alundblad
parents: 20606
diff changeset
   424
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   425
    @Override @DefinedBy(Api.LANGUAGE_MODEL)
16557
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   426
    public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   427
        @SuppressWarnings("unchecked")
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   428
        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
   429
        return tmp;
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   430
    }
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   431
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
    /** Return the base types of a list of types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
    public static List<Type> baseTypes(List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
        if (ts.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
            Type t = ts.head.baseType();
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
            List<Type> baseTypes = baseTypes(ts.tail);
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
            if (t != ts.head || baseTypes != ts.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
                return baseTypes.prepend(t);
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        return ts;
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   443
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   444
    protected void appendAnnotationsString(StringBuilder sb,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   445
                                         boolean prefix) {
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   446
        if (isAnnotated()) {
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   447
            if (prefix) {
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   448
                sb.append(" ");
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   449
            }
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   450
            sb.append(getAnnotationMirrors());
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   451
            sb.append(" ");
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   452
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   453
    }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   454
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   455
    protected void appendAnnotationsString(StringBuilder sb) {
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   456
        appendAnnotationsString(sb, false);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   457
    }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   458
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
    /** The Java source which this type represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
     */
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   461
    @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
    public String toString() {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   463
        StringBuilder sb = new StringBuilder();
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   464
        appendAnnotationsString(sb);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   465
        if (tsym == null || tsym.name == null) {
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   466
            sb.append("<none>");
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   467
        } else {
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   468
            sb.append(tsym.name);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   469
        }
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   470
        if (moreInfo && hasTag(TYPEVAR)) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   471
            sb.append(hashCode());
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   472
        }
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   473
        return sb.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
     * The Java source which this type list represents.  A List is
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
     * represented as a comma-spearated listing of the elements in
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
     * that list.
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
    public static String toString(List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
        if (ts.isEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
            return "";
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        } else {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   485
            StringBuilder buf = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
            buf.append(ts.head.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
            for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
                buf.append(",").append(l.head.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
            return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
     * The constant value of this type, converted to String
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
    public String stringValue() {
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   497
        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
   498
        return cv.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
    /**
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   502
     * Override this method with care. For most Type instances this should behave as ==.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
     */
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   504
    @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
    public boolean equals(Object t) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   506
        return this == t;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   507
    }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   508
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   509
    public boolean equalsIgnoreMetadata(Type t) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   510
        return typeNoMetadata().equals(t.typeNoMetadata());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   513
    @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
    public int hashCode() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
        return super.hashCode();
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
    public String argtypes(boolean varargs) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
        List<Type> args = getParameterTypes();
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        if (!varargs) return args.toString();
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
   521
        StringBuilder buf = new StringBuilder();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
        while (args.tail.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
            buf.append(args.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
            args = args.tail;
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
            buf.append(',');
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
        }
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   527
        if (args.head.hasTag(ARRAY)) {
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   528
            buf.append(((ArrayType)args.head).elemtype);
16557
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   529
            if (args.head.getAnnotationMirrors().nonEmpty()) {
67a3ae363f03 8007803: Implement javax.lang.model API for Type Annotations
jjg
parents: 16556
diff changeset
   530
                buf.append(args.head.getAnnotationMirrors());
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   531
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
            buf.append("...");
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
        } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
            buf.append(args.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
        return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
    /** Access methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
    public List<Type>        getTypeArguments()  { return List.nil(); }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   542
    public Type              getEnclosingType()  { return null; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
    public List<Type>        getParameterTypes() { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
    public Type              getReturnType()     { return null; }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   545
    public Type              getReceiverType()   { return null; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
    public List<Type>        getThrownTypes()    { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
    public Type              getUpperBound()     { return null; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
    public Type              getLowerBound()     { return null; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
    /** Navigation methods, these will work for classes, type variables,
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
     *  foralls, but will return null for arrays and methods.
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
   /** Return all parameters of this type and all its outer types in order
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
    *  outer (first) to inner (last).
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
    */
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
    public List<Type> allparams() { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
    /** Does this type contain "error" elements?
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
    public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
    public static boolean isErroneous(List<Type> ts) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
            if (l.head.isErroneous()) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
    /** Is this type parameterized?
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
     *  A class type is parameterized if it has some parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
     *  An array type is parameterized if its element type is parameterized.
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
     *  All other types are not parameterized.
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
    public boolean isParameterized() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
    /** Is this type a raw type?
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
     *  A class type is a raw type if it misses some of its parameters.
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
     *  An array type is a raw type if its element type is raw.
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
     *  All other types are not raw.
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
     *  Type validation will ensure that the only raw types
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
     *  in a program are types that miss all their type variables.
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
    public boolean isRaw() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
33556
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
   591
    /**
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
   592
     * A compound type is a special class type whose supertypes are used to store a list
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
   593
     * of component types. There are two kinds of compound types: (i) intersection types
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
   594
     * {@see IntersectionClassType} and (ii) union types {@see UnionClassType}.
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
   595
     */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
    public boolean isCompound() {
33556
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
   597
        return false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
29147
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
   600
    public boolean isIntersection() {
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
   601
        return false;
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
   602
    }
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
   603
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
   604
    public boolean isUnion() {
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
   605
        return false;
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
   606
    }
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
   607
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
    public boolean isInterface() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
        return (tsym.flags() & INTERFACE) != 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
6353
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   612
    public boolean isFinal() {
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   613
        return (tsym.flags() & FINAL) != 0;
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   614
    }
bb5c39054bf3 6932571: Compiling Generics causing Inconvertible types
mcimadamore
parents: 6348
diff changeset
   615
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
     * Does this type contain occurrences of type t?
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
    public boolean contains(Type t) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   620
        return t.equalsIgnoreMetadata(this);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
    public static boolean contains(List<Type> ts, Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
        for (List<Type> l = ts;
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
             l.tail != null /*inlined: l.nonEmpty()*/;
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
             l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
            if (l.head.contains(t)) return true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   631
    /** Does this type contain an occurrence of some type in 'ts'?
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
     */
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   633
    public boolean containsAny(List<Type> ts) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   634
        for (Type t : ts)
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   635
            if (this.contains(t)) return true;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   636
        return false;
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   637
    }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   638
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   639
    public static boolean containsAny(List<Type> ts1, List<Type> ts2) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   640
        for (Type t : ts1)
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   641
            if (t.containsAny(ts2)) return true;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   642
        return false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   643
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   644
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   645
    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
   646
        ListBuffer<Type> buf = new ListBuffer<>();
8044
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   647
        for (Type t : ts) {
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   648
            if (tf.accepts(t)) {
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   649
                buf.append(t);
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   650
            }
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   651
        }
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   652
        return buf.toList();
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   653
    }
7fd529d4472c 6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents: 8032
diff changeset
   654
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   655
    public boolean isSuperBound() { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   656
    public boolean isExtendsBound() { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   657
    public boolean isUnbound() { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   658
    public Type withTypeVar(Type t) { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
   659
06bc494ca11e Initial load
duke
parents:
diff changeset
   660
    /** The underlying method type of this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   661
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   662
    public MethodType asMethodType() { throw new AssertionError(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
   663
06bc494ca11e Initial load
duke
parents:
diff changeset
   664
    /** Complete loading all classes in this type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   665
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   666
    public void complete() {}
06bc494ca11e Initial load
duke
parents:
diff changeset
   667
06bc494ca11e Initial load
duke
parents:
diff changeset
   668
    public TypeSymbol asElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   669
        return tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   670
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   671
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   672
    @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   673
    public TypeKind getKind() {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   674
        return TypeKind.OTHER;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   675
    }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   676
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   677
    @Override @DefinedBy(Api.LANGUAGE_MODEL)
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   678
    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
   679
        throw new AssertionError();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   680
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   681
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   682
    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
   683
            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
   684
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   685
        TypeTag tag;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   686
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   687
        public JCPrimitiveType(TypeTag tag, TypeSymbol tsym) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   688
            this(tag, tsym, TypeMetadata.EMPTY);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   689
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   690
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   691
        private JCPrimitiveType(TypeTag tag, TypeSymbol tsym, TypeMetadata metadata) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   692
            super(tsym, metadata);
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   693
            this.tag = tag;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   694
            Assert.check(tag.isPrimitive);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   695
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   696
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   697
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   698
        public JCPrimitiveType cloneWithMetadata(TypeMetadata md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   699
            return new JCPrimitiveType(tag, tsym, md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   700
                @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   701
                public Type baseType() { return JCPrimitiveType.this.baseType(); }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   702
            };
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   703
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   704
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   705
        @Override
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   706
        public boolean isNumeric() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   707
            return tag != BOOLEAN;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   708
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   709
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   710
        @Override
33018
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   711
        public boolean isIntegral() {
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   712
            switch (tag) {
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   713
                case CHAR:
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   714
                case BYTE:
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   715
                case SHORT:
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   716
                case INT:
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   717
                case LONG:
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   718
                    return true;
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   719
                default:
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   720
                    return false;
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   721
            }
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   722
        }
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   723
9790ed482dd0 8138840: NPE when compiling bitwise operations with illegal operand types
mcimadamore
parents: 30066
diff changeset
   724
        @Override
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   725
        public boolean isPrimitive() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   726
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   727
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   728
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   729
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   730
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   731
            return tag;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   732
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   733
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   734
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   735
        public boolean isPrimitiveOrVoid() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   736
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   737
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   738
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   739
        /** 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
   740
         *  and with given constant value
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   741
         */
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   742
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   743
        public Type constType(Object constValue) {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   744
            final Object value = constValue;
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   745
            return new JCPrimitiveType(tag, tsym, metadata) {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   746
                    @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   747
                    public Object constValue() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   748
                        return value;
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
                    @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   751
                    public Type baseType() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   752
                        return tsym.type;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   753
                    }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   754
                };
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   755
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   756
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   757
        /**
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   758
         * 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
   759
         */
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   760
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   761
        public String stringValue() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   762
            Object cv = Assert.checkNonNull(constValue());
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   763
            if (tag == BOOLEAN) {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   764
                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
   765
            }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   766
            else if (tag == CHAR) {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   767
                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
   768
            }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   769
            else {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   770
                return cv.toString();
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   771
            }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   772
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   773
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   774
        /** 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
   775
         */
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   776
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   777
        public boolean isFalse() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   778
            return
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   779
                tag == BOOLEAN &&
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   780
                constValue() != null &&
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   781
                ((Integer)constValue()).intValue() == 0;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   782
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   783
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   784
        /** 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
   785
         */
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   786
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   787
        public boolean isTrue() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   788
            return
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   789
                tag == BOOLEAN &&
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   790
                constValue() != null &&
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   791
                ((Integer)constValue()).intValue() != 0;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   792
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   793
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   794
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   795
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   796
            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
   797
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   798
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   799
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   800
        public TypeKind getKind() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   801
            switch (tag) {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   802
                case BYTE:      return TypeKind.BYTE;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   803
                case CHAR:      return TypeKind.CHAR;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   804
                case SHORT:     return TypeKind.SHORT;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   805
                case INT:       return TypeKind.INT;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   806
                case LONG:      return TypeKind.LONG;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   807
                case FLOAT:     return TypeKind.FLOAT;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   808
                case DOUBLE:    return TypeKind.DOUBLE;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   809
                case BOOLEAN:   return TypeKind.BOOLEAN;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   810
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   811
            throw new AssertionError();
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   812
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   813
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   814
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   815
06bc494ca11e Initial load
duke
parents:
diff changeset
   816
    public static class WildcardType extends Type
06bc494ca11e Initial load
duke
parents:
diff changeset
   817
            implements javax.lang.model.type.WildcardType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   818
06bc494ca11e Initial load
duke
parents:
diff changeset
   819
        public Type type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   820
        public BoundKind kind;
06bc494ca11e Initial load
duke
parents:
diff changeset
   821
        public TypeVar bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
   822
06bc494ca11e Initial load
duke
parents:
diff changeset
   823
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   824
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   825
            return v.visitWildcardType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   826
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   827
06bc494ca11e Initial load
duke
parents:
diff changeset
   828
        public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   829
            this(type, kind, tsym, null, TypeMetadata.EMPTY);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   830
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   831
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   832
        public WildcardType(Type type, BoundKind kind, TypeSymbol tsym,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   833
                            TypeMetadata metadata) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   834
            this(type, kind, tsym, null, metadata);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   835
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   836
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   837
        public WildcardType(Type type, BoundKind kind, TypeSymbol tsym,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   838
                            TypeVar bound) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   839
            this(type, kind, tsym, bound, TypeMetadata.EMPTY);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   840
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   841
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   842
        public WildcardType(Type type, BoundKind kind, TypeSymbol tsym,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   843
                            TypeVar bound, TypeMetadata metadata) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   844
            super(tsym, metadata);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
   845
            this.type = Assert.checkNonNull(type);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   846
            this.kind = kind;
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   847
            this.bound = bound;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   848
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   849
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   850
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   851
        public WildcardType cloneWithMetadata(TypeMetadata md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   852
            return new WildcardType(type, kind, tsym, bound, md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   853
                @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   854
                public Type baseType() { return WildcardType.this.baseType(); }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   855
            };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   856
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   857
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   858
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   859
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   860
            return WILDCARD;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   861
        }
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
        @Override
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   864
        public boolean contains(Type t) {
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   865
            return kind != UNBOUND && type.contains(t);
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   866
        }
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
   867
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   868
        public boolean isSuperBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   869
            return kind == SUPER ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   870
                kind == UNBOUND;
06bc494ca11e Initial load
duke
parents:
diff changeset
   871
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   872
        public boolean isExtendsBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   873
            return kind == EXTENDS ||
06bc494ca11e Initial load
duke
parents:
diff changeset
   874
                kind == UNBOUND;
06bc494ca11e Initial load
duke
parents:
diff changeset
   875
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   876
        public boolean isUnbound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   877
            return kind == UNBOUND;
06bc494ca11e Initial load
duke
parents:
diff changeset
   878
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   879
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   880
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   881
        public boolean isReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   882
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   883
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   884
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   885
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   886
        public boolean isNullOrReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   887
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   888
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   889
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   890
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   891
        public Type withTypeVar(Type t) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   892
            //-System.err.println(this+".withTypeVar("+t+");");//DEBUG
06bc494ca11e Initial load
duke
parents:
diff changeset
   893
            if (bound == t)
06bc494ca11e Initial load
duke
parents:
diff changeset
   894
                return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   895
            bound = (TypeVar)t;
06bc494ca11e Initial load
duke
parents:
diff changeset
   896
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   897
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   898
06bc494ca11e Initial load
duke
parents:
diff changeset
   899
        boolean isPrintingBound = false;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   900
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   901
        public String toString() {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   902
            StringBuilder s = new StringBuilder();
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   903
            appendAnnotationsString(s);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   904
            s.append(kind.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
   905
            if (kind != UNBOUND)
06bc494ca11e Initial load
duke
parents:
diff changeset
   906
                s.append(type);
06bc494ca11e Initial load
duke
parents:
diff changeset
   907
            if (moreInfo && bound != null && !isPrintingBound)
06bc494ca11e Initial load
duke
parents:
diff changeset
   908
                try {
06bc494ca11e Initial load
duke
parents:
diff changeset
   909
                    isPrintingBound = true;
06bc494ca11e Initial load
duke
parents:
diff changeset
   910
                    s.append("{:").append(bound.bound).append(":}");
06bc494ca11e Initial load
duke
parents:
diff changeset
   911
                } finally {
06bc494ca11e Initial load
duke
parents:
diff changeset
   912
                    isPrintingBound = false;
06bc494ca11e Initial load
duke
parents:
diff changeset
   913
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   914
            return s.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
   915
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   916
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   917
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   918
        public Type getExtendsBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   919
            if (kind == EXTENDS)
06bc494ca11e Initial load
duke
parents:
diff changeset
   920
                return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   921
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   922
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   923
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   924
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   925
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   926
        public Type getSuperBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   927
            if (kind == SUPER)
06bc494ca11e Initial load
duke
parents:
diff changeset
   928
                return type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   929
            else
06bc494ca11e Initial load
duke
parents:
diff changeset
   930
                return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   931
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   932
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   933
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   934
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   935
            return TypeKind.WILDCARD;
06bc494ca11e Initial load
duke
parents:
diff changeset
   936
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   937
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   938
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   939
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   940
            return v.visitWildcard(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
   941
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   942
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   943
06bc494ca11e Initial load
duke
parents:
diff changeset
   944
    public static class ClassType extends Type implements DeclaredType {
06bc494ca11e Initial load
duke
parents:
diff changeset
   945
06bc494ca11e Initial load
duke
parents:
diff changeset
   946
        /** The enclosing type of this type. If this is the type of an inner
06bc494ca11e Initial load
duke
parents:
diff changeset
   947
         *  class, outer_field refers to the type of its enclosing
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
   948
         *  instance class, in all other cases it refers to noType.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   949
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   950
        private Type outer_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   951
06bc494ca11e Initial load
duke
parents:
diff changeset
   952
        /** The type parameters of this type (to be set once class is loaded).
06bc494ca11e Initial load
duke
parents:
diff changeset
   953
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   954
        public List<Type> typarams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   955
06bc494ca11e Initial load
duke
parents:
diff changeset
   956
        /** A cache variable for the type parameters of this type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   957
         *  appended to all parameters of its enclosing class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   958
         *  @see #allparams
06bc494ca11e Initial load
duke
parents:
diff changeset
   959
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   960
        public List<Type> allparams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   961
06bc494ca11e Initial load
duke
parents:
diff changeset
   962
        /** The supertype of this class (to be set once class is loaded).
06bc494ca11e Initial load
duke
parents:
diff changeset
   963
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   964
        public Type supertype_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   965
06bc494ca11e Initial load
duke
parents:
diff changeset
   966
        /** The interfaces of this class (to be set once class is loaded).
06bc494ca11e Initial load
duke
parents:
diff changeset
   967
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   968
        public List<Type> interfaces_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
   969
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   970
        /** All the interfaces of this class, including missing ones.
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   971
         */
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   972
        public List<Type> all_interfaces_field;
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
   973
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   974
        public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   975
            this(outer, typarams, tsym, TypeMetadata.EMPTY);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   976
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   977
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   978
        public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   979
                         TypeMetadata metadata) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
   980
            super(tsym, metadata);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   981
            this.outer_field = outer;
06bc494ca11e Initial load
duke
parents:
diff changeset
   982
            this.typarams_field = typarams;
06bc494ca11e Initial load
duke
parents:
diff changeset
   983
            this.allparams_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   984
            this.supertype_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   985
            this.interfaces_field = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   986
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   987
06bc494ca11e Initial load
duke
parents:
diff changeset
   988
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   989
        public ClassType cloneWithMetadata(TypeMetadata md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   990
            return new ClassType(outer_field, typarams_field, tsym, md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   991
                @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   992
                public Type baseType() { return ClassType.this.baseType(); }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
   993
            };
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   994
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   995
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
   996
        @Override
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   997
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   998
            return CLASS;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   999
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1000
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1001
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1002
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1003
            return v.visitClassType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1004
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1005
06bc494ca11e Initial load
duke
parents:
diff changeset
  1006
        public Type constType(Object constValue) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1007
            final Object value = constValue;
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1008
            return new ClassType(getEnclosingType(), typarams_field, tsym, metadata) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1009
                    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1010
                    public Object constValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1011
                        return value;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1012
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1013
                    @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1014
                    public Type baseType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1015
                        return tsym.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1016
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1017
                };
06bc494ca11e Initial load
duke
parents:
diff changeset
  1018
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1019
06bc494ca11e Initial load
duke
parents:
diff changeset
  1020
        /** The Java source which this type represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1021
         */
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1022
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1023
        public String toString() {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
  1024
            StringBuilder buf = new StringBuilder();
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1025
            if (getEnclosingType().hasTag(CLASS) && tsym.owner.kind == TYP) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1026
                buf.append(getEnclosingType().toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1027
                buf.append(".");
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1028
                appendAnnotationsString(buf);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1029
                buf.append(className(tsym, false));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1030
            } else {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1031
                appendAnnotationsString(buf);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1032
                buf.append(className(tsym, true));
06bc494ca11e Initial load
duke
parents:
diff changeset
  1033
            }
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1034
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1035
            if (getTypeArguments().nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1036
                buf.append('<');
06bc494ca11e Initial load
duke
parents:
diff changeset
  1037
                buf.append(getTypeArguments().toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1038
                buf.append(">");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1039
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1040
            return buf.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1041
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1042
//where
06bc494ca11e Initial load
duke
parents:
diff changeset
  1043
            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
  1044
                if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) {
8625
6b51ef804d49 6639645: Modeling type implementing missing interfaces
jjg
parents: 8430
diff changeset
  1045
                    StringBuilder s = new StringBuilder(supertype_field.toString());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1046
                    for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1047
                        s.append("&");
06bc494ca11e Initial load
duke
parents:
diff changeset
  1048
                        s.append(is.head.toString());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1049
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1050
                    return s.toString();
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
  1051
                } else if (sym.name.isEmpty()) {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1052
                    String s;
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1053
                    ClassType norm = (ClassType) tsym.type;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1054
                    if (norm == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1055
                        s = Log.getLocalizedString("anonymous.class", (Object)null);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1056
                    } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1057
                        s = Log.getLocalizedString("anonymous.class",
06bc494ca11e Initial load
duke
parents:
diff changeset
  1058
                                                   norm.interfaces_field.head);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1059
                    } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1060
                        s = Log.getLocalizedString("anonymous.class",
06bc494ca11e Initial load
duke
parents:
diff changeset
  1061
                                                   norm.supertype_field);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1062
                    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1063
                    if (moreInfo)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1064
                        s += String.valueOf(sym.hashCode());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1065
                    return s;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1066
                } else if (longform) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1067
                    return sym.getQualifiedName().toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1068
                } else {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1069
                    return sym.name.toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1070
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1071
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1072
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1073
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1074
        public List<Type> getTypeArguments() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1075
            if (typarams_field == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1076
                complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1077
                if (typarams_field == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1078
                    typarams_field = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1079
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1080
            return typarams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1081
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1082
514
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1083
        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
  1084
            return isRaw();
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1085
        }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1086
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1087
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1088
        public Type getEnclosingType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1089
            return outer_field;
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 void setEnclosingType(Type outer) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1093
            outer_field = outer;
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 List<Type> allparams() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1097
            if (allparams_field == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1098
                allparams_field = getTypeArguments().prependList(getEnclosingType().allparams());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1099
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1100
            return allparams_field;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1101
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1102
06bc494ca11e Initial load
duke
parents:
diff changeset
  1103
        public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1104
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1105
                getEnclosingType().isErroneous() ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1106
                isErroneous(getTypeArguments()) ||
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1107
                this != tsym.type && tsym.type.isErroneous();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1108
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1109
06bc494ca11e Initial load
duke
parents:
diff changeset
  1110
        public boolean isParameterized() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1111
            return allparams().tail != null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1112
            // optimization, was: allparams().nonEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1113
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1114
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1115
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1116
        public boolean isReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1117
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1118
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1119
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1120
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1121
        public boolean isNullOrReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1122
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1123
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1124
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1125
        /** A cache for the rank. */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1126
        int rank_field = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1127
06bc494ca11e Initial load
duke
parents:
diff changeset
  1128
        /** A class type is raw if it misses some
06bc494ca11e Initial load
duke
parents:
diff changeset
  1129
         *  of its type parameter sections.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1130
         *  After validation, this is equivalent to:
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 13631
diff changeset
  1131
         *  {@code allparams.isEmpty() && tsym.type.allparams.nonEmpty(); }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1132
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1133
        public boolean isRaw() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1134
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1135
                this != tsym.type && // necessary, but not sufficient condition
06bc494ca11e Initial load
duke
parents:
diff changeset
  1136
                tsym.type.allparams().nonEmpty() &&
06bc494ca11e Initial load
duke
parents:
diff changeset
  1137
                allparams().isEmpty();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1138
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1139
06bc494ca11e Initial load
duke
parents:
diff changeset
  1140
        public boolean contains(Type elem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1141
            return
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1142
                elem.equalsIgnoreMetadata(this)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1143
                || (isParameterized()
6348
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
  1144
                    && (getEnclosingType().contains(elem) || contains(getTypeArguments(), elem)))
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
  1145
                || (isCompound()
6c9b14d4a438 6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents: 5847
diff changeset
  1146
                    && (supertype_field.contains(elem) || contains(interfaces_field, elem)));
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1147
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1148
06bc494ca11e Initial load
duke
parents:
diff changeset
  1149
        public void complete() {
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 30011
diff changeset
  1150
            tsym.complete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1151
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1152
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1153
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1154
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1155
            return TypeKind.DECLARED;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1156
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1157
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1158
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1159
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1160
            return v.visitDeclared(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1161
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1162
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1163
514
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1164
    public static class ErasedClassType extends ClassType {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1165
        public ErasedClassType(Type outer, TypeSymbol tsym,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1166
                               TypeMetadata metadata) {
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
  1167
            super(outer, List.nil(), tsym, metadata);
514
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1168
        }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1169
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1170
        @Override
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1171
        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
  1172
            return true;
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1173
        }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1174
    }
3942d9cdc81c 6559182: Cast from a raw type with non-generic supertype to a raw type fails unexpectedly
mcimadamore
parents: 10
diff changeset
  1175
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1176
    // 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
  1177
    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
  1178
        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
  1179
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1180
        public UnionClassType(ClassType ct, List<? extends Type> alternatives) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1181
            // Presently no way to refer to this type directly, so we
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1182
            // cannot put annotations directly on it.
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1183
            super(ct.outer_field, ct.typarams_field, ct.tsym);
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1184
            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
  1185
            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
  1186
            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
  1187
            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
  1188
            alternatives_field = alternatives;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1189
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1190
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1191
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1192
        public UnionClassType cloneWithMetadata(TypeMetadata md) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1193
            throw new AssertionError("Cannot add metadata to a union type");
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1194
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1195
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1196
        public Type getLub() {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1197
            return tsym.type;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1198
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1199
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1200
        @DefinedBy(Api.LANGUAGE_MODEL)
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1201
        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
  1202
            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
  1203
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1204
29147
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
  1205
        @Override
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
  1206
        public boolean isUnion() {
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
  1207
            return true;
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
  1208
        }
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
  1209
33556
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
  1210
        @Override
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
  1211
        public boolean isCompound() {
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
  1212
            return getLub().isCompound();
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
  1213
        }
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
  1214
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1215
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1216
        public TypeKind getKind() {
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1217
            return TypeKind.UNION;
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1218
        }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1219
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1220
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1221
        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
  1222
            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
  1223
        }
25440
7f9cedf2e88d 8042239: javac: TreeMaker.Type(Type t) does not handle UnionClassType
jlahoda
parents: 24794
diff changeset
  1224
7f9cedf2e88d 8042239: javac: TreeMaker.Type(Type t) does not handle UnionClassType
jlahoda
parents: 24794
diff changeset
  1225
        public Iterable<? extends Type> getAlternativeTypes() {
7f9cedf2e88d 8042239: javac: TreeMaker.Type(Type t) does not handle UnionClassType
jlahoda
parents: 24794
diff changeset
  1226
            return alternatives_field;
7f9cedf2e88d 8042239: javac: TreeMaker.Type(Type t) does not handle UnionClassType
jlahoda
parents: 24794
diff changeset
  1227
        }
9599
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1228
    }
0996df19ea87 7029150: Project Coin: present union types from the tree API through to javax.lang.model
jjg
parents: 8625
diff changeset
  1229
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1230
    // 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
  1231
    public static class IntersectionClassType extends ClassType implements IntersectionType {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1232
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1233
        public boolean allInterfaces;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1234
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1235
        public IntersectionClassType(List<Type> bounds, ClassSymbol csym, boolean allInterfaces) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1236
            // Presently no way to refer to this type directly, so we
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1237
            // cannot put annotations directly on it.
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
  1238
            super(Type.noType, List.nil(), csym);
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1239
            this.allInterfaces = allInterfaces;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1240
            Assert.check((csym.flags() & COMPOUND) != 0);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1241
            supertype_field = bounds.head;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1242
            interfaces_field = bounds.tail;
30066
d74c06a92bd8 8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents: 30011
diff changeset
  1243
            Assert.check(!supertype_field.tsym.isCompleted() ||
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1244
                    !supertype_field.isInterface(), supertype_field);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1245
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1246
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1247
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1248
        public IntersectionClassType cloneWithMetadata(TypeMetadata md) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1249
            throw new AssertionError("Cannot add metadata to an intersection type");
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1250
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1251
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1252
        @DefinedBy(Api.LANGUAGE_MODEL)
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1253
        public java.util.List<? extends TypeMirror> getBounds() {
20252
fae5c47ba7a4 6499673: Assertion check for TypeVariable.getUpperBound() fails.
emc
parents: 20249
diff changeset
  1254
            return Collections.unmodifiableList(getExplicitComponents());
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1255
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1256
33556
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
  1257
        @Override
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
  1258
        public boolean isCompound() {
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
  1259
            return true;
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
  1260
        }
a14a556cf2c9 8141343: Subtle semantics changes for union types in cast conversion
mcimadamore
parents: 33018
diff changeset
  1261
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1262
        public List<Type> getComponents() {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1263
            return interfaces_field.prepend(supertype_field);
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1264
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1265
29147
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
  1266
        @Override
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
  1267
        public boolean isIntersection() {
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
  1268
            return true;
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
  1269
        }
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27224
diff changeset
  1270
16809
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16557
diff changeset
  1271
        public List<Type> getExplicitComponents() {
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16557
diff changeset
  1272
            return allInterfaces ?
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16557
diff changeset
  1273
                    interfaces_field :
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16557
diff changeset
  1274
                    getComponents();
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16557
diff changeset
  1275
        }
5acfcb821d65 8010822: Intersection type cast for functional expressions does not follow spec EDR
mcimadamore
parents: 16557
diff changeset
  1276
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1277
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1278
        public TypeKind getKind() {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1279
            return TypeKind.INTERSECTION;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1280
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1281
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1282
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1283
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
21890
a627c91c71db 6557966: Multiple upper bounds of the TypeVariable
jlahoda
parents: 21041
diff changeset
  1284
            return v.visitIntersection(this, p);
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1285
        }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1286
    }
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14359
diff changeset
  1287
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1288
    public static class ArrayType extends Type
06bc494ca11e Initial load
duke
parents:
diff changeset
  1289
            implements javax.lang.model.type.ArrayType {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1290
06bc494ca11e Initial load
duke
parents:
diff changeset
  1291
        public Type elemtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1292
06bc494ca11e Initial load
duke
parents:
diff changeset
  1293
        public ArrayType(Type elemtype, TypeSymbol arrayClass) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1294
            this(elemtype, arrayClass, TypeMetadata.EMPTY);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1295
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1296
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1297
        public ArrayType(Type elemtype, TypeSymbol arrayClass,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1298
                         TypeMetadata metadata) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1299
            super(arrayClass, metadata);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1300
            this.elemtype = elemtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1301
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1302
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1303
        public ArrayType(ArrayType that) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1304
            //note: type metadata is deliberately shared here, as we want side-effects from annotation
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1305
            //processing to flow from original array to the cloned array.
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1306
            this(that.elemtype, that.tsym, that.getMetadata());
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1307
        }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1308
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1309
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1310
        public ArrayType cloneWithMetadata(TypeMetadata md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1311
            return new ArrayType(elemtype, tsym, md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1312
                @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1313
                public Type baseType() { return ArrayType.this.baseType(); }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1314
            };
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1315
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1316
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1317
        @Override
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1318
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1319
            return ARRAY;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1320
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1321
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1322
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1323
            return v.visitArrayType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1324
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1325
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1326
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1327
        public String toString() {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1328
            StringBuilder sb = new StringBuilder();
30011
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1329
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1330
            // First append root component type
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1331
            Type t = elemtype;
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1332
            while (t.getKind() == TypeKind.ARRAY)
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1333
                t = ((ArrayType) t).getComponentType();
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1334
            sb.append(t);
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1335
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1336
            // then append @Anno[] @Anno[] ... @Anno[]
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1337
            t = this;
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1338
            do {
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1339
                t.appendAnnotationsString(sb, true);
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1340
                sb.append("[]");
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1341
                t = ((ArrayType) t).getComponentType();
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1342
            } while (t.getKind() == TypeKind.ARRAY);
34df75eba76b 8068737: ArrayType prints element type post order
alundblad
parents: 29842
diff changeset
  1343
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1344
            return sb.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1345
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1346
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1347
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1348
        public boolean equals(Object obj) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1349
            if (obj instanceof ArrayType) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1350
                ArrayType that = (ArrayType)obj;
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1351
                return this == that ||
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1352
                        elemtype.equals(that.elemtype);
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1353
            }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1354
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1355
            return false;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1356
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1357
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1358
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1359
        public int hashCode() {
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
  1360
            return (ARRAY.ordinal() << 5) + elemtype.hashCode();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1361
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1362
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1363
        public boolean isVarargs() {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1364
            return false;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1365
        }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1366
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1367
        public List<Type> allparams() { return elemtype.allparams(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1368
06bc494ca11e Initial load
duke
parents:
diff changeset
  1369
        public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1370
            return elemtype.isErroneous();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1371
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1372
06bc494ca11e Initial load
duke
parents:
diff changeset
  1373
        public boolean isParameterized() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1374
            return elemtype.isParameterized();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1375
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1376
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1377
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1378
        public boolean isReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1379
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1380
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1381
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1382
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1383
        public boolean isNullOrReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1384
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1385
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1386
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1387
        public boolean isRaw() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1388
            return elemtype.isRaw();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1389
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1390
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1391
        public ArrayType makeVarargs() {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1392
            return new ArrayType(elemtype, tsym, metadata) {
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1393
                @Override
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1394
                public boolean isVarargs() {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1395
                    return true;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1396
                }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1397
            };
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1398
        }
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7637
diff changeset
  1399
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1400
        public boolean contains(Type elem) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1401
            return elem.equalsIgnoreMetadata(this) || elemtype.contains(elem);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1402
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1403
06bc494ca11e Initial load
duke
parents:
diff changeset
  1404
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1405
            elemtype.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1406
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1407
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1408
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1409
        public Type getComponentType() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1410
            return elemtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1411
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1412
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1413
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1414
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1415
            return TypeKind.ARRAY;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1416
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1417
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1418
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1419
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1420
            return v.visitArray(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1421
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1422
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1423
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8044
diff changeset
  1424
    public static class MethodType extends Type implements ExecutableType {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1425
06bc494ca11e Initial load
duke
parents:
diff changeset
  1426
        public List<Type> argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1427
        public Type restype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1428
        public List<Type> thrown;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1429
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1430
        /** The type annotations on the method receiver.
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1431
         */
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1432
        public Type recvtype;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1433
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1434
        public MethodType(List<Type> argtypes,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1435
                          Type restype,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1436
                          List<Type> thrown,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1437
                          TypeSymbol methodClass) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1438
            // Presently no way to refer to a method type directly, so
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1439
            // we cannot put type annotations on it.
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1440
            super(methodClass, TypeMetadata.EMPTY);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1441
            this.argtypes = argtypes;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1442
            this.restype = restype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1443
            this.thrown = thrown;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1444
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1445
06bc494ca11e Initial load
duke
parents:
diff changeset
  1446
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1447
        public MethodType cloneWithMetadata(TypeMetadata md) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1448
            throw new AssertionError("Cannot add metadata to a method type");
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1449
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1450
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1451
        @Override
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1452
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1453
            return METHOD;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1454
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1455
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1456
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1457
            return v.visitMethodType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1458
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1459
06bc494ca11e Initial load
duke
parents:
diff changeset
  1460
        /** The Java source which this type represents.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1461
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
  1462
         *  XXX 06/09/99 iris This isn't correct Java syntax, but it probably
06bc494ca11e Initial load
duke
parents:
diff changeset
  1463
         *  should be.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1464
         */
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1465
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1466
        public String toString() {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1467
            StringBuilder sb = new StringBuilder();
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1468
            appendAnnotationsString(sb);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1469
            sb.append('(');
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1470
            sb.append(argtypes);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1471
            sb.append(')');
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1472
            sb.append(restype);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1473
            return sb.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1474
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1475
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1476
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1477
        public List<Type>        getParameterTypes() { return argtypes; }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1478
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1479
        public Type              getReturnType()     { return restype; }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1480
        @DefinedBy(Api.LANGUAGE_MODEL)
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1481
        public Type              getReceiverType()   { return recvtype; }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1482
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1483
        public List<Type>        getThrownTypes()    { return thrown; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1484
06bc494ca11e Initial load
duke
parents:
diff changeset
  1485
        public boolean isErroneous() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1486
            return
06bc494ca11e Initial load
duke
parents:
diff changeset
  1487
                isErroneous(argtypes) ||
06bc494ca11e Initial load
duke
parents:
diff changeset
  1488
                restype != null && restype.isErroneous();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1489
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1490
06bc494ca11e Initial load
duke
parents:
diff changeset
  1491
        public boolean contains(Type elem) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1492
            return elem.equalsIgnoreMetadata(this) || contains(argtypes, elem) || restype.contains(elem) || contains(thrown, elem);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1493
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1494
06bc494ca11e Initial load
duke
parents:
diff changeset
  1495
        public MethodType asMethodType() { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1496
06bc494ca11e Initial load
duke
parents:
diff changeset
  1497
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1498
            for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1499
                l.head.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1500
            restype.complete();
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1501
            recvtype.complete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1502
            for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)
06bc494ca11e Initial load
duke
parents:
diff changeset
  1503
                l.head.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1504
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1505
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1506
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1507
        public List<TypeVar> getTypeVariables() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1508
            return List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1509
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1510
06bc494ca11e Initial load
duke
parents:
diff changeset
  1511
        public TypeSymbol asElement() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1512
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1513
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1514
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1515
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1516
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1517
            return TypeKind.EXECUTABLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1518
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1519
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1520
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1521
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1522
            return v.visitExecutable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1523
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1524
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1525
06bc494ca11e Initial load
duke
parents:
diff changeset
  1526
    public static class PackageType extends Type implements NoType {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1527
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1528
        PackageType(PackageSymbol tsym) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1529
            // Package types cannot be annotated
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1530
            super(tsym, TypeMetadata.EMPTY);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1531
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1532
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1533
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1534
        public PackageType cloneWithMetadata(TypeMetadata md) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1535
            throw new AssertionError("Cannot add metadata to a package type");
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1536
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1537
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1538
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1539
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1540
            return PACKAGE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1541
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1542
06bc494ca11e Initial load
duke
parents:
diff changeset
  1543
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1544
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1545
            return v.visitPackageType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1546
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1547
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1548
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1549
        public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1550
            return tsym.getQualifiedName().toString();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1551
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1552
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1553
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1554
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1555
            return TypeKind.PACKAGE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1556
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1557
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1558
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1559
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1560
            return v.visitNoType(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1561
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1562
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1563
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1564
    public static class ModuleType extends Type implements NoType {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1565
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1566
        ModuleType(ModuleSymbol tsym) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1567
            // Module types cannot be annotated
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1568
            super(tsym, TypeMetadata.EMPTY);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1569
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1570
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1571
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1572
        public ModuleType cloneWithMetadata(TypeMetadata md) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1573
            throw new AssertionError("Cannot add metadata to a module type");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1574
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1575
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1576
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1577
        public ModuleType annotatedType(List<Attribute.TypeCompound> annos) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1578
            throw new AssertionError("Cannot annotate a module type");
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1579
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1580
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1581
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1582
        public TypeTag getTag() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1583
            return TypeTag.MODULE;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1584
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1585
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1586
        @Override
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1587
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1588
            return v.visitModuleType(this, s);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1589
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1590
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 37003
diff changeset
  1591
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1592
        public String toString() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1593
            return tsym.getQualifiedName().toString();
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1594
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1595
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 37003
diff changeset
  1596
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1597
        public TypeKind getKind() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1598
            return TypeKind.MODULE;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1599
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1600
37848
3c8ff4204d2d 8154956: Module system implementation refresh (4/2016)
alanb
parents: 37003
diff changeset
  1601
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1602
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1603
            return v.visitNoType(this, p);
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1604
        }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1605
    }
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  1606
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1607
    public static class TypeVar extends Type implements TypeVariable {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1608
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1609
        /** The upper bound of this type variable; set from outside.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1610
         *  Must be nonempty once it is set.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1611
         *  For a bound, `bound' is the bound type itself.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1612
         *  Multiple bounds are expressed as a single class type which has the
06bc494ca11e Initial load
duke
parents:
diff changeset
  1613
         *  individual bounds as superclass, respectively interfaces.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1614
         *  The class type then has as `tsym' a compiler generated class `c',
06bc494ca11e Initial load
duke
parents:
diff changeset
  1615
         *  which has a flag COMPOUND and whose owner is the type variable
06bc494ca11e Initial load
duke
parents:
diff changeset
  1616
         *  itself. Furthermore, the erasure_field of the class
06bc494ca11e Initial load
duke
parents:
diff changeset
  1617
         *  points to the first class or interface bound.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1618
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1619
        public Type bound = null;
7637
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1620
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1621
        /** The lower bound of this type variable.
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1622
         *  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
  1623
         *  to syms.botType.
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1624
         *  Subtypes, such as CapturedType, may provide a different value.
467bc8fc514e 6990134: minor (but red) findbugs warnings
jjg
parents: 6353
diff changeset
  1625
         */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1626
        public Type lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1627
06bc494ca11e Initial load
duke
parents:
diff changeset
  1628
        public TypeVar(Name name, Symbol owner, Type lower) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1629
            super(null, TypeMetadata.EMPTY);
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16809
diff changeset
  1630
            tsym = new TypeVariableSymbol(0, name, this, owner);
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1631
            this.bound = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1632
            this.lower = lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1633
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1634
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1635
        public TypeVar(TypeSymbol tsym, Type bound, Type lower) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1636
            this(tsym, bound, lower, TypeMetadata.EMPTY);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1637
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1638
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1639
        public TypeVar(TypeSymbol tsym, Type bound, Type lower,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1640
                       TypeMetadata metadata) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1641
            super(tsym, metadata);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1642
            this.bound = bound;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1643
            this.lower = lower;
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
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1647
        public TypeVar cloneWithMetadata(TypeMetadata md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1648
            return new TypeVar(tsym, bound, lower, md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1649
                @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1650
                public Type baseType() { return TypeVar.this.baseType(); }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1651
            };
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1652
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1653
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1654
        @Override
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1655
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1656
            return TYPEVAR;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1657
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1658
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1659
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1660
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1661
            return v.visitTypeVar(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1662
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1663
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1664
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1665
        public Type getUpperBound() {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1666
            if ((bound == null || bound.hasTag(NONE)) && this != tsym.type) {
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1667
                bound = tsym.type.getUpperBound();
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1668
            }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1669
            return bound;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1670
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1671
06bc494ca11e Initial load
duke
parents:
diff changeset
  1672
        int rank_field = -1;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1673
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1674
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1675
        public Type getLowerBound() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1676
            return lower;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1677
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1678
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1679
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1680
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1681
            return TypeKind.TYPEVAR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1682
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1683
938
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1684
        public boolean isCaptured() {
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1685
            return false;
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1686
        }
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1687
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1688
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1689
        public boolean isReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1690
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1691
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1692
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1693
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1694
        public boolean isNullOrReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1695
            return true;
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
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1698
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1699
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1700
            return v.visitTypeVariable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1701
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1702
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1703
06bc494ca11e Initial load
duke
parents:
diff changeset
  1704
    /** A captured type variable comes from wildcards which can have
06bc494ca11e Initial load
duke
parents:
diff changeset
  1705
     *  both upper and lower bound.  CapturedType extends TypeVar with
06bc494ca11e Initial load
duke
parents:
diff changeset
  1706
     *  a lower bound.
06bc494ca11e Initial load
duke
parents:
diff changeset
  1707
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1708
    public static class CapturedType extends TypeVar {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1709
06bc494ca11e Initial load
duke
parents:
diff changeset
  1710
        public WildcardType wildcard;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1711
06bc494ca11e Initial load
duke
parents:
diff changeset
  1712
        public CapturedType(Name name,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1713
                            Symbol owner,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1714
                            Type upper,
06bc494ca11e Initial load
duke
parents:
diff changeset
  1715
                            Type lower,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1716
                            WildcardType wildcard) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1717
            super(name, owner, lower);
8032
e1aa25ccdabb 6396503: javac should not require assertions enabled
jjg
parents: 7681
diff changeset
  1718
            this.lower = Assert.checkNonNull(lower);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1719
            this.bound = upper;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1720
            this.wildcard = wildcard;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1721
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1722
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1723
        public CapturedType(TypeSymbol tsym,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1724
                            Type bound,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1725
                            Type upper,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1726
                            Type lower,
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1727
                            WildcardType wildcard,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1728
                            TypeMetadata metadata) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1729
            super(tsym, bound, lower, metadata);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1730
            this.wildcard = wildcard;
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1731
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1732
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1733
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1734
        public CapturedType cloneWithMetadata(TypeMetadata md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1735
            return new CapturedType(tsym, bound, bound, lower, wildcard, md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1736
                @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1737
                public Type baseType() { return CapturedType.this.baseType(); }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1738
            };
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1739
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1740
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1741
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1742
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1743
            return v.visitCapturedType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1744
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1745
06bc494ca11e Initial load
duke
parents:
diff changeset
  1746
        @Override
938
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1747
        public boolean isCaptured() {
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1748
            return true;
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1749
        }
13aae74ca013 6594284: NPE thrown when calling a method on an intersection type
mcimadamore
parents: 735
diff changeset
  1750
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1751
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1752
        public String toString() {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1753
            StringBuilder sb = new StringBuilder();
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1754
            appendAnnotationsString(sb);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1755
            sb.append("capture#");
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1756
            sb.append((hashCode() & 0xFFFFFFFFL) % Printer.PRIME);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1757
            sb.append(" of ");
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1758
            sb.append(wildcard);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1759
            return sb.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1760
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1761
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1762
06bc494ca11e Initial load
duke
parents:
diff changeset
  1763
    public static abstract class DelegatedType extends Type {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1764
        public Type qtype;
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1765
        public TypeTag tag;
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1766
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1767
        public DelegatedType(TypeTag tag, Type qtype) {
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1768
            this(tag, qtype, TypeMetadata.EMPTY);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1769
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1770
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1771
        public DelegatedType(TypeTag tag, Type qtype,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1772
                             TypeMetadata metadata) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1773
            super(qtype.tsym, metadata);
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1774
            this.tag = tag;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1775
            this.qtype = qtype;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1776
        }
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1777
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  1778
        public TypeTag getTag() { return tag; }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1779
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1780
        public String toString() { return qtype.toString(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1781
        public List<Type> getTypeArguments() { return qtype.getTypeArguments(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1782
        public Type getEnclosingType() { return qtype.getEnclosingType(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1783
        public List<Type> getParameterTypes() { return qtype.getParameterTypes(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1784
        public Type getReturnType() { return qtype.getReturnType(); }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  1785
        public Type getReceiverType() { return qtype.getReceiverType(); }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1786
        public List<Type> getThrownTypes() { return qtype.getThrownTypes(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1787
        public List<Type> allparams() { return qtype.allparams(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1788
        public Type getUpperBound() { return qtype.getUpperBound(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1789
        public boolean isErroneous() { return qtype.isErroneous(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1790
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1791
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1792
    /**
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1793
     * 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
  1794
     * 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
  1795
     * type.
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1796
     */
8430
be3e5581ea25 6990136: Cleanup use of Type.clone()
dlsmith
parents: 8044
diff changeset
  1797
    public static class ForAll extends DelegatedType implements ExecutableType {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1798
        public List<Type> tvars;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1799
06bc494ca11e Initial load
duke
parents:
diff changeset
  1800
        public ForAll(List<Type> tvars, Type qtype) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1801
            super(FORALL, (MethodType)qtype);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1802
            this.tvars = tvars;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1803
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1804
06bc494ca11e Initial load
duke
parents:
diff changeset
  1805
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  1806
        public ForAll cloneWithMetadata(TypeMetadata md) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1807
            throw new AssertionError("Cannot add metadata to a forall type");
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1808
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1809
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1810
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1811
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1812
            return v.visitForAll(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1813
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1814
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1815
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1816
        public String toString() {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1817
            StringBuilder sb = new StringBuilder();
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1818
            appendAnnotationsString(sb);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1819
            sb.append('<');
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1820
            sb.append(tvars);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1821
            sb.append('>');
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1822
            sb.append(qtype);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1823
            return sb.toString();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1824
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1825
06bc494ca11e Initial load
duke
parents:
diff changeset
  1826
        public List<Type> getTypeArguments()   { return tvars; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1827
06bc494ca11e Initial load
duke
parents:
diff changeset
  1828
        public boolean isErroneous()  {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1829
            return qtype.isErroneous();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1830
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1831
06bc494ca11e Initial load
duke
parents:
diff changeset
  1832
        public boolean contains(Type elem) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1833
            return qtype.contains(elem);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1834
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1835
06bc494ca11e Initial load
duke
parents:
diff changeset
  1836
        public MethodType asMethodType() {
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
  1837
            return (MethodType)qtype;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1838
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1839
06bc494ca11e Initial load
duke
parents:
diff changeset
  1840
        public void complete() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1841
            for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1842
                ((TypeVar)l.head).bound.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1843
            }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1844
            qtype.complete();
06bc494ca11e Initial load
duke
parents:
diff changeset
  1845
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1846
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1847
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1848
        public List<TypeVar> getTypeVariables() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1849
            return List.convert(TypeVar.class, getTypeArguments());
06bc494ca11e Initial load
duke
parents:
diff changeset
  1850
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1851
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1852
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1853
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1854
            return TypeKind.EXECUTABLE;
06bc494ca11e Initial load
duke
parents:
diff changeset
  1855
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1856
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1857
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1858
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1859
            return v.visitExecutable(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1860
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1861
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1862
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1863
    /** 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
  1864
     *  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
  1865
     *  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
  1866
     *  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
  1867
     *  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
  1868
     *  whenever the bounds of an inference variable change.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1869
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  1870
    public static class UndetVar extends DelegatedType {
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1871
42416
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1872
        enum Kind {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1873
            NORMAL,
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1874
            CAPTURED,
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1875
            THROWS;
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1876
        }
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1877
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1878
        /** 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
  1879
         *  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
  1880
         */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1881
        public interface UndetVarListener {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1882
            /** called when some inference variable bounds (of given kinds ibs) change */
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1883
            void varBoundChanged(UndetVar uv, InferenceBound ib, Type bound, boolean update);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1884
            /** called when the inferred type is set on some inference variable */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1885
            default void varInstantiated(UndetVar uv) { Assert.error(); }
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1886
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1887
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1888
        /**
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1889
         * Inference variable bound kinds
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1890
         */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1891
        public enum InferenceBound {
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1892
            /** lower bounds */
24293
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 23395
diff changeset
  1893
            LOWER {
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 23395
diff changeset
  1894
                public InferenceBound complement() { return UPPER; }
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 23395
diff changeset
  1895
            },
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1896
            /** equality constraints */
24293
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 23395
diff changeset
  1897
            EQ {
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 23395
diff changeset
  1898
                public InferenceBound complement() { return EQ; }
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1899
            },
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1900
            /** upper bounds */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1901
            UPPER {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1902
                public InferenceBound complement() { return LOWER; }
24293
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 23395
diff changeset
  1903
            };
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 23395
diff changeset
  1904
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 23395
diff changeset
  1905
            public abstract InferenceBound complement();
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1906
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1907
            public boolean lessThan(InferenceBound that) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1908
                if (that == this) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1909
                    return false;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1910
                } else {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1911
                    switch (that) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1912
                        case UPPER: return true;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1913
                        case LOWER: return false;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1914
                        case EQ: return (this != UPPER);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1915
                        default:
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1916
                            Assert.error("Cannot get here!");
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1917
                            return false;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1918
                    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1919
                }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1920
            }
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1921
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1922
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1923
        /** list of incorporation actions (used by the incorporation engine). */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1924
        public ArrayDeque<IncorporationAction> incorporationActions = new ArrayDeque<>();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1925
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1926
        /** inference variable bounds */
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18904
diff changeset
  1927
        protected Map<InferenceBound, List<Type>> bounds;
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1928
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1929
        /** inference variable's inferred type (set from Infer.java) */
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1930
        private Type inst = null;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1931
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1932
        /** number of declared (upper) bounds */
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1933
        public int declaredCount;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1934
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1935
        /** inference variable's change listener */
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1936
        public UndetVarListener listener = null;
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  1937
42416
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1938
        Kind kind;
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1939
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1940
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  1941
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  1942
            return v.visitUndetVar(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  1943
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1944
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1945
        public UndetVar(TypeVar origin, UndetVarListener listener, Types types) {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1946
            // This is a synthesized internal type, so we cannot annotate it.
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  1947
            super(UNDETVAR, origin);
42416
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1948
            this.kind = origin.isCaptured() ?
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1949
                    Kind.CAPTURED :
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1950
                    Kind.NORMAL;
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1951
            this.listener = listener;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21890
diff changeset
  1952
            bounds = new EnumMap<>(InferenceBound.class);
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1953
            List<Type> declaredBounds = types.getBounds(origin);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  1954
            declaredCount = declaredBounds.length();
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1955
            bounds.put(InferenceBound.UPPER, List.nil());
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1956
            bounds.put(InferenceBound.LOWER, List.nil());
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1957
            bounds.put(InferenceBound.EQ, List.nil());
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1958
            for (Type t : declaredBounds.reverse()) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1959
                //add bound works in reverse order
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1960
                addBound(InferenceBound.UPPER, t, types, true);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  1961
            }
42416
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1962
            if (origin.isCaptured() && !origin.lower.hasTag(BOT)) {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1963
                //add lower bound if needed
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1964
                addBound(InferenceBound.LOWER, origin.lower, types, true);
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1965
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1966
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1967
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  1968
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1969
        public String toString() {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1970
            StringBuilder sb = new StringBuilder();
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1971
            appendAnnotationsString(sb);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1972
            if (inst == null) {
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1973
                sb.append(qtype);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1974
                sb.append('?');
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1975
            } else {
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1976
                sb.append(inst);
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1977
            }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1978
            return sb.toString();
23395
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1979
        }
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1980
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1981
        public String debugString() {
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1982
            String result = "inference var = " + qtype + "\n";
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1983
            if (inst != null) {
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1984
                result += "inst = " + inst + '\n';
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1985
            }
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1986
            for (InferenceBound bound: InferenceBound.values()) {
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1987
                List<Type> aboundList = bounds.get(bound);
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1988
                if (aboundList.size() > 0) {
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1989
                    result += bound + " = " + aboundList + '\n';
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1990
                }
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1991
            }
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  1992
            return result;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  1993
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  1994
42416
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1995
        public void setThrow() {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1996
            if (this.kind == Kind.CAPTURED) {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1997
                //invalid state transition
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1998
                throw new IllegalStateException();
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  1999
            }
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2000
            this.kind = Kind.THROWS;
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2001
        }
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2002
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2003
        /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2004
         * Returns a new copy of this undet var.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2005
         */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2006
        public UndetVar dup(Types types) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2007
            UndetVar uv2 = new UndetVar((TypeVar)qtype, listener, types);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2008
            dupTo(uv2, types);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2009
            return uv2;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2010
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2011
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2012
        /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2013
         * Dumps the contents of this undet var on another undet var.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2014
         */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2015
        public void dupTo(UndetVar uv2, Types types) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2016
            uv2.listener = null;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2017
            uv2.bounds.clear();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2018
            for (InferenceBound ib : InferenceBound.values()) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2019
                uv2.bounds.put(ib, List.nil());
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2020
                for (Type t : getBounds(ib)) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2021
                    uv2.addBound(ib, t, types, true);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2022
                }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2023
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2024
            uv2.inst = inst;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2025
            uv2.listener = listener;
37003
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36526
diff changeset
  2026
            uv2.incorporationActions = new ArrayDeque<>();
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36526
diff changeset
  2027
            for (IncorporationAction action : incorporationActions) {
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36526
diff changeset
  2028
                uv2.incorporationActions.add(action.dup(uv2));
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36526
diff changeset
  2029
            }
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2030
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2031
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2032
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2033
        public UndetVar cloneWithMetadata(TypeMetadata md) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2034
            throw new AssertionError("Cannot add metadata to an UndetVar type");
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2035
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2036
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2037
        @Override
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2038
        public boolean isPartial() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2039
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2040
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2041
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2042
        @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2043
        public Type baseType() {
23395
e7e0973e6d2e 8034127: javac provide debug oriented toString() methods to InferenceContext and UndetVar
vromero
parents: 22163
diff changeset
  2044
            return (inst == null) ? this : inst.baseType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2045
        }
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2046
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2047
        public Type getInst() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2048
            return inst;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2049
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2050
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2051
        public void setInst(Type inst) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2052
            this.inst = inst;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2053
            if (listener != null) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2054
                listener.varInstantiated(this);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2055
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2056
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2057
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2058
        /** get all bounds of a given kind */
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2059
        public List<Type> getBounds(InferenceBound... ibs) {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19502
diff changeset
  2060
            ListBuffer<Type> buf = new ListBuffer<>();
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2061
            for (InferenceBound ib : ibs) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2062
                buf.appendList(bounds.get(ib));
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2063
            }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2064
            return buf.toList();
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2065
        }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2066
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2067
        /** get the list of declared (upper) bounds */
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2068
        public List<Type> getDeclaredBounds() {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19502
diff changeset
  2069
            ListBuffer<Type> buf = new ListBuffer<>();
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2070
            int count = 0;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2071
            for (Type b : getBounds(InferenceBound.UPPER)) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2072
                if (count++ == declaredCount) break;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2073
                buf.append(b);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2074
            }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2075
            return buf.toList();
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2076
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2077
18904
3c4c6457ec5b 8019824: very long error messages on inference error
mcimadamore
parents: 18902
diff changeset
  2078
        /** internal method used to override an undetvar bounds */
3c4c6457ec5b 8019824: very long error messages on inference error
mcimadamore
parents: 18902
diff changeset
  2079
        public void setBounds(InferenceBound ib, List<Type> newBounds) {
3c4c6457ec5b 8019824: very long error messages on inference error
mcimadamore
parents: 18902
diff changeset
  2080
            bounds.put(ib, newBounds);
3c4c6457ec5b 8019824: very long error messages on inference error
mcimadamore
parents: 18902
diff changeset
  2081
        }
3c4c6457ec5b 8019824: very long error messages on inference error
mcimadamore
parents: 18902
diff changeset
  2082
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2083
        /** 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
  2084
        public final void addBound(InferenceBound ib, Type bound, Types types) {
42819
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2085
            // Per JDK-8075793: in pre-8 sources, follow legacy javac behavior
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2086
            // when capture variables are inferred as bounds: for lower bounds,
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2087
            // map to the capture variable's upper bound; for upper bounds,
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2088
            // if the capture variable has a lower bound, map to that type
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2089
            if (types.mapCapturesToBounds) {
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2090
                switch (ib) {
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2091
                    case LOWER:
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2092
                        bound = types.cvarUpperBound(bound);
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2093
                        break;
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2094
                    case UPPER:
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2095
                        Type altBound = types.cvarLowerBound(bound);
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2096
                        if (!altBound.hasTag(TypeTag.BOT)) bound = altBound;
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2097
                        break;
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2098
                }
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 42416
diff changeset
  2099
            }
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18904
diff changeset
  2100
            addBound(ib, bound, types, false);
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18904
diff changeset
  2101
        }
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18904
diff changeset
  2102
42416
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2103
        @SuppressWarnings("fallthrough")
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2104
        private void addBound(InferenceBound ib, Type bound, Types types, boolean update) {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2105
            if (kind == Kind.CAPTURED && !update) {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2106
                //Captured inference variables bounds must not be updated during incorporation,
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2107
                //except when some inference variable (beta) has been instantiated in the
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2108
                //right-hand-side of a 'C<alpha> = capture(C<? extends/super beta>) constraint.
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2109
                if (bound.hasTag(UNDETVAR) && !((UndetVar)bound).isCaptured()) {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2110
                    //If the new incoming bound is itself a (regular) inference variable,
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2111
                    //then we are allowed to propagate this inference variable bounds to it.
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2112
                    ((UndetVar)bound).addBound(ib.complement(), this, types, false);
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2113
                }
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2114
            } else {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2115
                Type bound2 = bound.map(toTypeVarMap).baseType();
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2116
                List<Type> prevBounds = bounds.get(ib);
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2117
                if (bound == qtype) return;
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2118
                for (Type b : prevBounds) {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2119
                    //check for redundancy - use strict version of isSameType on tvars
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2120
                    //(as the standard version will lead to false positives w.r.t. clones ivars)
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2121
                    if (types.isSameType(b, bound2, true)) return;
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2122
                }
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2123
                bounds.put(ib, prevBounds.prepend(bound2));
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2124
                notifyBoundChange(ib, bound2, false);
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2125
            }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2126
        }
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2127
        //where
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
  2128
            TypeMapping<Void> toTypeVarMap = new TypeMapping<Void>() {
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2129
                @Override
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
  2130
                public Type visitUndetVar(UndetVar uv, Void _unused) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
  2131
                    return uv.inst != null ? uv.inst : uv.qtype;
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2132
                }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2133
            };
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2134
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2135
        /** 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
  2136
        public void substBounds(List<Type> from, List<Type> to, Types types) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2137
            final ListBuffer<Pair<InferenceBound, Type>>  boundsChanged = new ListBuffer<>();
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2138
            UndetVarListener prevListener = listener;
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2139
            try {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2140
                //setup new listener for keeping track of changed bounds
42827
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42819
diff changeset
  2141
                listener = (uv, ib, t, _ignored) -> {
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42819
diff changeset
  2142
                    Assert.check(uv == UndetVar.this);
36468b5fa7f4 8181370: Convert anonymous inner classes into lambdas/method references
mcimadamore
parents: 42819
diff changeset
  2143
                    boundsChanged.add(new Pair<>(ib, t));
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2144
                };
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2145
                for (Map.Entry<InferenceBound, List<Type>> _entry : bounds.entrySet()) {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2146
                    InferenceBound ib = _entry.getKey();
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2147
                    List<Type> prevBounds = _entry.getValue();
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19502
diff changeset
  2148
                    ListBuffer<Type> newBounds = new ListBuffer<>();
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19502
diff changeset
  2149
                    ListBuffer<Type> deps = new ListBuffer<>();
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2150
                    //step 1 - re-add bounds that are not dependent on ivars
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2151
                    for (Type t : prevBounds) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2152
                        if (!t.containsAny(from)) {
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2153
                            newBounds.append(t);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2154
                        } else {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2155
                            deps.append(t);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2156
                        }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2157
                    }
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2158
                    //step 2 - replace bounds
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2159
                    bounds.put(ib, newBounds.toList());
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2160
                    //step 3 - for each dependency, add new replaced bound
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2161
                    for (Type dep : deps) {
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18904
diff changeset
  2162
                        addBound(ib, types.subst(dep, from, to), types, true);
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2163
                    }
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2164
                }
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2165
            } finally {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2166
                listener = prevListener;
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2167
                for (Pair<InferenceBound, Type> boundUpdate : boundsChanged) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2168
                    notifyBoundChange(boundUpdate.fst, boundUpdate.snd, true);
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15385
diff changeset
  2169
                }
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2170
            }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2171
        }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2172
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2173
        private void notifyBoundChange(InferenceBound ib, Type bound, boolean update) {
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2174
            if (listener != null) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2175
                listener.varBoundChanged(this, ib, bound, update);
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2176
            }
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 13844
diff changeset
  2177
        }
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18904
diff changeset
  2178
42416
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2179
        public final boolean isCaptured() {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2180
            return kind == Kind.CAPTURED;
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18904
diff changeset
  2181
        }
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18904
diff changeset
  2182
42416
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2183
        public final boolean isThrows() {
1cfad0990b99 8170410: inference: javac doesn't implement 18.2.5 correctly
mcimadamore
parents: 37848
diff changeset
  2184
            return kind == Kind.THROWS;
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33556
diff changeset
  2185
        }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2186
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2187
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2188
    /** Represents NONE.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2189
     */
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2190
    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
  2191
        public JCNoType() {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2192
            // Need to use List.nil(), because JCNoType constructor
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2193
            // gets called in static initializers in Type, where
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2194
            // noAnnotations is also defined.
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2195
            super(null, TypeMetadata.EMPTY);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2196
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2197
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2198
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2199
        public JCNoType cloneWithMetadata(TypeMetadata md) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2200
            throw new AssertionError("Cannot add metadata to a JCNoType");
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2201
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2202
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2203
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2204
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2205
            return NONE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2206
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2207
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2208
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2209
        public TypeKind getKind() {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2210
            return TypeKind.NONE;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2211
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2212
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2213
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2214
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2215
            return v.visitNoType(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2216
        }
20606
a8910a0bdbe6 8025413: NPE in Type.java due to recent change
emc
parents: 20252
diff changeset
  2217
a8910a0bdbe6 8025413: NPE in Type.java due to recent change
emc
parents: 20252
diff changeset
  2218
        @Override
a8910a0bdbe6 8025413: NPE in Type.java due to recent change
emc
parents: 20252
diff changeset
  2219
        public boolean isCompound() { return false; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2220
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2221
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2222
    /** Represents VOID.
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2223
     */
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2224
    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
  2225
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2226
        public JCVoidType() {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2227
            // Void cannot be annotated
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2228
            super(null, TypeMetadata.EMPTY);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2229
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2230
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2231
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2232
        public JCVoidType cloneWithMetadata(TypeMetadata md) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2233
            throw new AssertionError("Cannot add metadata to a void type");
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2234
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2235
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2236
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2237
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2238
            return VOID;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2239
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2240
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2241
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2242
        public TypeKind getKind() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2243
            return TypeKind.VOID;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2244
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2245
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2246
        @Override
20606
a8910a0bdbe6 8025413: NPE in Type.java due to recent change
emc
parents: 20252
diff changeset
  2247
        public boolean isCompound() { return false; }
a8910a0bdbe6 8025413: NPE in Type.java due to recent change
emc
parents: 20252
diff changeset
  2248
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2249
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2250
        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
  2251
            return v.visitNoType(this, p);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2252
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2253
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2254
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2255
        public boolean isPrimitiveOrVoid() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2256
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2257
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2258
    }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2259
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2260
    static class BottomType extends Type implements NullType {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2261
        public BottomType() {
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2262
            // Bottom is a synthesized internal type, so it cannot be annotated
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2263
            super(null, TypeMetadata.EMPTY);
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2264
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2265
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2266
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2267
        public BottomType cloneWithMetadata(TypeMetadata md) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2268
            throw new AssertionError("Cannot add metadata to a bottom type");
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2269
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2270
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2271
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2272
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2273
            return BOT;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2274
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2275
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2276
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2277
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2278
            return TypeKind.NULL;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2279
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2280
06bc494ca11e Initial load
duke
parents:
diff changeset
  2281
        @Override
20606
a8910a0bdbe6 8025413: NPE in Type.java due to recent change
emc
parents: 20252
diff changeset
  2282
        public boolean isCompound() { return false; }
a8910a0bdbe6 8025413: NPE in Type.java due to recent change
emc
parents: 20252
diff changeset
  2283
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2284
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2285
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2286
            return v.visitNull(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2287
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2288
06bc494ca11e Initial load
duke
parents:
diff changeset
  2289
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  2290
        public Type constType(Object value) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2291
            return this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2292
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2293
06bc494ca11e Initial load
duke
parents:
diff changeset
  2294
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  2295
        public String stringValue() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2296
            return "null";
06bc494ca11e Initial load
duke
parents:
diff changeset
  2297
        }
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2298
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2299
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2300
        public boolean isNullOrReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2301
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2302
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2303
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2304
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2305
06bc494ca11e Initial load
duke
parents:
diff changeset
  2306
    public static class ErrorType extends ClassType
06bc494ca11e Initial load
duke
parents:
diff changeset
  2307
            implements javax.lang.model.type.ErrorType {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2308
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
  2309
        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
  2310
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  2311
        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
  2312
            this(originalType, c);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2313
            c.type = this;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2314
            c.kind = ERR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2315
            c.members_field = new Scope.ErrorScope(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2316
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2317
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2318
        public ErrorType(Type originalType, TypeSymbol tsym) {
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
  2319
            super(noType, List.nil(), null);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2320
            this.tsym = tsym;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2321
            this.originalType = (originalType == null ? noType : originalType);
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2322
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2323
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2324
        private ErrorType(Type originalType, TypeSymbol tsym,
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2325
                          TypeMetadata metadata) {
42828
cce89649f958 8171371: Remove redundant type-arguments from generic method calls
mcimadamore
parents: 42827
diff changeset
  2326
            super(noType, List.nil(), null, metadata);
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2327
            this.tsym = tsym;
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2328
            this.originalType = (originalType == null ? noType : originalType);
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2329
        }
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2330
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2331
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2332
        public ErrorType cloneWithMetadata(TypeMetadata md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2333
            return new ErrorType(originalType, tsym, md) {
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2334
                @Override
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2335
                public Type baseType() { return ErrorType.this.baseType(); }
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2336
            };
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2337
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2338
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2339
        @Override
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2340
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2341
            return ERROR;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2342
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2343
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2344
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2345
        public boolean isPartial() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2346
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2347
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2348
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2349
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2350
        public boolean isReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2351
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2352
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2353
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2354
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2355
        public boolean isNullOrReference() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2356
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2357
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2358
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
  2359
        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
  2360
            this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2361
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2362
06bc494ca11e Initial load
duke
parents:
diff changeset
  2363
        @Override
06bc494ca11e Initial load
duke
parents:
diff changeset
  2364
        public <R,S> R accept(Type.Visitor<R,S> v, S s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2365
            return v.visitErrorType(this, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2366
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2367
06bc494ca11e Initial load
duke
parents:
diff changeset
  2368
        public Type constType(Object constValue) { return this; }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2369
        @DefinedBy(Api.LANGUAGE_MODEL)
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  2370
        public Type getEnclosingType()           { return this; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2371
        public Type getReturnType()              { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2372
        public Type asSub(Symbol sym)            { return this; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2373
06bc494ca11e Initial load
duke
parents:
diff changeset
  2374
        public boolean isGenType(Type t)         { return true; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2375
        public boolean isErroneous()             { return true; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2376
        public boolean isCompound()              { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2377
        public boolean isInterface()             { return false; }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2378
06bc494ca11e Initial load
duke
parents:
diff changeset
  2379
        public List<Type> allparams()            { return List.nil(); }
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2380
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2381
        public List<Type> getTypeArguments()     { return List.nil(); }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2382
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2383
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2384
        public TypeKind getKind() {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2385
            return TypeKind.ERROR;
06bc494ca11e Initial load
duke
parents:
diff changeset
  2386
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2387
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
  2388
        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
  2389
            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
  2390
        }
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1206
diff changeset
  2391
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2392
        @DefinedBy(Api.LANGUAGE_MODEL)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2393
        public <R, P> R accept(TypeVisitor<R, P> v, P p) {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2394
            return v.visitError(this, p);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2395
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2396
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2397
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2398
    public static class UnknownType extends Type {
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2399
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2400
        public UnknownType() {
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2401
            // Unknown is a synthesized internal type, so it cannot be
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  2402
            // annotated.
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2403
            super(null, TypeMetadata.EMPTY);
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  2404
        }
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  2405
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  2406
        @Override
29842
826ac2519523 8031744: Annotations on many Language Model elements are not returned
jjg
parents: 29554
diff changeset
  2407
        public UnknownType cloneWithMetadata(TypeMetadata md) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26266
diff changeset
  2408
            throw new AssertionError("Cannot add metadata to an unknown type");
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2409
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2410
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2411
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2412
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2413
            return UNKNOWN;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2414
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2415
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
  2416
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2417
        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
  2418
            return v.visitUnknown(this, p);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2419
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2420
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2421
        @Override
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2422
        public boolean isPartial() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2423
            return true;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2424
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2425
    }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
  2426
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2427
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
  2428
     * A visitor for types.  A visitor is used to implement operations
06bc494ca11e Initial load
duke
parents:
diff changeset
  2429
     * (or relations) on types.  Most common operations on types are
06bc494ca11e Initial load
duke
parents:
diff changeset
  2430
     * binary relations and this interface is designed for binary
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 14949
diff changeset
  2431
     * relations, that is, operations of the form
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2432
     * Type&nbsp;&times;&nbsp;S&nbsp;&rarr;&nbsp;R.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2433
     * <!-- In plain text: Type x S -> R -->
06bc494ca11e Initial load
duke
parents:
diff changeset
  2434
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
  2435
     * @param <R> the return type of the operation implemented by this
06bc494ca11e Initial load
duke
parents:
diff changeset
  2436
     * visitor; use Void if no return type is needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2437
     * @param <S> the type of the second argument (the first being the
06bc494ca11e Initial load
duke
parents:
diff changeset
  2438
     * type itself) of the operation implemented by this visitor; use
06bc494ca11e Initial load
duke
parents:
diff changeset
  2439
     * Void if a second argument is not needed.
06bc494ca11e Initial load
duke
parents:
diff changeset
  2440
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
  2441
    public interface Visitor<R,S> {
06bc494ca11e Initial load
duke
parents:
diff changeset
  2442
        R visitClassType(ClassType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2443
        R visitWildcardType(WildcardType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2444
        R visitArrayType(ArrayType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2445
        R visitMethodType(MethodType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2446
        R visitPackageType(PackageType t, S s);
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35348
diff changeset
  2447
        R visitModuleType(ModuleType t, S s);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
  2448
        R visitTypeVar(TypeVar t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2449
        R visitCapturedType(CapturedType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2450
        R visitForAll(ForAll t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2451
        R visitUndetVar(UndetVar t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2452
        R visitErrorType(ErrorType t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2453
        R visitType(Type t, S s);
06bc494ca11e Initial load
duke
parents:
diff changeset
  2454
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
  2455
}