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