duke@1: /*
jjg@1521: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
duke@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1: *
duke@1: * This code is free software; you can redistribute it and/or modify it
duke@1: * under the terms of the GNU General Public License version 2 only, as
ohair@554: * published by the Free Software Foundation. Oracle designates this
duke@1: * particular file as subject to the "Classpath" exception as provided
ohair@554: * by Oracle in the LICENSE file that accompanied this code.
duke@1: *
duke@1: * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1: * version 2 for more details (a copy is included in the LICENSE file that
duke@1: * accompanied this code).
duke@1: *
duke@1: * You should have received a copy of the GNU General Public License version
duke@1: * 2 along with this work; if not, write to the Free Software Foundation,
duke@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1: *
ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554: * or visit www.oracle.com if you need additional information or have any
ohair@554: * questions.
duke@1: */
duke@1:
duke@1: package com.sun.tools.javac.code;
duke@1:
jjg@1645: import java.lang.annotation.Annotation;
jjg@988: import java.util.Collections;
mcimadamore@1338: import java.util.EnumMap;
mcimadamore@1338: import java.util.EnumSet;
mcimadamore@1338: import java.util.Map;
mcimadamore@1338: import java.util.Set;
mcimadamore@1342:
duke@1: import javax.lang.model.type.*;
duke@1:
jjg@1357: import com.sun.tools.javac.code.Symbol.*;
jjg@1755: import com.sun.tools.javac.model.JavacAnnoConstructs;
jjg@1357: import com.sun.tools.javac.util.*;
mcimadamore@1342: import static com.sun.tools.javac.code.BoundKind.*;
duke@1: import static com.sun.tools.javac.code.Flags.*;
duke@1: import static com.sun.tools.javac.code.Kinds.*;
jjg@1374: import static com.sun.tools.javac.code.TypeTag.*;
duke@1:
duke@1: /** This class represents Java types. The class itself defines the behavior of
duke@1: * the following types:
duke@1: *
duke@1: * base types (tags: BYTE, CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, BOOLEAN),
duke@1: * type `void' (tag: VOID),
duke@1: * the bottom type (tag: BOT),
duke@1: * the missing type (tag: NONE).
duke@1: *
duke@1: * The behavior of the following types is defined in subclasses, which are
duke@1: * all static inner classes of this class:
duke@1: *
duke@1: * class types (tag: CLASS, class: ClassType),
duke@1: * array types (tag: ARRAY, class: ArrayType),
duke@1: * method types (tag: METHOD, class: MethodType),
duke@1: * package types (tag: PACKAGE, class: PackageType),
duke@1: * type variables (tag: TYPEVAR, class: TypeVar),
duke@1: * type arguments (tag: WILDCARD, class: WildcardType),
mcimadamore@1268: * generic method types (tag: FORALL, class: ForAll),
duke@1: * the error type (tag: ERROR, class: ErrorType).
duke@1: *
duke@1: *
jjg@581: * This is NOT part of any supported API.
jjg@581: * If you write code that depends on this, you do so at your own risk.
duke@1: * This code and its internal interfaces are subject to change or
duke@1: * deletion without notice.
duke@1: *
jjg@1374: * @see TypeTag
duke@1: */
vromero@1853: public abstract class Type implements TypeMirror {
duke@1:
duke@1: /** Constant type: no type at all. */
vromero@1853: public static final JCNoType noType = new JCNoType();
duke@1:
mcimadamore@1347: /** Constant type: special type to be used during recovery of deferred expressions. */
vromero@1853: public static final JCNoType recoveryType = new JCNoType();
mcimadamore@1347:
duke@1: /** If this switch is turned on, the names of type variables
duke@1: * and anonymous classes are printed with hashcodes appended.
duke@1: */
duke@1: public static boolean moreInfo = false;
duke@1:
jjg@1521: /** The defining class / interface / package / type variable.
duke@1: */
duke@1: public TypeSymbol tsym;
duke@1:
duke@1: /**
jjg@1374: * Checks if the current type tag is equal to the given tag.
jjg@1374: * @return true if tag is equal to the current type tag.
jjg@1374: */
jjg@1374: public boolean hasTag(TypeTag tag) {
vromero@1853: return tag == getTag();
jjg@1374: }
jjg@1374:
jjg@1374: /**
jjg@1374: * Returns the current type tag.
jjg@1374: * @return the value of the current type tag.
jjg@1374: */
vromero@1853: public abstract TypeTag getTag();
jjg@1374:
jjg@1374: public boolean isNumeric() {
vromero@1853: return false;
jjg@1374: }
jjg@1374:
jjg@1374: public boolean isPrimitive() {
vromero@1853: return false;
jjg@1374: }
jjg@1374:
jjg@1374: public boolean isPrimitiveOrVoid() {
vromero@1853: return false;
jjg@1374: }
jjg@1374:
jjg@1374: public boolean isReference() {
vromero@1853: return false;
jjg@1374: }
jjg@1374:
jjg@1374: public boolean isNullOrReference() {
vromero@1853: return false;
jjg@1374: }
jjg@1374:
jjg@1374: public boolean isPartial() {
vromero@1853: return false;
jjg@1374: }
jjg@1374:
jjg@1374: /**
duke@1: * The constant value of this type, null if this type does not
duke@1: * have a constant value attribute. Only primitive types and
duke@1: * strings (ClassType) can have a constant value attribute.
duke@1: * @return the constant value attribute of this type
duke@1: */
duke@1: public Object constValue() {
duke@1: return null;
duke@1: }
duke@1:
vromero@1853: /** Is this a constant type whose value is false?
vromero@1853: */
vromero@1853: public boolean isFalse() {
vromero@1853: return false;
vromero@1853: }
vromero@1853:
vromero@1853: /** Is this a constant type whose value is true?
vromero@1853: */
vromero@1853: public boolean isTrue() {
vromero@1853: return false;
vromero@1853: }
vromero@1853:
jjg@904: /**
jjg@904: * Get the representation of this type used for modelling purposes.
jjg@904: * By default, this is itself. For ErrorType, a different value
jjg@1521: * may be provided.
jjg@904: */
jjg@904: public Type getModelType() {
jjg@904: return this;
jjg@904: }
jjg@904:
jjg@904: public static List getModelTypes(List ts) {
vromero@1853: ListBuffer lb = new ListBuffer<>();
jjg@904: for (Type t: ts)
jjg@904: lb.append(t.getModelType());
jjg@904: return lb.toList();
jjg@904: }
jjg@904:
duke@1: public R accept(Type.Visitor v, S s) { return v.visitType(this, s); }
duke@1:
duke@1: /** Define a type given its tag and type symbol
duke@1: */
vromero@1853: public Type(TypeSymbol tsym) {
duke@1: this.tsym = tsym;
duke@1: }
duke@1:
duke@1: /** An abstract class for mappings from types to types
duke@1: */
duke@1: public static abstract class Mapping {
duke@1: private String name;
duke@1: public Mapping(String name) {
duke@1: this.name = name;
duke@1: }
duke@1: public abstract Type apply(Type t);
duke@1: public String toString() {
duke@1: return name;
duke@1: }
duke@1: }
duke@1:
duke@1: /** map a type function over all immediate descendants of this type
duke@1: */
duke@1: public Type map(Mapping f) {
duke@1: return this;
duke@1: }
duke@1:
duke@1: /** map a type function over a list of types
duke@1: */
duke@1: public static List map(List ts, Mapping f) {
duke@1: if (ts.nonEmpty()) {
duke@1: List tail1 = map(ts.tail, f);
duke@1: Type t = f.apply(ts.head);
duke@1: if (tail1 != ts.tail || t != ts.head)
duke@1: return tail1.prepend(t);
duke@1: }
duke@1: return ts;
duke@1: }
duke@1:
duke@1: /** Define a constant type, of the same kind as this type
duke@1: * and with given constant value
duke@1: */
duke@1: public Type constType(Object constValue) {
vromero@1853: throw new AssertionError();
duke@1: }
duke@1:
duke@1: /**
duke@1: * If this is a constant type, return its underlying type.
duke@1: * Otherwise, return the type itself.
duke@1: */
duke@1: public Type baseType() {
duke@1: return this;
duke@1: }
duke@1:
jjg@1644: public boolean isAnnotated() {
jjg@1644: return false;
jjg@1644: }
jjg@1644:
jjg@1521: /**
jjg@1521: * If this is an annotated type, return the underlying type.
jjg@1521: * Otherwise, return the type itself.
jjg@1521: */
jjg@1521: public Type unannotatedType() {
jjg@1521: return this;
jjg@1521: }
jjg@1521:
jjg@1645: @Override
jjg@1645: public List extends Attribute.TypeCompound> getAnnotationMirrors() {
jjg@1645: return List.nil();
jjg@1645: }
jjg@1645:
jjg@1645: @Override
jjg@1645: public A getAnnotation(Class annotationType) {
jjg@1645: return null;
jjg@1645: }
jjg@1645:
jjg@1645: @Override
jjg@1645: public A[] getAnnotationsByType(Class annotationType) {
jjg@1645: @SuppressWarnings("unchecked")
jjg@1645: A[] tmp = (A[]) java.lang.reflect.Array.newInstance(annotationType, 0);
jjg@1645: return tmp;
jjg@1645: }
jjg@1645:
duke@1: /** Return the base types of a list of types.
duke@1: */
duke@1: public static List baseTypes(List ts) {
duke@1: if (ts.nonEmpty()) {
duke@1: Type t = ts.head.baseType();
duke@1: List baseTypes = baseTypes(ts.tail);
duke@1: if (t != ts.head || baseTypes != ts.tail)
duke@1: return baseTypes.prepend(t);
duke@1: }
duke@1: return ts;
duke@1: }
duke@1:
duke@1: /** The Java source which this type represents.
duke@1: */
duke@1: public String toString() {
duke@1: String s = (tsym == null || tsym.name == null)
duke@1: ? ""
duke@1: : tsym.name.toString();
vromero@1853: if (moreInfo && hasTag(TYPEVAR)) {
vromero@1853: s = s + hashCode();
vromero@1853: }
duke@1: return s;
duke@1: }
duke@1:
duke@1: /**
duke@1: * The Java source which this type list represents. A List is
duke@1: * represented as a comma-spearated listing of the elements in
duke@1: * that list.
duke@1: */
duke@1: public static String toString(List ts) {
duke@1: if (ts.isEmpty()) {
duke@1: return "";
duke@1: } else {
jjg@904: StringBuilder buf = new StringBuilder();
duke@1: buf.append(ts.head.toString());
duke@1: for (List l = ts.tail; l.nonEmpty(); l = l.tail)
duke@1: buf.append(",").append(l.head.toString());
duke@1: return buf.toString();
duke@1: }
duke@1: }
duke@1:
duke@1: /**
duke@1: * The constant value of this type, converted to String
duke@1: */
duke@1: public String stringValue() {
jjg@816: Object cv = Assert.checkNonNull(constValue());
vromero@1853: return cv.toString();
duke@1: }
duke@1:
duke@1: /**
duke@1: * This method is analogous to isSameType, but weaker, since we
duke@1: * never complete classes. Where isSameType would complete a
duke@1: * class, equals assumes that the two types are different.
duke@1: */
vromero@1452: @Override
duke@1: public boolean equals(Object t) {
duke@1: return super.equals(t);
duke@1: }
duke@1:
vromero@1452: @Override
duke@1: public int hashCode() {
duke@1: return super.hashCode();
duke@1: }
duke@1:
duke@1: public String argtypes(boolean varargs) {
duke@1: List args = getParameterTypes();
duke@1: if (!varargs) return args.toString();
jjg@789: StringBuilder buf = new StringBuilder();
duke@1: while (args.tail.nonEmpty()) {
duke@1: buf.append(args.head);
duke@1: args = args.tail;
duke@1: buf.append(',');
duke@1: }
vromero@1853: if (args.head.unannotatedType().hasTag(ARRAY)) {
jjg@1521: buf.append(((ArrayType)args.head.unannotatedType()).elemtype);
jjg@1645: if (args.head.getAnnotationMirrors().nonEmpty()) {
jjg@1645: buf.append(args.head.getAnnotationMirrors());
jjg@1521: }
duke@1: buf.append("...");
duke@1: } else {
duke@1: buf.append(args.head);
duke@1: }
duke@1: return buf.toString();
duke@1: }
duke@1:
duke@1: /** Access methods.
duke@1: */
duke@1: public List getTypeArguments() { return List.nil(); }
jjg@1521: public Type getEnclosingType() { return null; }
duke@1: public List getParameterTypes() { return List.nil(); }
duke@1: public Type getReturnType() { return null; }
jjg@1521: public Type getReceiverType() { return null; }
duke@1: public List getThrownTypes() { return List.nil(); }
duke@1: public Type getUpperBound() { return null; }
duke@1: public Type getLowerBound() { return null; }
duke@1:
duke@1: /** Navigation methods, these will work for classes, type variables,
duke@1: * foralls, but will return null for arrays and methods.
duke@1: */
duke@1:
duke@1: /** Return all parameters of this type and all its outer types in order
duke@1: * outer (first) to inner (last).
duke@1: */
duke@1: public List allparams() { return List.nil(); }
duke@1:
duke@1: /** Does this type contain "error" elements?
duke@1: */
duke@1: public boolean isErroneous() {
duke@1: return false;
duke@1: }
duke@1:
duke@1: public static boolean isErroneous(List ts) {
duke@1: for (List l = ts; l.nonEmpty(); l = l.tail)
duke@1: if (l.head.isErroneous()) return true;
duke@1: return false;
duke@1: }
duke@1:
duke@1: /** Is this type parameterized?
duke@1: * A class type is parameterized if it has some parameters.
duke@1: * An array type is parameterized if its element type is parameterized.
duke@1: * All other types are not parameterized.
duke@1: */
duke@1: public boolean isParameterized() {
duke@1: return false;
duke@1: }
duke@1:
duke@1: /** Is this type a raw type?
duke@1: * A class type is a raw type if it misses some of its parameters.
duke@1: * An array type is a raw type if its element type is raw.
duke@1: * All other types are not raw.
duke@1: * Type validation will ensure that the only raw types
duke@1: * in a program are types that miss all their type variables.
duke@1: */
duke@1: public boolean isRaw() {
duke@1: return false;
duke@1: }
duke@1:
duke@1: public boolean isCompound() {
duke@1: return tsym.completer == null
duke@1: // Compound types can't have a completer. Calling
duke@1: // flags() will complete the symbol causing the
duke@1: // compiler to load classes unnecessarily. This led
duke@1: // to regression 6180021.
duke@1: && (tsym.flags() & COMPOUND) != 0;
duke@1: }
duke@1:
duke@1: public boolean isInterface() {
duke@1: return (tsym.flags() & INTERFACE) != 0;
duke@1: }
duke@1:
mcimadamore@640: public boolean isFinal() {
mcimadamore@640: return (tsym.flags() & FINAL) != 0;
mcimadamore@640: }
mcimadamore@640:
duke@1: /**
duke@1: * Does this type contain occurrences of type t?
duke@1: */
duke@1: public boolean contains(Type t) {
duke@1: return t == this;
duke@1: }
duke@1:
duke@1: public static boolean contains(List ts, Type t) {
duke@1: for (List l = ts;
duke@1: l.tail != null /*inlined: l.nonEmpty()*/;
duke@1: l = l.tail)
duke@1: if (l.head.contains(t)) return true;
duke@1: return false;
duke@1: }
duke@1:
mcimadamore@635: /** Does this type contain an occurrence of some type in 'ts'?
duke@1: */
mcimadamore@635: public boolean containsAny(List ts) {
mcimadamore@635: for (Type t : ts)
mcimadamore@635: if (this.contains(t)) return true;
mcimadamore@635: return false;
mcimadamore@635: }
mcimadamore@635:
mcimadamore@635: public static boolean containsAny(List ts1, List ts2) {
mcimadamore@635: for (Type t : ts1)
mcimadamore@635: if (t.containsAny(ts2)) return true;
duke@1: return false;
duke@1: }
duke@1:
mcimadamore@828: public static List filter(List ts, Filter tf) {
mcimadamore@828: ListBuffer buf = ListBuffer.lb();
mcimadamore@828: for (Type t : ts) {
mcimadamore@828: if (tf.accepts(t)) {
mcimadamore@828: buf.append(t);
mcimadamore@828: }
mcimadamore@828: }
mcimadamore@828: return buf.toList();
mcimadamore@828: }
mcimadamore@828:
duke@1: public boolean isSuperBound() { return false; }
duke@1: public boolean isExtendsBound() { return false; }
duke@1: public boolean isUnbound() { return false; }
duke@1: public Type withTypeVar(Type t) { return this; }
duke@1:
duke@1: /** The underlying method type of this type.
duke@1: */
duke@1: public MethodType asMethodType() { throw new AssertionError(); }
duke@1:
duke@1: /** Complete loading all classes in this type.
duke@1: */
duke@1: public void complete() {}
duke@1:
duke@1: public TypeSymbol asElement() {
duke@1: return tsym;
duke@1: }
duke@1:
vromero@1853: @Override
duke@1: public TypeKind getKind() {
vromero@1853: return TypeKind.OTHER;
duke@1: }
duke@1:
vromero@1853: @Override
duke@1: public R accept(TypeVisitor v, P p) {
vromero@1853: throw new AssertionError();
vromero@1853: }
vromero@1853:
vromero@1853: public static class JCPrimitiveType extends Type
vromero@1853: implements javax.lang.model.type.PrimitiveType {
vromero@1853:
vromero@1853: TypeTag tag;
vromero@1853:
vromero@1853: public JCPrimitiveType(TypeTag tag, TypeSymbol tsym) {
vromero@1853: super(tsym);
vromero@1853: this.tag = tag;
vromero@1853: Assert.check(tag.isPrimitive);
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isNumeric() {
vromero@1853: return tag != BOOLEAN;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isPrimitive() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return tag;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isPrimitiveOrVoid() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: /** Define a constant type, of the same kind as this type
vromero@1853: * and with given constant value
vromero@1853: */
vromero@1853: @Override
vromero@1853: public Type constType(Object constValue) {
vromero@1853: final Object value = constValue;
vromero@1853: return new JCPrimitiveType(tag, tsym) {
vromero@1853: @Override
vromero@1853: public Object constValue() {
vromero@1853: return value;
vromero@1853: }
vromero@1853: @Override
vromero@1853: public Type baseType() {
vromero@1853: return tsym.type;
vromero@1853: }
vromero@1853: };
vromero@1853: }
vromero@1853:
vromero@1853: /**
vromero@1853: * The constant value of this type, converted to String
vromero@1853: */
vromero@1853: @Override
vromero@1853: public String stringValue() {
vromero@1853: Object cv = Assert.checkNonNull(constValue());
vromero@1853: if (tag == BOOLEAN) {
vromero@1853: return ((Integer) cv).intValue() == 0 ? "false" : "true";
vromero@1853: }
vromero@1853: else if (tag == CHAR) {
vromero@1853: return String.valueOf((char) ((Integer) cv).intValue());
vromero@1853: }
vromero@1853: else {
vromero@1853: return cv.toString();
vromero@1853: }
vromero@1853: }
vromero@1853:
vromero@1853: /** Is this a constant type whose value is false?
vromero@1853: */
vromero@1853: @Override
vromero@1853: public boolean isFalse() {
vromero@1853: return
vromero@1853: tag == BOOLEAN &&
vromero@1853: constValue() != null &&
vromero@1853: ((Integer)constValue()).intValue() == 0;
vromero@1853: }
vromero@1853:
vromero@1853: /** Is this a constant type whose value is true?
vromero@1853: */
vromero@1853: @Override
vromero@1853: public boolean isTrue() {
vromero@1853: return
vromero@1853: tag == BOOLEAN &&
vromero@1853: constValue() != null &&
vromero@1853: ((Integer)constValue()).intValue() != 0;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitPrimitive(this, p);
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public TypeKind getKind() {
vromero@1853: switch (tag) {
vromero@1853: case BYTE: return TypeKind.BYTE;
vromero@1853: case CHAR: return TypeKind.CHAR;
vromero@1853: case SHORT: return TypeKind.SHORT;
vromero@1853: case INT: return TypeKind.INT;
vromero@1853: case LONG: return TypeKind.LONG;
vromero@1853: case FLOAT: return TypeKind.FLOAT;
vromero@1853: case DOUBLE: return TypeKind.DOUBLE;
vromero@1853: case BOOLEAN: return TypeKind.BOOLEAN;
vromero@1853: }
duke@1: throw new AssertionError();
vromero@1853: }
vromero@1853:
duke@1: }
duke@1:
duke@1: public static class WildcardType extends Type
duke@1: implements javax.lang.model.type.WildcardType {
duke@1:
duke@1: public Type type;
duke@1: public BoundKind kind;
duke@1: public TypeVar bound;
duke@1:
duke@1: @Override
duke@1: public R accept(Type.Visitor v, S s) {
duke@1: return v.visitWildcardType(this, s);
duke@1: }
duke@1:
duke@1: public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
vromero@1853: super(tsym);
jjg@816: this.type = Assert.checkNonNull(type);
duke@1: this.kind = kind;
duke@1: }
duke@1: public WildcardType(WildcardType t, TypeVar bound) {
duke@1: this(t.type, t.kind, t.tsym, bound);
duke@1: }
duke@1:
duke@1: public WildcardType(Type type, BoundKind kind, TypeSymbol tsym, TypeVar bound) {
duke@1: this(type, kind, tsym);
duke@1: this.bound = bound;
duke@1: }
duke@1:
vromero@1853: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return WILDCARD;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
mcimadamore@635: public boolean contains(Type t) {
mcimadamore@635: return kind != UNBOUND && type.contains(t);
mcimadamore@635: }
mcimadamore@635:
duke@1: public boolean isSuperBound() {
duke@1: return kind == SUPER ||
duke@1: kind == UNBOUND;
duke@1: }
duke@1: public boolean isExtendsBound() {
duke@1: return kind == EXTENDS ||
duke@1: kind == UNBOUND;
duke@1: }
duke@1: public boolean isUnbound() {
duke@1: return kind == UNBOUND;
duke@1: }
duke@1:
vromero@1853: @Override
vromero@1853: public boolean isReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isNullOrReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
duke@1: public Type withTypeVar(Type t) {
duke@1: //-System.err.println(this+".withTypeVar("+t+");");//DEBUG
duke@1: if (bound == t)
duke@1: return this;
duke@1: bound = (TypeVar)t;
duke@1: return this;
duke@1: }
duke@1:
duke@1: boolean isPrintingBound = false;
duke@1: public String toString() {
jjg@904: StringBuilder s = new StringBuilder();
duke@1: s.append(kind.toString());
duke@1: if (kind != UNBOUND)
duke@1: s.append(type);
duke@1: if (moreInfo && bound != null && !isPrintingBound)
duke@1: try {
duke@1: isPrintingBound = true;
duke@1: s.append("{:").append(bound.bound).append(":}");
duke@1: } finally {
duke@1: isPrintingBound = false;
duke@1: }
duke@1: return s.toString();
duke@1: }
duke@1:
duke@1: public Type map(Mapping f) {
duke@1: //- System.err.println(" (" + this + ").map(" + f + ")");//DEBUG
duke@1: Type t = type;
duke@1: if (t != null)
duke@1: t = f.apply(t);
duke@1: if (t == type)
duke@1: return this;
duke@1: else
duke@1: return new WildcardType(t, kind, tsym, bound);
duke@1: }
duke@1:
duke@1: public Type getExtendsBound() {
duke@1: if (kind == EXTENDS)
duke@1: return type;
duke@1: else
duke@1: return null;
duke@1: }
duke@1:
duke@1: public Type getSuperBound() {
duke@1: if (kind == SUPER)
duke@1: return type;
duke@1: else
duke@1: return null;
duke@1: }
duke@1:
duke@1: public TypeKind getKind() {
duke@1: return TypeKind.WILDCARD;
duke@1: }
duke@1:
duke@1: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitWildcard(this, p);
duke@1: }
duke@1: }
duke@1:
duke@1: public static class ClassType extends Type implements DeclaredType {
duke@1:
duke@1: /** The enclosing type of this type. If this is the type of an inner
duke@1: * class, outer_field refers to the type of its enclosing
jjg@1521: * instance class, in all other cases it refers to noType.
duke@1: */
duke@1: private Type outer_field;
duke@1:
duke@1: /** The type parameters of this type (to be set once class is loaded).
duke@1: */
duke@1: public List typarams_field;
duke@1:
duke@1: /** A cache variable for the type parameters of this type,
duke@1: * appended to all parameters of its enclosing class.
duke@1: * @see #allparams
duke@1: */
duke@1: public List allparams_field;
duke@1:
duke@1: /** The supertype of this class (to be set once class is loaded).
duke@1: */
duke@1: public Type supertype_field;
duke@1:
duke@1: /** The interfaces of this class (to be set once class is loaded).
duke@1: */
duke@1: public List interfaces_field;
duke@1:
jjg@904: /** All the interfaces of this class, including missing ones.
jjg@904: */
jjg@904: public List all_interfaces_field;
jjg@904:
duke@1: public ClassType(Type outer, List typarams, TypeSymbol tsym) {
vromero@1853: super(tsym);
duke@1: this.outer_field = outer;
duke@1: this.typarams_field = typarams;
duke@1: this.allparams_field = null;
duke@1: this.supertype_field = null;
duke@1: this.interfaces_field = null;
duke@1: /*
duke@1: // this can happen during error recovery
duke@1: assert
duke@1: outer.isParameterized() ?
duke@1: typarams.length() == tsym.type.typarams().length() :
duke@1: outer.isRaw() ?
duke@1: typarams.length() == 0 :
duke@1: true;
duke@1: */
duke@1: }
duke@1:
duke@1: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return CLASS;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
duke@1: public R accept(Type.Visitor v, S s) {
duke@1: return v.visitClassType(this, s);
duke@1: }
duke@1:
duke@1: public Type constType(Object constValue) {
duke@1: final Object value = constValue;
duke@1: return new ClassType(getEnclosingType(), typarams_field, tsym) {
duke@1: @Override
duke@1: public Object constValue() {
duke@1: return value;
duke@1: }
duke@1: @Override
duke@1: public Type baseType() {
duke@1: return tsym.type;
duke@1: }
duke@1: };
duke@1: }
duke@1:
duke@1: /** The Java source which this type represents.
duke@1: */
duke@1: public String toString() {
jjg@904: StringBuilder buf = new StringBuilder();
vromero@1853: if (getEnclosingType().hasTag(CLASS) && tsym.owner.kind == TYP) {
duke@1: buf.append(getEnclosingType().toString());
duke@1: buf.append(".");
duke@1: buf.append(className(tsym, false));
duke@1: } else {
duke@1: buf.append(className(tsym, true));
duke@1: }
duke@1: if (getTypeArguments().nonEmpty()) {
duke@1: buf.append('<');
duke@1: buf.append(getTypeArguments().toString());
duke@1: buf.append(">");
duke@1: }
duke@1: return buf.toString();
duke@1: }
duke@1: //where
duke@1: private String className(Symbol sym, boolean longform) {
jjg@113: if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) {
jjg@904: StringBuilder s = new StringBuilder(supertype_field.toString());
duke@1: for (List is=interfaces_field; is.nonEmpty(); is = is.tail) {
duke@1: s.append("&");
duke@1: s.append(is.head.toString());
duke@1: }
duke@1: return s.toString();
jjg@113: } else if (sym.name.isEmpty()) {
duke@1: String s;
jjg@1755: ClassType norm = (ClassType) tsym.type.unannotatedType();
duke@1: if (norm == null) {
duke@1: s = Log.getLocalizedString("anonymous.class", (Object)null);
duke@1: } else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
duke@1: s = Log.getLocalizedString("anonymous.class",
duke@1: norm.interfaces_field.head);
duke@1: } else {
duke@1: s = Log.getLocalizedString("anonymous.class",
duke@1: norm.supertype_field);
duke@1: }
duke@1: if (moreInfo)
duke@1: s += String.valueOf(sym.hashCode());
duke@1: return s;
duke@1: } else if (longform) {
duke@1: return sym.getQualifiedName().toString();
duke@1: } else {
duke@1: return sym.name.toString();
duke@1: }
duke@1: }
duke@1:
duke@1: public List getTypeArguments() {
duke@1: if (typarams_field == null) {
duke@1: complete();
duke@1: if (typarams_field == null)
duke@1: typarams_field = List.nil();
duke@1: }
duke@1: return typarams_field;
duke@1: }
duke@1:
mcimadamore@30: public boolean hasErasedSupertypes() {
mcimadamore@30: return isRaw();
mcimadamore@30: }
mcimadamore@30:
duke@1: public Type getEnclosingType() {
duke@1: return outer_field;
duke@1: }
duke@1:
duke@1: public void setEnclosingType(Type outer) {
duke@1: outer_field = outer;
duke@1: }
duke@1:
duke@1: public List allparams() {
duke@1: if (allparams_field == null) {
duke@1: allparams_field = getTypeArguments().prependList(getEnclosingType().allparams());
duke@1: }
duke@1: return allparams_field;
duke@1: }
duke@1:
duke@1: public boolean isErroneous() {
duke@1: return
duke@1: getEnclosingType().isErroneous() ||
duke@1: isErroneous(getTypeArguments()) ||
jjg@1755: this != tsym.type.unannotatedType() && tsym.type.isErroneous();
duke@1: }
duke@1:
duke@1: public boolean isParameterized() {
duke@1: return allparams().tail != null;
duke@1: // optimization, was: allparams().nonEmpty();
duke@1: }
duke@1:
vromero@1853: @Override
vromero@1853: public boolean isReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isNullOrReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
duke@1: /** A cache for the rank. */
duke@1: int rank_field = -1;
duke@1:
duke@1: /** A class type is raw if it misses some
duke@1: * of its type parameter sections.
duke@1: * After validation, this is equivalent to:
jjg@1326: * {@code allparams.isEmpty() && tsym.type.allparams.nonEmpty(); }
duke@1: */
duke@1: public boolean isRaw() {
duke@1: return
duke@1: this != tsym.type && // necessary, but not sufficient condition
duke@1: tsym.type.allparams().nonEmpty() &&
duke@1: allparams().isEmpty();
duke@1: }
duke@1:
duke@1: public Type map(Mapping f) {
duke@1: Type outer = getEnclosingType();
duke@1: Type outer1 = f.apply(outer);
duke@1: List typarams = getTypeArguments();
duke@1: List typarams1 = map(typarams, f);
duke@1: if (outer1 == outer && typarams1 == typarams) return this;
duke@1: else return new ClassType(outer1, typarams1, tsym);
duke@1: }
duke@1:
duke@1: public boolean contains(Type elem) {
duke@1: return
duke@1: elem == this
duke@1: || (isParameterized()
mcimadamore@635: && (getEnclosingType().contains(elem) || contains(getTypeArguments(), elem)))
mcimadamore@635: || (isCompound()
mcimadamore@635: && (supertype_field.contains(elem) || contains(interfaces_field, elem)));
duke@1: }
duke@1:
duke@1: public void complete() {
duke@1: if (tsym.completer != null) tsym.complete();
duke@1: }
duke@1:
duke@1: public TypeKind getKind() {
duke@1: return TypeKind.DECLARED;
duke@1: }
duke@1:
duke@1: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitDeclared(this, p);
duke@1: }
duke@1: }
duke@1:
mcimadamore@30: public static class ErasedClassType extends ClassType {
mcimadamore@30: public ErasedClassType(Type outer, TypeSymbol tsym) {
mcimadamore@30: super(outer, List.nil(), tsym);
mcimadamore@30: }
mcimadamore@30:
mcimadamore@30: @Override
mcimadamore@30: public boolean hasErasedSupertypes() {
mcimadamore@30: return true;
mcimadamore@30: }
mcimadamore@30: }
mcimadamore@30:
jjg@988: // a clone of a ClassType that knows about the alternatives of a union type.
jjg@988: public static class UnionClassType extends ClassType implements UnionType {
jjg@988: final List extends Type> alternatives_field;
jjg@988:
jjg@988: public UnionClassType(ClassType ct, List extends Type> alternatives) {
jjg@988: super(ct.outer_field, ct.typarams_field, ct.tsym);
jjg@988: allparams_field = ct.allparams_field;
jjg@988: supertype_field = ct.supertype_field;
jjg@988: interfaces_field = ct.interfaces_field;
jjg@988: all_interfaces_field = ct.interfaces_field;
jjg@988: alternatives_field = alternatives;
jjg@988: }
jjg@988:
jjg@988: public Type getLub() {
jjg@988: return tsym.type;
jjg@988: }
jjg@988:
jjg@988: public java.util.List extends TypeMirror> getAlternatives() {
jjg@988: return Collections.unmodifiableList(alternatives_field);
jjg@988: }
jjg@988:
jjg@988: @Override
jjg@988: public TypeKind getKind() {
jjg@988: return TypeKind.UNION;
jjg@988: }
jjg@988:
jjg@988: @Override
jjg@988: public R accept(TypeVisitor v, P p) {
jjg@988: return v.visitUnion(this, p);
jjg@988: }
jjg@988: }
jjg@988:
mcimadamore@1436: // a clone of a ClassType that knows about the bounds of an intersection type.
mcimadamore@1436: public static class IntersectionClassType extends ClassType implements IntersectionType {
mcimadamore@1436:
mcimadamore@1436: public boolean allInterfaces;
mcimadamore@1436:
mcimadamore@1436: public enum IntersectionKind {
mcimadamore@1436: EXPLICIT,
mcimadamore@1436: IMPLICT;
mcimadamore@1436: }
mcimadamore@1436:
mcimadamore@1436: public IntersectionKind intersectionKind;
mcimadamore@1436:
mcimadamore@1436: public IntersectionClassType(List bounds, ClassSymbol csym, boolean allInterfaces) {
mcimadamore@1436: super(Type.noType, List.nil(), csym);
mcimadamore@1436: this.allInterfaces = allInterfaces;
mcimadamore@1436: Assert.check((csym.flags() & COMPOUND) != 0);
mcimadamore@1436: supertype_field = bounds.head;
mcimadamore@1436: interfaces_field = bounds.tail;
mcimadamore@1436: Assert.check(supertype_field.tsym.completer != null ||
mcimadamore@1436: !supertype_field.isInterface(), supertype_field);
mcimadamore@1436: }
mcimadamore@1436:
mcimadamore@1436: public java.util.List extends TypeMirror> getBounds() {
mcimadamore@1436: return Collections.unmodifiableList(getComponents());
mcimadamore@1436: }
mcimadamore@1436:
mcimadamore@1436: public List getComponents() {
mcimadamore@1436: return interfaces_field.prepend(supertype_field);
mcimadamore@1436: }
mcimadamore@1436:
mcimadamore@1678: public List getExplicitComponents() {
mcimadamore@1678: return allInterfaces ?
mcimadamore@1678: interfaces_field :
mcimadamore@1678: getComponents();
mcimadamore@1678: }
mcimadamore@1678:
mcimadamore@1436: @Override
mcimadamore@1436: public TypeKind getKind() {
mcimadamore@1436: return TypeKind.INTERSECTION;
mcimadamore@1436: }
mcimadamore@1436:
mcimadamore@1436: @Override
mcimadamore@1436: public R accept(TypeVisitor v, P p) {
mcimadamore@1436: return intersectionKind == IntersectionKind.EXPLICIT ?
mcimadamore@1436: v.visitIntersection(this, p) :
mcimadamore@1436: v.visitDeclared(this, p);
mcimadamore@1436: }
mcimadamore@1436: }
mcimadamore@1436:
duke@1: public static class ArrayType extends Type
duke@1: implements javax.lang.model.type.ArrayType {
duke@1:
duke@1: public Type elemtype;
duke@1:
duke@1: public ArrayType(Type elemtype, TypeSymbol arrayClass) {
vromero@1853: super(arrayClass);
duke@1: this.elemtype = elemtype;
duke@1: }
duke@1:
duke@1: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return ARRAY;
vromero@1853: }
vromero@1853:
duke@1: public R accept(Type.Visitor v, S s) {
duke@1: return v.visitArrayType(this, s);
duke@1: }
duke@1:
duke@1: public String toString() {
duke@1: return elemtype + "[]";
duke@1: }
duke@1:
duke@1: public boolean equals(Object obj) {
duke@1: return
duke@1: this == obj ||
duke@1: (obj instanceof ArrayType &&
duke@1: this.elemtype.equals(((ArrayType)obj).elemtype));
duke@1: }
duke@1:
duke@1: public int hashCode() {
jjg@1374: return (ARRAY.ordinal() << 5) + elemtype.hashCode();
duke@1: }
duke@1:
mcimadamore@795: public boolean isVarargs() {
mcimadamore@795: return false;
mcimadamore@795: }
mcimadamore@795:
duke@1: public List allparams() { return elemtype.allparams(); }
duke@1:
duke@1: public boolean isErroneous() {
duke@1: return elemtype.isErroneous();
duke@1: }
duke@1:
duke@1: public boolean isParameterized() {
duke@1: return elemtype.isParameterized();
duke@1: }
duke@1:
vromero@1853: @Override
vromero@1853: public boolean isReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isNullOrReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
duke@1: public boolean isRaw() {
duke@1: return elemtype.isRaw();
duke@1: }
duke@1:
mcimadamore@795: public ArrayType makeVarargs() {
mcimadamore@795: return new ArrayType(elemtype, tsym) {
mcimadamore@795: @Override
mcimadamore@795: public boolean isVarargs() {
mcimadamore@795: return true;
mcimadamore@795: }
mcimadamore@795: };
mcimadamore@795: }
mcimadamore@795:
duke@1: public Type map(Mapping f) {
duke@1: Type elemtype1 = f.apply(elemtype);
duke@1: if (elemtype1 == elemtype) return this;
duke@1: else return new ArrayType(elemtype1, tsym);
duke@1: }
duke@1:
duke@1: public boolean contains(Type elem) {
duke@1: return elem == this || elemtype.contains(elem);
duke@1: }
duke@1:
duke@1: public void complete() {
duke@1: elemtype.complete();
duke@1: }
duke@1:
duke@1: public Type getComponentType() {
duke@1: return elemtype;
duke@1: }
duke@1:
duke@1: public TypeKind getKind() {
duke@1: return TypeKind.ARRAY;
duke@1: }
duke@1:
duke@1: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitArray(this, p);
duke@1: }
duke@1: }
duke@1:
dlsmith@880: public static class MethodType extends Type implements ExecutableType {
duke@1:
duke@1: public List argtypes;
duke@1: public Type restype;
duke@1: public List thrown;
duke@1:
jjg@1521: /** The type annotations on the method receiver.
jjg@1521: */
jjg@1521: public Type recvtype;
jjg@1521:
duke@1: public MethodType(List argtypes,
duke@1: Type restype,
duke@1: List thrown,
duke@1: TypeSymbol methodClass) {
vromero@1853: super(methodClass);
duke@1: this.argtypes = argtypes;
duke@1: this.restype = restype;
duke@1: this.thrown = thrown;
duke@1: }
duke@1:
duke@1: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return METHOD;
vromero@1853: }
vromero@1853:
duke@1: public R accept(Type.Visitor v, S s) {
duke@1: return v.visitMethodType(this, s);
duke@1: }
duke@1:
duke@1: /** The Java source which this type represents.
duke@1: *
duke@1: * XXX 06/09/99 iris This isn't correct Java syntax, but it probably
duke@1: * should be.
duke@1: */
duke@1: public String toString() {
duke@1: return "(" + argtypes + ")" + restype;
duke@1: }
duke@1:
duke@1: public List getParameterTypes() { return argtypes; }
duke@1: public Type getReturnType() { return restype; }
jjg@1521: public Type getReceiverType() { return recvtype; }
duke@1: public List getThrownTypes() { return thrown; }
duke@1:
duke@1: public boolean isErroneous() {
duke@1: return
duke@1: isErroneous(argtypes) ||
duke@1: restype != null && restype.isErroneous();
duke@1: }
duke@1:
duke@1: public Type map(Mapping f) {
duke@1: List argtypes1 = map(argtypes, f);
duke@1: Type restype1 = f.apply(restype);
duke@1: List thrown1 = map(thrown, f);
duke@1: if (argtypes1 == argtypes &&
duke@1: restype1 == restype &&
duke@1: thrown1 == thrown) return this;
duke@1: else return new MethodType(argtypes1, restype1, thrown1, tsym);
duke@1: }
duke@1:
duke@1: public boolean contains(Type elem) {
duke@1: return elem == this || contains(argtypes, elem) || restype.contains(elem);
duke@1: }
duke@1:
duke@1: public MethodType asMethodType() { return this; }
duke@1:
duke@1: public void complete() {
duke@1: for (List l = argtypes; l.nonEmpty(); l = l.tail)
duke@1: l.head.complete();
duke@1: restype.complete();
jjg@1521: recvtype.complete();
duke@1: for (List l = thrown; l.nonEmpty(); l = l.tail)
duke@1: l.head.complete();
duke@1: }
duke@1:
duke@1: public List getTypeVariables() {
duke@1: return List.nil();
duke@1: }
duke@1:
duke@1: public TypeSymbol asElement() {
duke@1: return null;
duke@1: }
duke@1:
duke@1: public TypeKind getKind() {
duke@1: return TypeKind.EXECUTABLE;
duke@1: }
duke@1:
duke@1: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitExecutable(this, p);
duke@1: }
duke@1: }
duke@1:
duke@1: public static class PackageType extends Type implements NoType {
duke@1:
duke@1: PackageType(TypeSymbol tsym) {
vromero@1853: super(tsym);
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return PACKAGE;
duke@1: }
duke@1:
duke@1: @Override
duke@1: public R accept(Type.Visitor v, S s) {
duke@1: return v.visitPackageType(this, s);
duke@1: }
duke@1:
duke@1: public String toString() {
duke@1: return tsym.getQualifiedName().toString();
duke@1: }
duke@1:
duke@1: public TypeKind getKind() {
duke@1: return TypeKind.PACKAGE;
duke@1: }
duke@1:
duke@1: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitNoType(this, p);
duke@1: }
duke@1: }
duke@1:
duke@1: public static class TypeVar extends Type implements TypeVariable {
duke@1:
jjg@789: /** The upper bound of this type variable; set from outside.
duke@1: * Must be nonempty once it is set.
duke@1: * For a bound, `bound' is the bound type itself.
duke@1: * Multiple bounds are expressed as a single class type which has the
duke@1: * individual bounds as superclass, respectively interfaces.
duke@1: * The class type then has as `tsym' a compiler generated class `c',
duke@1: * which has a flag COMPOUND and whose owner is the type variable
duke@1: * itself. Furthermore, the erasure_field of the class
duke@1: * points to the first class or interface bound.
duke@1: */
duke@1: public Type bound = null;
jjg@789:
jjg@789: /** The lower bound of this type variable.
jjg@789: * TypeVars don't normally have a lower bound, so it is normally set
jjg@789: * to syms.botType.
jjg@789: * Subtypes, such as CapturedType, may provide a different value.
jjg@789: */
duke@1: public Type lower;
duke@1:
duke@1: public TypeVar(Name name, Symbol owner, Type lower) {
vromero@1853: super(null);
jfranck@1689: tsym = new TypeVariableSymbol(0, name, this, owner);
duke@1: this.lower = lower;
duke@1: }
duke@1:
duke@1: public TypeVar(TypeSymbol tsym, Type bound, Type lower) {
vromero@1853: super(tsym);
duke@1: this.bound = bound;
duke@1: this.lower = lower;
duke@1: }
duke@1:
duke@1: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return TYPEVAR;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
duke@1: public R accept(Type.Visitor v, S s) {
duke@1: return v.visitTypeVar(this, s);
duke@1: }
duke@1:
jjg@789: @Override
jjg@1521: public Type getUpperBound() {
vromero@1853: if ((bound == null || bound.hasTag(NONE)) && this != tsym.type) {
jjg@1521: bound = tsym.type.getUpperBound();
vromero@1853: }
jjg@1521: return bound;
jjg@1521: }
duke@1:
duke@1: int rank_field = -1;
duke@1:
jjg@789: @Override
duke@1: public Type getLowerBound() {
duke@1: return lower;
duke@1: }
duke@1:
duke@1: public TypeKind getKind() {
duke@1: return TypeKind.TYPEVAR;
duke@1: }
duke@1:
mcimadamore@79: public boolean isCaptured() {
mcimadamore@79: return false;
mcimadamore@79: }
mcimadamore@79:
vromero@1853: @Override
vromero@1853: public boolean isReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isNullOrReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
duke@1: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitTypeVariable(this, p);
duke@1: }
duke@1: }
duke@1:
duke@1: /** A captured type variable comes from wildcards which can have
duke@1: * both upper and lower bound. CapturedType extends TypeVar with
duke@1: * a lower bound.
duke@1: */
duke@1: public static class CapturedType extends TypeVar {
duke@1:
duke@1: public WildcardType wildcard;
duke@1:
duke@1: public CapturedType(Name name,
duke@1: Symbol owner,
duke@1: Type upper,
duke@1: Type lower,
duke@1: WildcardType wildcard) {
duke@1: super(name, owner, lower);
jjg@816: this.lower = Assert.checkNonNull(lower);
duke@1: this.bound = upper;
duke@1: this.wildcard = wildcard;
duke@1: }
duke@1:
duke@1: @Override
duke@1: public R accept(Type.Visitor v, S s) {
duke@1: return v.visitCapturedType(this, s);
duke@1: }
duke@1:
duke@1: @Override
mcimadamore@79: public boolean isCaptured() {
mcimadamore@79: return true;
mcimadamore@79: }
mcimadamore@79:
mcimadamore@79: @Override
duke@1: public String toString() {
duke@1: return "capture#"
mcimadamore@288: + (hashCode() & 0xFFFFFFFFL) % Printer.PRIME
duke@1: + " of "
duke@1: + wildcard;
duke@1: }
duke@1: }
duke@1:
duke@1: public static abstract class DelegatedType extends Type {
duke@1: public Type qtype;
vromero@1853: public TypeTag tag;
jjg@1374: public DelegatedType(TypeTag tag, Type qtype) {
vromero@1853: super(qtype.tsym);
vromero@1853: this.tag = tag;
duke@1: this.qtype = qtype;
duke@1: }
vromero@1853: public TypeTag getTag() { return tag; }
duke@1: public String toString() { return qtype.toString(); }
duke@1: public List getTypeArguments() { return qtype.getTypeArguments(); }
duke@1: public Type getEnclosingType() { return qtype.getEnclosingType(); }
duke@1: public List getParameterTypes() { return qtype.getParameterTypes(); }
duke@1: public Type getReturnType() { return qtype.getReturnType(); }
jjg@1521: public Type getReceiverType() { return qtype.getReceiverType(); }
duke@1: public List getThrownTypes() { return qtype.getThrownTypes(); }
duke@1: public List allparams() { return qtype.allparams(); }
duke@1: public Type getUpperBound() { return qtype.getUpperBound(); }
duke@1: public boolean isErroneous() { return qtype.isErroneous(); }
duke@1: }
duke@1:
mcimadamore@1268: /**
mcimadamore@1268: * The type of a generic method type. It consists of a method type and
mcimadamore@1268: * a list of method type-parameters that are used within the method
mcimadamore@1268: * type.
mcimadamore@1268: */
dlsmith@880: public static class ForAll extends DelegatedType implements ExecutableType {
duke@1: public List tvars;
duke@1:
duke@1: public ForAll(List tvars, Type qtype) {
mcimadamore@1268: super(FORALL, (MethodType)qtype);
duke@1: this.tvars = tvars;
duke@1: }
duke@1:
duke@1: @Override
duke@1: public R accept(Type.Visitor v, S s) {
duke@1: return v.visitForAll(this, s);
duke@1: }
duke@1:
duke@1: public String toString() {
duke@1: return "<" + tvars + ">" + qtype;
duke@1: }
duke@1:
duke@1: public List getTypeArguments() { return tvars; }
duke@1:
duke@1: public boolean isErroneous() {
duke@1: return qtype.isErroneous();
duke@1: }
duke@1:
duke@1: public Type map(Mapping f) {
duke@1: return f.apply(qtype);
duke@1: }
duke@1:
duke@1: public boolean contains(Type elem) {
duke@1: return qtype.contains(elem);
duke@1: }
duke@1:
duke@1: public MethodType asMethodType() {
mcimadamore@1268: return (MethodType)qtype;
duke@1: }
duke@1:
duke@1: public void complete() {
duke@1: for (List l = tvars; l.nonEmpty(); l = l.tail) {
duke@1: ((TypeVar)l.head).bound.complete();
duke@1: }
duke@1: qtype.complete();
duke@1: }
duke@1:
duke@1: public List getTypeVariables() {
duke@1: return List.convert(TypeVar.class, getTypeArguments());
duke@1: }
duke@1:
duke@1: public TypeKind getKind() {
duke@1: return TypeKind.EXECUTABLE;
duke@1: }
duke@1:
duke@1: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitExecutable(this, p);
duke@1: }
duke@1: }
duke@1:
mcimadamore@1338: /** A class for inference variables, for use during method/diamond type
mcimadamore@1338: * inference. An inference variable has upper/lower bounds and a set
mcimadamore@1338: * of equality constraints. Such bounds are set during subtyping, type-containment,
mcimadamore@1338: * type-equality checks, when the types being tested contain inference variables.
mcimadamore@1338: * A change listener can be attached to an inference variable, to receive notifications
mcimadamore@1338: * whenever the bounds of an inference variable change.
duke@1: */
duke@1: public static class UndetVar extends DelegatedType {
mcimadamore@1338:
mcimadamore@1338: /** Inference variable change listener. The listener method is called
mcimadamore@1338: * whenever a change to the inference variable's bounds occurs
mcimadamore@1338: */
mcimadamore@1338: public interface UndetVarListener {
mcimadamore@1338: /** called when some inference variable bounds (of given kinds ibs) change */
mcimadamore@1338: void varChanged(UndetVar uv, Set ibs);
mcimadamore@1338: }
mcimadamore@1338:
mcimadamore@1338: /**
mcimadamore@1338: * Inference variable bound kinds
mcimadamore@1338: */
mcimadamore@1338: public enum InferenceBound {
mcimadamore@1338: /** upper bounds */
mcimadamore@1338: UPPER,
mcimadamore@1338: /** lower bounds */
mcimadamore@1338: LOWER,
mcimadamore@1338: /** equality constraints */
mcimadamore@1338: EQ;
mcimadamore@1338: }
mcimadamore@1338:
mcimadamore@1338: /** inference variable bounds */
mcimadamore@1338: private Map> bounds;
mcimadamore@1338:
mcimadamore@1338: /** inference variable's inferred type (set from Infer.java) */
duke@1: public Type inst = null;
duke@1:
mcimadamore@1550: /** number of declared (upper) bounds */
mcimadamore@1550: public int declaredCount;
mcimadamore@1550:
mcimadamore@1338: /** inference variable's change listener */
mcimadamore@1338: public UndetVarListener listener = null;
mcimadamore@1338:
duke@1: @Override
duke@1: public R accept(Type.Visitor v, S s) {
duke@1: return v.visitUndetVar(this, s);
duke@1: }
duke@1:
mcimadamore@1338: public UndetVar(TypeVar origin, Types types) {
duke@1: super(UNDETVAR, origin);
mcimadamore@1338: bounds = new EnumMap>(InferenceBound.class);
mcimadamore@1550: List declaredBounds = types.getBounds(origin);
mcimadamore@1550: declaredCount = declaredBounds.length();
mcimadamore@1550: bounds.put(InferenceBound.UPPER, declaredBounds);
mcimadamore@1338: bounds.put(InferenceBound.LOWER, List.nil());
mcimadamore@1338: bounds.put(InferenceBound.EQ, List.nil());
duke@1: }
duke@1:
duke@1: public String toString() {
duke@1: if (inst != null) return inst.toString();
duke@1: else return qtype + "?";
duke@1: }
duke@1:
vromero@1853: @Override
vromero@1853: public boolean isPartial() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
duke@1: public Type baseType() {
duke@1: if (inst != null) return inst.baseType();
duke@1: else return this;
duke@1: }
mcimadamore@1338:
mcimadamore@1338: /** get all bounds of a given kind */
mcimadamore@1550: public List getBounds(InferenceBound... ibs) {
mcimadamore@1550: ListBuffer buf = ListBuffer.lb();
mcimadamore@1550: for (InferenceBound ib : ibs) {
mcimadamore@1550: buf.appendList(bounds.get(ib));
mcimadamore@1550: }
mcimadamore@1550: return buf.toList();
mcimadamore@1550: }
mcimadamore@1550:
mcimadamore@1550: /** get the list of declared (upper) bounds */
mcimadamore@1550: public List getDeclaredBounds() {
mcimadamore@1550: ListBuffer buf = ListBuffer.lb();
mcimadamore@1550: int count = 0;
mcimadamore@1550: for (Type b : getBounds(InferenceBound.UPPER)) {
mcimadamore@1550: if (count++ == declaredCount) break;
mcimadamore@1550: buf.append(b);
mcimadamore@1550: }
mcimadamore@1550: return buf.toList();
mcimadamore@1338: }
mcimadamore@1338:
mcimadamore@1338: /** add a bound of a given kind - this might trigger listener notification */
mcimadamore@1338: public void addBound(InferenceBound ib, Type bound, Types types) {
mcimadamore@1550: Type bound2 = toTypeVarMap.apply(bound);
mcimadamore@1338: List prevBounds = bounds.get(ib);
mcimadamore@1338: for (Type b : prevBounds) {
mcimadamore@1550: //check for redundancy - use strict version of isSameType on tvars
mcimadamore@1550: //(as the standard version will lead to false positives w.r.t. clones ivars)
mcimadamore@1628: if (types.isSameType(b, bound2, true) || bound == qtype) return;
mcimadamore@1338: }
mcimadamore@1550: bounds.put(ib, prevBounds.prepend(bound2));
mcimadamore@1338: notifyChange(EnumSet.of(ib));
mcimadamore@1338: }
mcimadamore@1550: //where
mcimadamore@1550: Type.Mapping toTypeVarMap = new Mapping("toTypeVarMap") {
mcimadamore@1550: @Override
mcimadamore@1550: public Type apply(Type t) {
mcimadamore@1550: if (t.hasTag(UNDETVAR)) {
mcimadamore@1550: UndetVar uv = (UndetVar)t;
mcimadamore@1550: return uv.qtype;
mcimadamore@1550: } else {
mcimadamore@1550: return t.map(this);
mcimadamore@1550: }
mcimadamore@1550: }
mcimadamore@1550: };
mcimadamore@1338:
mcimadamore@1338: /** replace types in all bounds - this might trigger listener notification */
mcimadamore@1338: public void substBounds(List from, List to, Types types) {
mcimadamore@1550: List instVars = from.diff(to);
mcimadamore@1550: //if set of instantiated ivars is empty, there's nothing to do!
mcimadamore@1550: if (instVars.isEmpty()) return;
mcimadamore@1550: final EnumSet boundsChanged = EnumSet.noneOf(InferenceBound.class);
mcimadamore@1550: UndetVarListener prevListener = listener;
mcimadamore@1550: try {
mcimadamore@1550: //setup new listener for keeping track of changed bounds
mcimadamore@1550: listener = new UndetVarListener() {
mcimadamore@1550: public void varChanged(UndetVar uv, Set ibs) {
mcimadamore@1550: boundsChanged.addAll(ibs);
mcimadamore@1550: }
mcimadamore@1550: };
mcimadamore@1550: for (Map.Entry> _entry : bounds.entrySet()) {
mcimadamore@1550: InferenceBound ib = _entry.getKey();
mcimadamore@1550: List prevBounds = _entry.getValue();
mcimadamore@1550: ListBuffer newBounds = ListBuffer.lb();
mcimadamore@1550: ListBuffer deps = ListBuffer.lb();
mcimadamore@1550: //step 1 - re-add bounds that are not dependent on ivars
mcimadamore@1550: for (Type t : prevBounds) {
mcimadamore@1550: if (!t.containsAny(instVars)) {
mcimadamore@1550: newBounds.append(t);
mcimadamore@1550: } else {
mcimadamore@1550: deps.append(t);
mcimadamore@1550: }
mcimadamore@1550: }
mcimadamore@1550: //step 2 - replace bounds
mcimadamore@1550: bounds.put(ib, newBounds.toList());
mcimadamore@1550: //step 3 - for each dependency, add new replaced bound
mcimadamore@1550: for (Type dep : deps) {
mcimadamore@1550: addBound(ib, types.subst(dep, from, to), types);
mcimadamore@1550: }
mcimadamore@1338: }
mcimadamore@1550: } finally {
mcimadamore@1550: listener = prevListener;
mcimadamore@1550: if (!boundsChanged.isEmpty()) {
mcimadamore@1550: notifyChange(boundsChanged);
mcimadamore@1550: }
mcimadamore@1338: }
mcimadamore@1338: }
mcimadamore@1338:
mcimadamore@1338: private void notifyChange(EnumSet ibs) {
mcimadamore@1338: if (listener != null) {
mcimadamore@1338: listener.varChanged(this, ibs);
mcimadamore@1338: }
mcimadamore@1338: }
duke@1: }
duke@1:
vromero@1853: /** Represents NONE.
duke@1: */
vromero@1853: public static class JCNoType extends Type implements NoType {
vromero@1853: public JCNoType() {
vromero@1853: super(null);
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return NONE;
duke@1: }
duke@1:
duke@1: @Override
duke@1: public TypeKind getKind() {
vromero@1853: return TypeKind.NONE;
duke@1: }
duke@1:
duke@1: @Override
duke@1: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitNoType(this, p);
duke@1: }
duke@1: }
duke@1:
vromero@1853: /** Represents VOID.
vromero@1853: */
vromero@1853: public static class JCVoidType extends Type implements NoType {
vromero@1853:
vromero@1853: public JCVoidType() {
vromero@1853: super(null);
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return VOID;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public TypeKind getKind() {
vromero@1853: return TypeKind.VOID;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public R accept(TypeVisitor v, P p) {
vromero@1853: return v.visitNoType(this, p);
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isPrimitiveOrVoid() {
vromero@1853: return true;
vromero@1853: }
vromero@1853: }
vromero@1853:
duke@1: static class BottomType extends Type implements NullType {
duke@1: public BottomType() {
vromero@1853: super(null);
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return BOT;
duke@1: }
duke@1:
duke@1: @Override
duke@1: public TypeKind getKind() {
duke@1: return TypeKind.NULL;
duke@1: }
duke@1:
duke@1: @Override
duke@1: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitNull(this, p);
duke@1: }
duke@1:
duke@1: @Override
duke@1: public Type constType(Object value) {
duke@1: return this;
duke@1: }
duke@1:
duke@1: @Override
duke@1: public String stringValue() {
duke@1: return "null";
duke@1: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isNullOrReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
duke@1: }
duke@1:
duke@1: public static class ErrorType extends ClassType
duke@1: implements javax.lang.model.type.ErrorType {
duke@1:
jjg@110: private Type originalType = null;
jjg@110:
jjg@110: public ErrorType(Type originalType, TypeSymbol tsym) {
duke@1: super(noType, List.nil(), null);
jjg@110: this.tsym = tsym;
jjg@110: this.originalType = (originalType == null ? noType : originalType);
duke@1: }
duke@1:
jjg@110: public ErrorType(ClassSymbol c, Type originalType) {
jjg@110: this(originalType, c);
duke@1: c.type = this;
duke@1: c.kind = ERR;
duke@1: c.members_field = new Scope.ErrorScope(c);
duke@1: }
duke@1:
vromero@1853: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return ERROR;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isPartial() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isNullOrReference() {
vromero@1853: return true;
vromero@1853: }
vromero@1853:
jjg@110: public ErrorType(Name name, TypeSymbol container, Type originalType) {
jjg@110: this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType);
duke@1: }
duke@1:
duke@1: @Override
duke@1: public R accept(Type.Visitor v, S s) {
duke@1: return v.visitErrorType(this, s);
duke@1: }
duke@1:
duke@1: public Type constType(Object constValue) { return this; }
jjg@1521: public Type getEnclosingType() { return this; }
duke@1: public Type getReturnType() { return this; }
duke@1: public Type asSub(Symbol sym) { return this; }
duke@1: public Type map(Mapping f) { return this; }
duke@1:
duke@1: public boolean isGenType(Type t) { return true; }
duke@1: public boolean isErroneous() { return true; }
duke@1: public boolean isCompound() { return false; }
duke@1: public boolean isInterface() { return false; }
duke@1:
duke@1: public List allparams() { return List.nil(); }
duke@1: public List getTypeArguments() { return List.nil(); }
duke@1:
duke@1: public TypeKind getKind() {
duke@1: return TypeKind.ERROR;
duke@1: }
duke@1:
jjg@110: public Type getOriginalType() {
jjg@110: return originalType;
jjg@110: }
jjg@110:
duke@1: public R accept(TypeVisitor v, P p) {
duke@1: return v.visitError(this, p);
duke@1: }
duke@1: }
duke@1:
jjg@1521: public static class AnnotatedType extends Type
jjg@1644: implements
jjg@1644: javax.lang.model.type.ArrayType,
jjg@1644: javax.lang.model.type.DeclaredType,
jjg@1644: javax.lang.model.type.PrimitiveType,
jjg@1644: javax.lang.model.type.TypeVariable,
jjg@1644: javax.lang.model.type.WildcardType {
jjg@1521: /** The type annotations on this type.
jjg@1521: */
jjg@1521: public List typeAnnotations;
jjg@1521:
jjg@1521: /** The underlying type that is annotated.
jjg@1521: */
jjg@1521: public Type underlyingType;
jjg@1521:
jjg@1521: public AnnotatedType(Type underlyingType) {
vromero@1853: super(underlyingType.tsym);
jjg@1521: this.typeAnnotations = List.nil();
jjg@1521: this.underlyingType = underlyingType;
jjg@1644: Assert.check(!underlyingType.isAnnotated(),
jjg@1521: "Can't annotate already annotated type: " + underlyingType);
jjg@1521: }
jjg@1521:
jjg@1521: public AnnotatedType(List typeAnnotations,
jjg@1521: Type underlyingType) {
vromero@1853: super(underlyingType.tsym);
jjg@1521: this.typeAnnotations = typeAnnotations;
jjg@1521: this.underlyingType = underlyingType;
jjg@1644: Assert.check(!underlyingType.isAnnotated(),
jjg@1521: "Can't annotate already annotated type: " + underlyingType +
jjg@1521: "; adding: " + typeAnnotations);
jjg@1521: }
jjg@1521:
jjg@1521: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return underlyingType.getTag();
vromero@1853: }
vromero@1853:
vromero@1853: @Override
jjg@1644: public boolean isAnnotated() {
jjg@1644: return true;
jjg@1644: }
jjg@1644:
jjg@1644: @Override
jjg@1645: public List extends Attribute.TypeCompound> getAnnotationMirrors() {
jjg@1645: return typeAnnotations;
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1645: public A getAnnotation(Class annotationType) {
jjg@1645: return JavacAnnoConstructs.getAnnotation(this, annotationType);
jjg@1645: }
jjg@1645:
jjg@1645: @Override
jjg@1645: public A[] getAnnotationsByType(Class annotationType) {
jjg@1645: return JavacAnnoConstructs.getAnnotationsByType(this, annotationType);
jjg@1645: }
jjg@1645:
jjg@1645: @Override
jjg@1645: public TypeKind getKind() {
jjg@1645: return underlyingType.getKind();
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1521: public Type unannotatedType() {
jjg@1521: return underlyingType;
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1521: public R accept(Type.Visitor v, S s) {
jjg@1521: return v.visitAnnotatedType(this, s);
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1521: public R accept(TypeVisitor v, P p) {
jjg@1644: return underlyingType.accept(v, p);
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1521: public Type map(Mapping f) {
jjg@1521: underlyingType.map(f);
jjg@1521: return this;
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1521: public Type constType(Object constValue) { return underlyingType.constType(constValue); }
jjg@1521: @Override
jjg@1521: public Type getEnclosingType() { return underlyingType.getEnclosingType(); }
jjg@1521:
jjg@1521: @Override
jjg@1521: public Type getReturnType() { return underlyingType.getReturnType(); }
jjg@1521: @Override
jjg@1521: public List getTypeArguments() { return underlyingType.getTypeArguments(); }
jjg@1521: @Override
jjg@1521: public List getParameterTypes() { return underlyingType.getParameterTypes(); }
jjg@1521: @Override
jjg@1521: public Type getReceiverType() { return underlyingType.getReceiverType(); }
jjg@1521: @Override
jjg@1521: public List getThrownTypes() { return underlyingType.getThrownTypes(); }
jjg@1521: @Override
jjg@1521: public Type getUpperBound() { return underlyingType.getUpperBound(); }
jjg@1521: @Override
jjg@1521: public Type getLowerBound() { return underlyingType.getLowerBound(); }
jjg@1521:
jjg@1521: @Override
jjg@1521: public boolean isErroneous() { return underlyingType.isErroneous(); }
jjg@1521: @Override
jjg@1521: public boolean isCompound() { return underlyingType.isCompound(); }
jjg@1521: @Override
jjg@1521: public boolean isInterface() { return underlyingType.isInterface(); }
jjg@1521: @Override
jjg@1521: public List allparams() { return underlyingType.allparams(); }
jjg@1521: @Override
vromero@1853: public boolean isPrimitive() { return underlyingType.isPrimitive(); }
vromero@1853: @Override
vromero@1853: public boolean isPrimitiveOrVoid() { return underlyingType.isPrimitiveOrVoid(); }
vromero@1853: @Override
jjg@1521: public boolean isNumeric() { return underlyingType.isNumeric(); }
jjg@1521: @Override
jjg@1521: public boolean isReference() { return underlyingType.isReference(); }
jjg@1521: @Override
vromero@1853: public boolean isNullOrReference() { return underlyingType.isNullOrReference(); }
vromero@1853: @Override
vromero@1853: public boolean isPartial() { return underlyingType.isPartial(); }
vromero@1853: @Override
jjg@1521: public boolean isParameterized() { return underlyingType.isParameterized(); }
jjg@1521: @Override
jjg@1521: public boolean isRaw() { return underlyingType.isRaw(); }
jjg@1521: @Override
jjg@1521: public boolean isFinal() { return underlyingType.isFinal(); }
jjg@1521: @Override
jjg@1521: public boolean isSuperBound() { return underlyingType.isSuperBound(); }
jjg@1521: @Override
jjg@1521: public boolean isExtendsBound() { return underlyingType.isExtendsBound(); }
jjg@1521: @Override
jjg@1521: public boolean isUnbound() { return underlyingType.isUnbound(); }
jjg@1521:
jjg@1521: @Override
jjg@1521: public String toString() {
jjg@1755: // This method is only used for internal debugging output.
jjg@1755: // See
jjg@1755: // com.sun.tools.javac.code.Printer.visitAnnotatedType(AnnotatedType, Locale)
jjg@1755: // for the user-visible logic.
jjg@1521: if (typeAnnotations != null &&
jjg@1521: !typeAnnotations.isEmpty()) {
jjg@1521: return "(" + typeAnnotations.toString() + " :: " + underlyingType.toString() + ")";
jjg@1521: } else {
jjg@1521: return "({} :: " + underlyingType.toString() +")";
jjg@1521: }
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1521: public boolean contains(Type t) { return underlyingType.contains(t); }
jjg@1521:
jjg@1521: @Override
jjg@1755: public Type withTypeVar(Type t) {
jjg@1755: // Don't create a new AnnotatedType, as 'this' will
jjg@1755: // get its annotations set later.
jjg@1755: underlyingType = underlyingType.withTypeVar(t);
jjg@1755: return this;
jjg@1755: }
jjg@1521:
jjg@1521: // TODO: attach annotations?
jjg@1521: @Override
jjg@1521: public TypeSymbol asElement() { return underlyingType.asElement(); }
jjg@1521:
jjg@1521: // TODO: attach annotations?
jjg@1521: @Override
jjg@1521: public MethodType asMethodType() { return underlyingType.asMethodType(); }
jjg@1521:
jjg@1521: @Override
jjg@1521: public void complete() { underlyingType.complete(); }
jjg@1521:
jjg@1521: @Override
jjg@1521: public TypeMirror getComponentType() { return ((ArrayType)underlyingType).getComponentType(); }
jjg@1521:
jjg@1521: // The result is an ArrayType, but only in the model sense, not the Type sense.
jjg@1521: public AnnotatedType makeVarargs() {
jjg@1521: AnnotatedType atype = new AnnotatedType(((ArrayType)underlyingType).makeVarargs());
jjg@1521: atype.typeAnnotations = this.typeAnnotations;
jjg@1521: return atype;
jjg@1521: }
jjg@1521:
jjg@1521: @Override
jjg@1521: public TypeMirror getExtendsBound() { return ((WildcardType)underlyingType).getExtendsBound(); }
jjg@1521: @Override
jjg@1521: public TypeMirror getSuperBound() { return ((WildcardType)underlyingType).getSuperBound(); }
jjg@1521: }
jjg@1521:
vromero@1853: public static class UnknownType extends Type {
vromero@1853:
vromero@1853: public UnknownType() {
vromero@1853: super(null);
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public TypeTag getTag() {
vromero@1853: return UNKNOWN;
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public R accept(TypeVisitor v, P p) {
vromero@1853: return v.visitUnknown(this, p);
vromero@1853: }
vromero@1853:
vromero@1853: @Override
vromero@1853: public boolean isPartial() {
vromero@1853: return true;
vromero@1853: }
vromero@1853: }
vromero@1853:
duke@1: /**
duke@1: * A visitor for types. A visitor is used to implement operations
duke@1: * (or relations) on types. Most common operations on types are
duke@1: * binary relations and this interface is designed for binary
jjg@1521: * relations, that is, operations of the form
duke@1: * Type × S → R.
duke@1: *
duke@1: *
duke@1: * @param the return type of the operation implemented by this
duke@1: * visitor; use Void if no return type is needed.
duke@1: * @param the type of the second argument (the first being the
duke@1: * type itself) of the operation implemented by this visitor; use
duke@1: * Void if a second argument is not needed.
duke@1: */
duke@1: public interface Visitor {
duke@1: R visitClassType(ClassType t, S s);
duke@1: R visitWildcardType(WildcardType t, S s);
duke@1: R visitArrayType(ArrayType t, S s);
duke@1: R visitMethodType(MethodType t, S s);
duke@1: R visitPackageType(PackageType t, S s);
duke@1: R visitTypeVar(TypeVar t, S s);
duke@1: R visitCapturedType(CapturedType t, S s);
duke@1: R visitForAll(ForAll t, S s);
duke@1: R visitUndetVar(UndetVar t, S s);
duke@1: R visitErrorType(ErrorType t, S s);
jjg@1521: R visitAnnotatedType(AnnotatedType t, S s);
duke@1: R visitType(Type t, S s);
duke@1: }
duke@1: }