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