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