package com.sun.tools.javac.code;
import java.lang.annotation.Annotation;
import java.util.ArrayDeque;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
import javax.lang.model.type.*;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.TypeMetadata.Entry;
import com.sun.tools.javac.code.Types.TypeMapping;
import com.sun.tools.javac.comp.Infer.IncorporationAction;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.DefinedBy.Api;
import static com.sun.tools.javac.code.BoundKind.*;
import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Kinds.Kind.*;
import static com.sun.tools.javac.code.TypeTag.*;
public abstract class Type extends AnnoConstruct implements TypeMirror {
protected final TypeMetadata metadata;
public TypeMetadata getMetadata() {
return metadata;
}
public Entry getMetadataOfKind(final Entry.Kind kind) {
return metadata != null ? metadata.get(kind) : null;
}
public static final JCNoType noType = new JCNoType() {
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
return "none";
}
};
public static final JCNoType recoveryType = new JCNoType(){
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
return "recovery";
}
};
public static final JCNoType stuckType = new JCNoType() {
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
return "stuck";
}
};
public static boolean moreInfo = false;
public TypeSymbol tsym;
public boolean hasTag(TypeTag tag) {
return tag == getTag();
}
public abstract TypeTag getTag();
public boolean isNumeric() {
return false;
}
public boolean isIntegral() {
return false;
}
public boolean isPrimitive() {
return false;
}
public boolean isPrimitiveOrVoid() {
return false;
}
public boolean isReference() {
return false;
}
public boolean isNullOrReference() {
return false;
}
public boolean isPartial() {
return false;
}
public Object constValue() {
return null;
}
public boolean isFalse() {
return false;
}
public boolean isTrue() {
return false;
}
public Type getModelType() {
return this;
}
public static List<Type> getModelTypes(List<Type> ts) {
ListBuffer<Type> lb = new ListBuffer<>();
for (Type t: ts)
lb.append(t.getModelType());
return lb.toList();
}
public Type getOriginalType() {
return this;
}
public <R,S> R accept(Type.Visitor<R,S> v, S s) { return v.visitType(this, s); }
public Type(TypeSymbol tsym, TypeMetadata metadata) {
Assert.checkNonNull(metadata);
this.tsym = tsym;
this.metadata = metadata;
}
public static abstract class StructuralTypeMapping<S> extends Types.TypeMapping<S> {
@Override
public Type visitClassType(ClassType t, S s) {
Type outer = t.getEnclosingType();
Type outer1 = visit(outer, s);
List<Type> typarams = t.getTypeArguments();
List<Type> typarams1 = visit(typarams, s);
if (outer1 == outer && typarams1 == typarams) return t;
else return new ClassType(outer1, typarams1, t.tsym, t.metadata) {
@Override
protected boolean needsStripping() {
return true;
}
};
}
@Override
public Type visitWildcardType(WildcardType wt, S s) {
Type t = wt.type;
if (t != null)
t = visit(t, s);
if (t == wt.type)
return wt;
else
return new WildcardType(t, wt.kind, wt.tsym, wt.bound, wt.metadata) {
@Override
protected boolean needsStripping() {
return true;
}
};
}
@Override
public Type visitArrayType(ArrayType t, S s) {
Type elemtype = t.elemtype;
Type elemtype1 = visit(elemtype, s);
if (elemtype1 == elemtype) return t;
else return new ArrayType(elemtype1, t.tsym, t.metadata) {
@Override
protected boolean needsStripping() {
return true;
}
};
}
@Override
public Type visitMethodType(MethodType t, S s) {
List<Type> argtypes = t.argtypes;
Type restype = t.restype;
List<Type> thrown = t.thrown;
List<Type> argtypes1 = visit(argtypes, s);
Type restype1 = visit(restype, s);
List<Type> thrown1 = visit(thrown, s);
if (argtypes1 == argtypes &&
restype1 == restype &&
thrown1 == thrown) return t;
else return new MethodType(argtypes1, restype1, thrown1, t.tsym) {
@Override
protected boolean needsStripping() {
return true;
}
};
}
@Override
public Type visitForAll(ForAll t, S s) {
return visit(t.qtype, s);
}
}
public <Z> Type map(TypeMapping<Z> mapping, Z arg) {
return mapping.visit(this, arg);
}
public <Z> Type map(TypeMapping<Z> mapping) {
return mapping.visit(this, null);
}
public Type constType(Object constValue) {
throw new AssertionError();
}
public Type baseType() {
return this;
}
protected Type typeNoMetadata() {
return metadata == TypeMetadata.EMPTY ? this : baseType();
}
public abstract Type cloneWithMetadata(TypeMetadata metadata);
protected boolean needsStripping() {
return false;
}
public Type stripMetadataIfNeeded() {
return needsStripping() ?
accept(stripMetadata, null) :
this;
}
public Type stripMetadata() {
return accept(stripMetadata, null);
}
private final static TypeMapping<Void> stripMetadata = new StructuralTypeMapping<Void>() {
@Override
public Type visitClassType(ClassType t, Void aVoid) {
return super.visitClassType((ClassType)t.typeNoMetadata(), aVoid);
}
@Override
public Type visitArrayType(ArrayType t, Void aVoid) {
return super.visitArrayType((ArrayType)t.typeNoMetadata(), aVoid);
}
@Override
public Type visitTypeVar(TypeVar t, Void aVoid) {
return super.visitTypeVar((TypeVar)t.typeNoMetadata(), aVoid);
}
@Override
public Type visitWildcardType(WildcardType wt, Void aVoid) {
return super.visitWildcardType((WildcardType)wt.typeNoMetadata(), aVoid);
}
};
public Type annotatedType(final List<Attribute.TypeCompound> annos) {
final Entry annoMetadata = new TypeMetadata.Annotations(annos);
return cloneWithMetadata(metadata.combine(annoMetadata));
}
public boolean isAnnotated() {
final TypeMetadata.Annotations metadata =
(TypeMetadata.Annotations)getMetadataOfKind(Entry.Kind.ANNOTATIONS);
return null != metadata && !metadata.getAnnotations().isEmpty();
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public List<Attribute.TypeCompound> getAnnotationMirrors() {
final TypeMetadata.Annotations metadata =
(TypeMetadata.Annotations)getMetadataOfKind(Entry.Kind.ANNOTATIONS);
return metadata == null ? List.nil() : metadata.getAnnotations();
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
return null;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <A extends Annotation> A[] getAnnotationsByType(Class<A> annotationType) {
@SuppressWarnings("unchecked")
A[] tmp = (A[]) java.lang.reflect.Array.newInstance(annotationType, 0);
return tmp;
}
public static List<Type> baseTypes(List<Type> ts) {
if (ts.nonEmpty()) {
Type t = ts.head.baseType();
List<Type> baseTypes = baseTypes(ts.tail);
if (t != ts.head || baseTypes != ts.tail)
return baseTypes.prepend(t);
}
return ts;
}
protected void appendAnnotationsString(StringBuilder sb,
boolean prefix) {
if (isAnnotated()) {
if (prefix) {
sb.append(" ");
}
sb.append(getAnnotationMirrors());
sb.append(" ");
}
}
protected void appendAnnotationsString(StringBuilder sb) {
appendAnnotationsString(sb, false);
}
@DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
StringBuilder sb = new StringBuilder();
appendAnnotationsString(sb);
if (tsym == null || tsym.name == null) {
sb.append("<none>");
} else {
sb.append(tsym.name);
}
if (moreInfo && hasTag(TYPEVAR)) {
sb.append(hashCode());
}
return sb.toString();
}
public static String toString(List<Type> ts) {
if (ts.isEmpty()) {
return "";
} else {
StringBuilder buf = new StringBuilder();
buf.append(ts.head.toString());
for (List<Type> l = ts.tail; l.nonEmpty(); l = l.tail)
buf.append(",").append(l.head.toString());
return buf.toString();
}
}
public String stringValue() {
Object cv = Assert.checkNonNull(constValue());
return cv.toString();
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public boolean equals(Object t) {
return this == t;
}
public boolean equalsIgnoreMetadata(Type t) {
return typeNoMetadata().equals(t.typeNoMetadata());
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public int hashCode() {
return super.hashCode();
}
public String argtypes(boolean varargs) {
List<Type> args = getParameterTypes();
if (!varargs) return args.toString();
StringBuilder buf = new StringBuilder();
while (args.tail.nonEmpty()) {
buf.append(args.head);
args = args.tail;
buf.append(',');
}
if (args.head.hasTag(ARRAY)) {
buf.append(((ArrayType)args.head).elemtype);
if (args.head.getAnnotationMirrors().nonEmpty()) {
buf.append(args.head.getAnnotationMirrors());
}
buf.append("...");
} else {
buf.append(args.head);
}
return buf.toString();
}
public List<Type> getTypeArguments() { return List.nil(); }
public Type getEnclosingType() { return null; }
public List<Type> getParameterTypes() { return List.nil(); }
public Type getReturnType() { return null; }
public Type getReceiverType() { return null; }
public List<Type> getThrownTypes() { return List.nil(); }
public Type getUpperBound() { return null; }
public Type getLowerBound() { return null; }
public List<Type> allparams() { return List.nil(); }
public boolean isErroneous() {
return false;
}
public static boolean isErroneous(List<Type> ts) {
for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
if (l.head.isErroneous()) return true;
return false;
}
public boolean isParameterized() {
return false;
}
public boolean isRaw() {
return false;
}
public boolean isCompound() {
return false;
}
public boolean isIntersection() {
return false;
}
public boolean isUnion() {
return false;
}
public boolean isInterface() {
return (tsym.flags() & INTERFACE) != 0;
}
public boolean isFinal() {
return (tsym.flags() & FINAL) != 0;
}
public boolean contains(Type t) {
return t.equalsIgnoreMetadata(this);
}
public static boolean contains(List<Type> ts, Type t) {
for (List<Type> l = ts;
l.tail != null ;
l = l.tail)
if (l.head.contains(t)) return true;
return false;
}
public boolean containsAny(List<Type> ts) {
for (Type t : ts)
if (this.contains(t)) return true;
return false;
}
public static boolean containsAny(List<Type> ts1, List<Type> ts2) {
for (Type t : ts1)
if (t.containsAny(ts2)) return true;
return false;
}
public static List<Type> filter(List<Type> ts, Filter<Type> tf) {
ListBuffer<Type> buf = new ListBuffer<>();
for (Type t : ts) {
if (tf.accepts(t)) {
buf.append(t);
}
}
return buf.toList();
}
public boolean isSuperBound() { return false; }
public boolean isExtendsBound() { return false; }
public boolean isUnbound() { return false; }
public Type withTypeVar(Type t) { return this; }
public MethodType asMethodType() { throw new AssertionError(); }
public void complete() {}
public TypeSymbol asElement() {
return tsym;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.OTHER;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
throw new AssertionError();
}
public static class JCPrimitiveType extends Type
implements javax.lang.model.type.PrimitiveType {
TypeTag tag;
public JCPrimitiveType(TypeTag tag, TypeSymbol tsym) {
this(tag, tsym, TypeMetadata.EMPTY);
}
private JCPrimitiveType(TypeTag tag, TypeSymbol tsym, TypeMetadata metadata) {
super(tsym, metadata);
this.tag = tag;
Assert.check(tag.isPrimitive);
}
@Override
public JCPrimitiveType cloneWithMetadata(TypeMetadata md) {
return new JCPrimitiveType(tag, tsym, md) {
@Override
public Type baseType() { return JCPrimitiveType.this.baseType(); }
};
}
@Override
public boolean isNumeric() {
return tag != BOOLEAN;
}
@Override
public boolean isIntegral() {
switch (tag) {
case CHAR:
case BYTE:
case SHORT:
case INT:
case LONG:
return true;
default:
return false;
}
}
@Override
public boolean isPrimitive() {
return true;
}
@Override
public TypeTag getTag() {
return tag;
}
@Override
public boolean isPrimitiveOrVoid() {
return true;
}
@Override
public Type constType(Object constValue) {
final Object value = constValue;
return new JCPrimitiveType(tag, tsym, metadata) {
@Override
public Object constValue() {
return value;
}
@Override
public Type baseType() {
return tsym.type;
}
};
}
@Override
public String stringValue() {
Object cv = Assert.checkNonNull(constValue());
if (tag == BOOLEAN) {
return ((Integer) cv).intValue() == 0 ? "false" : "true";
}
else if (tag == CHAR) {
return String.valueOf((char) ((Integer) cv).intValue());
}
else {
return cv.toString();
}
}
@Override
public boolean isFalse() {
return
tag == BOOLEAN &&
constValue() != null &&
((Integer)constValue()).intValue() == 0;
}
@Override
public boolean isTrue() {
return
tag == BOOLEAN &&
constValue() != null &&
((Integer)constValue()).intValue() != 0;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitPrimitive(this, p);
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
switch (tag) {
case BYTE: return TypeKind.BYTE;
case CHAR: return TypeKind.CHAR;
case SHORT: return TypeKind.SHORT;
case INT: return TypeKind.INT;
case LONG: return TypeKind.LONG;
case FLOAT: return TypeKind.FLOAT;
case DOUBLE: return TypeKind.DOUBLE;
case BOOLEAN: return TypeKind.BOOLEAN;
}
throw new AssertionError();
}
}
public static class WildcardType extends Type
implements javax.lang.model.type.WildcardType {
public Type type;
public BoundKind kind;
public TypeVar bound;
@Override
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitWildcardType(this, s);
}
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
this(type, kind, tsym, null, TypeMetadata.EMPTY);
}
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym,
TypeMetadata metadata) {
this(type, kind, tsym, null, metadata);
}
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym,
TypeVar bound) {
this(type, kind, tsym, bound, TypeMetadata.EMPTY);
}
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym,
TypeVar bound, TypeMetadata metadata) {
super(tsym, metadata);
this.type = Assert.checkNonNull(type);
this.kind = kind;
this.bound = bound;
}
@Override
public WildcardType cloneWithMetadata(TypeMetadata md) {
return new WildcardType(type, kind, tsym, bound, md) {
@Override
public Type baseType() { return WildcardType.this.baseType(); }
};
}
@Override
public TypeTag getTag() {
return WILDCARD;
}
@Override
public boolean contains(Type t) {
return kind != UNBOUND && type.contains(t);
}
public boolean isSuperBound() {
return kind == SUPER ||
kind == UNBOUND;
}
public boolean isExtendsBound() {
return kind == EXTENDS ||
kind == UNBOUND;
}
public boolean isUnbound() {
return kind == UNBOUND;
}
@Override
public boolean isReference() {
return true;
}
@Override
public boolean isNullOrReference() {
return true;
}
@Override
public Type withTypeVar(Type t) {
if (bound == t)
return this;
bound = (TypeVar)t;
return this;
}
boolean isPrintingBound = false;
@DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
StringBuilder s = new StringBuilder();
appendAnnotationsString(s);
s.append(kind.toString());
if (kind != UNBOUND)
s.append(type);
if (moreInfo && bound != null && !isPrintingBound)
try {
isPrintingBound = true;
s.append("{:").append(bound.bound).append(":}");
} finally {
isPrintingBound = false;
}
return s.toString();
}
@DefinedBy(Api.LANGUAGE_MODEL)
public Type getExtendsBound() {
if (kind == EXTENDS)
return type;
else
return null;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public Type getSuperBound() {
if (kind == SUPER)
return type;
else
return null;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.WILDCARD;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitWildcard(this, p);
}
}
public static class ClassType extends Type implements DeclaredType {
private Type outer_field;
public List<Type> typarams_field;
public List<Type> allparams_field;
public Type supertype_field;
public List<Type> interfaces_field;
public List<Type> all_interfaces_field;
public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym) {
this(outer, typarams, tsym, TypeMetadata.EMPTY);
}
public ClassType(Type outer, List<Type> typarams, TypeSymbol tsym,
TypeMetadata metadata) {
super(tsym, metadata);
this.outer_field = outer;
this.typarams_field = typarams;
this.allparams_field = null;
this.supertype_field = null;
this.interfaces_field = null;
}
@Override
public ClassType cloneWithMetadata(TypeMetadata md) {
return new ClassType(outer_field, typarams_field, tsym, md) {
@Override
public Type baseType() { return ClassType.this.baseType(); }
};
}
@Override
public TypeTag getTag() {
return CLASS;
}
@Override
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitClassType(this, s);
}
public Type constType(Object constValue) {
final Object value = constValue;
return new ClassType(getEnclosingType(), typarams_field, tsym, metadata) {
@Override
public Object constValue() {
return value;
}
@Override
public Type baseType() {
return tsym.type;
}
};
}
@DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
StringBuilder buf = new StringBuilder();
if (getEnclosingType().hasTag(CLASS) && tsym.owner.kind == TYP) {
buf.append(getEnclosingType().toString());
buf.append(".");
appendAnnotationsString(buf);
buf.append(className(tsym, false));
} else {
appendAnnotationsString(buf);
buf.append(className(tsym, true));
}
if (getTypeArguments().nonEmpty()) {
buf.append('<');
buf.append(getTypeArguments().toString());
buf.append(">");
}
return buf.toString();
}
private String className(Symbol sym, boolean longform) {
if (sym.name.isEmpty() && (sym.flags() & COMPOUND) != 0) {
StringBuilder s = new StringBuilder(supertype_field.toString());
for (List<Type> is=interfaces_field; is.nonEmpty(); is = is.tail) {
s.append("&");
s.append(is.head.toString());
}
return s.toString();
} else if (sym.name.isEmpty()) {
String s;
ClassType norm = (ClassType) tsym.type;
if (norm == null) {
s = Log.getLocalizedString("anonymous.class", (Object)null);
} else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
s = Log.getLocalizedString("anonymous.class",
norm.interfaces_field.head);
} else {
s = Log.getLocalizedString("anonymous.class",
norm.supertype_field);
}
if (moreInfo)
s += String.valueOf(sym.hashCode());
return s;
} else if (longform) {
return sym.getQualifiedName().toString();
} else {
return sym.name.toString();
}
}
@DefinedBy(Api.LANGUAGE_MODEL)
public List<Type> getTypeArguments() {
if (typarams_field == null) {
complete();
if (typarams_field == null)
typarams_field = List.nil();
}
return typarams_field;
}
public boolean hasErasedSupertypes() {
return isRaw();
}
@DefinedBy(Api.LANGUAGE_MODEL)
public Type getEnclosingType() {
return outer_field;
}
public void setEnclosingType(Type outer) {
outer_field = outer;
}
public List<Type> allparams() {
if (allparams_field == null) {
allparams_field = getTypeArguments().prependList(getEnclosingType().allparams());
}
return allparams_field;
}
public boolean isErroneous() {
return
getEnclosingType().isErroneous() ||
isErroneous(getTypeArguments()) ||
this != tsym.type && tsym.type.isErroneous();
}
public boolean isParameterized() {
return allparams().tail != null;
}
@Override
public boolean isReference() {
return true;
}
@Override
public boolean isNullOrReference() {
return true;
}
int rank_field = -1;
public boolean isRaw() {
return
this != tsym.type &&
tsym.type.allparams().nonEmpty() &&
allparams().isEmpty();
}
public boolean contains(Type elem) {
return
elem.equalsIgnoreMetadata(this)
|| (isParameterized()
&& (getEnclosingType().contains(elem) || contains(getTypeArguments(), elem)))
|| (isCompound()
&& (supertype_field.contains(elem) || contains(interfaces_field, elem)));
}
public void complete() {
tsym.complete();
}
@DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.DECLARED;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitDeclared(this, p);
}
}
public static class ErasedClassType extends ClassType {
public ErasedClassType(Type outer, TypeSymbol tsym,
TypeMetadata metadata) {
super(outer, List.nil(), tsym, metadata);
}
@Override
public boolean hasErasedSupertypes() {
return true;
}
}
public static class UnionClassType extends ClassType implements UnionType {
final List<? extends Type> alternatives_field;
public UnionClassType(ClassType ct, List<? extends Type> alternatives) {
super(ct.outer_field, ct.typarams_field, ct.tsym);
allparams_field = ct.allparams_field;
supertype_field = ct.supertype_field;
interfaces_field = ct.interfaces_field;
all_interfaces_field = ct.interfaces_field;
alternatives_field = alternatives;
}
@Override
public UnionClassType cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to a union type");
}
public Type getLub() {
return tsym.type;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public java.util.List<? extends TypeMirror> getAlternatives() {
return Collections.unmodifiableList(alternatives_field);
}
@Override
public boolean isUnion() {
return true;
}
@Override
public boolean isCompound() {
return getLub().isCompound();
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.UNION;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitUnion(this, p);
}
public Iterable<? extends Type> getAlternativeTypes() {
return alternatives_field;
}
}
public static class IntersectionClassType extends ClassType implements IntersectionType {
public boolean allInterfaces;
public IntersectionClassType(List<Type> bounds, ClassSymbol csym, boolean allInterfaces) {
super(Type.noType, List.nil(), csym);
this.allInterfaces = allInterfaces;
Assert.check((csym.flags() & COMPOUND) != 0);
supertype_field = bounds.head;
interfaces_field = bounds.tail;
Assert.check(!supertype_field.tsym.isCompleted() ||
!supertype_field.isInterface(), supertype_field);
}
@Override
public IntersectionClassType cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to an intersection type");
}
@DefinedBy(Api.LANGUAGE_MODEL)
public java.util.List<? extends TypeMirror> getBounds() {
return Collections.unmodifiableList(getExplicitComponents());
}
@Override
public boolean isCompound() {
return true;
}
public List<Type> getComponents() {
return interfaces_field.prepend(supertype_field);
}
@Override
public boolean isIntersection() {
return true;
}
public List<Type> getExplicitComponents() {
return allInterfaces ?
interfaces_field :
getComponents();
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.INTERSECTION;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitIntersection(this, p);
}
}
public static class ArrayType extends Type
implements javax.lang.model.type.ArrayType {
public Type elemtype;
public ArrayType(Type elemtype, TypeSymbol arrayClass) {
this(elemtype, arrayClass, TypeMetadata.EMPTY);
}
public ArrayType(Type elemtype, TypeSymbol arrayClass,
TypeMetadata metadata) {
super(arrayClass, metadata);
this.elemtype = elemtype;
}
public ArrayType(ArrayType that) {
this(that.elemtype, that.tsym, that.getMetadata());
}
@Override
public ArrayType cloneWithMetadata(TypeMetadata md) {
return new ArrayType(elemtype, tsym, md) {
@Override
public Type baseType() { return ArrayType.this.baseType(); }
};
}
@Override
public TypeTag getTag() {
return ARRAY;
}
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitArrayType(this, s);
}
@DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
StringBuilder sb = new StringBuilder();
Type t = elemtype;
while (t.getKind() == TypeKind.ARRAY)
t = ((ArrayType) t).getComponentType();
sb.append(t);
t = this;
do {
t.appendAnnotationsString(sb, true);
sb.append("[]");
t = ((ArrayType) t).getComponentType();
} while (t.getKind() == TypeKind.ARRAY);
return sb.toString();
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public boolean equals(Object obj) {
if (obj instanceof ArrayType) {
ArrayType that = (ArrayType)obj;
return this == that ||
elemtype.equals(that.elemtype);
}
return false;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public int hashCode() {
return (ARRAY.ordinal() << 5) + elemtype.hashCode();
}
public boolean isVarargs() {
return false;
}
public List<Type> allparams() { return elemtype.allparams(); }
public boolean isErroneous() {
return elemtype.isErroneous();
}
public boolean isParameterized() {
return elemtype.isParameterized();
}
@Override
public boolean isReference() {
return true;
}
@Override
public boolean isNullOrReference() {
return true;
}
public boolean isRaw() {
return elemtype.isRaw();
}
public ArrayType makeVarargs() {
return new ArrayType(elemtype, tsym, metadata) {
@Override
public boolean isVarargs() {
return true;
}
};
}
public boolean contains(Type elem) {
return elem.equalsIgnoreMetadata(this) || elemtype.contains(elem);
}
public void complete() {
elemtype.complete();
}
@DefinedBy(Api.LANGUAGE_MODEL)
public Type getComponentType() {
return elemtype;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.ARRAY;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitArray(this, p);
}
}
public static class MethodType extends Type implements ExecutableType {
public List<Type> argtypes;
public Type restype;
public List<Type> thrown;
public Type recvtype;
public MethodType(List<Type> argtypes,
Type restype,
List<Type> thrown,
TypeSymbol methodClass) {
super(methodClass, TypeMetadata.EMPTY);
this.argtypes = argtypes;
this.restype = restype;
this.thrown = thrown;
}
@Override
public MethodType cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to a method type");
}
@Override
public TypeTag getTag() {
return METHOD;
}
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitMethodType(this, s);
}
@DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
StringBuilder sb = new StringBuilder();
appendAnnotationsString(sb);
sb.append('(');
sb.append(argtypes);
sb.append(')');
sb.append(restype);
return sb.toString();
}
@DefinedBy(Api.LANGUAGE_MODEL)
public List<Type> getParameterTypes() { return argtypes; }
@DefinedBy(Api.LANGUAGE_MODEL)
public Type getReturnType() { return restype; }
@DefinedBy(Api.LANGUAGE_MODEL)
public Type getReceiverType() { return recvtype; }
@DefinedBy(Api.LANGUAGE_MODEL)
public List<Type> getThrownTypes() { return thrown; }
public boolean isErroneous() {
return
isErroneous(argtypes) ||
restype != null && restype.isErroneous();
}
public boolean contains(Type elem) {
return elem.equalsIgnoreMetadata(this) || contains(argtypes, elem) || restype.contains(elem) || contains(thrown, elem);
}
public MethodType asMethodType() { return this; }
public void complete() {
for (List<Type> l = argtypes; l.nonEmpty(); l = l.tail)
l.head.complete();
restype.complete();
recvtype.complete();
for (List<Type> l = thrown; l.nonEmpty(); l = l.tail)
l.head.complete();
}
@DefinedBy(Api.LANGUAGE_MODEL)
public List<TypeVar> getTypeVariables() {
return List.nil();
}
public TypeSymbol asElement() {
return null;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.EXECUTABLE;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitExecutable(this, p);
}
}
public static class PackageType extends Type implements NoType {
PackageType(PackageSymbol tsym) {
super(tsym, TypeMetadata.EMPTY);
}
@Override
public PackageType cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to a package type");
}
@Override
public TypeTag getTag() {
return PACKAGE;
}
@Override
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitPackageType(this, s);
}
@DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
return tsym.getQualifiedName().toString();
}
@DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.PACKAGE;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitNoType(this, p);
}
}
public static class ModuleType extends Type implements NoType {
ModuleType(ModuleSymbol tsym) {
super(tsym, TypeMetadata.EMPTY);
}
@Override
public ModuleType cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to a module type");
}
@Override
public ModuleType annotatedType(List<Attribute.TypeCompound> annos) {
throw new AssertionError("Cannot annotate a module type");
}
@Override
public TypeTag getTag() {
return TypeTag.MODULE;
}
@Override
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitModuleType(this, s);
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
return tsym.getQualifiedName().toString();
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.MODULE;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitNoType(this, p);
}
}
public static class TypeVar extends Type implements TypeVariable {
public Type bound = null;
public Type lower;
public TypeVar(Name name, Symbol owner, Type lower) {
super(null, TypeMetadata.EMPTY);
tsym = new TypeVariableSymbol(0, name, this, owner);
this.bound = null;
this.lower = lower;
}
public TypeVar(TypeSymbol tsym, Type bound, Type lower) {
this(tsym, bound, lower, TypeMetadata.EMPTY);
}
public TypeVar(TypeSymbol tsym, Type bound, Type lower,
TypeMetadata metadata) {
super(tsym, metadata);
this.bound = bound;
this.lower = lower;
}
@Override
public TypeVar cloneWithMetadata(TypeMetadata md) {
return new TypeVar(tsym, bound, lower, md) {
@Override
public Type baseType() { return TypeVar.this.baseType(); }
};
}
@Override
public TypeTag getTag() {
return TYPEVAR;
}
@Override
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitTypeVar(this, s);
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public Type getUpperBound() {
if ((bound == null || bound.hasTag(NONE)) && this != tsym.type) {
bound = tsym.type.getUpperBound();
}
return bound;
}
int rank_field = -1;
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public Type getLowerBound() {
return lower;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.TYPEVAR;
}
public boolean isCaptured() {
return false;
}
@Override
public boolean isReference() {
return true;
}
@Override
public boolean isNullOrReference() {
return true;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitTypeVariable(this, p);
}
}
public static class CapturedType extends TypeVar {
public WildcardType wildcard;
public CapturedType(Name name,
Symbol owner,
Type upper,
Type lower,
WildcardType wildcard) {
super(name, owner, lower);
this.lower = Assert.checkNonNull(lower);
this.bound = upper;
this.wildcard = wildcard;
}
public CapturedType(TypeSymbol tsym,
Type bound,
Type upper,
Type lower,
WildcardType wildcard,
TypeMetadata metadata) {
super(tsym, bound, lower, metadata);
this.wildcard = wildcard;
}
@Override
public CapturedType cloneWithMetadata(TypeMetadata md) {
return new CapturedType(tsym, bound, bound, lower, wildcard, md) {
@Override
public Type baseType() { return CapturedType.this.baseType(); }
};
}
@Override
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitCapturedType(this, s);
}
@Override
public boolean isCaptured() {
return true;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
StringBuilder sb = new StringBuilder();
appendAnnotationsString(sb);
sb.append("capture#");
sb.append((hashCode() & 0xFFFFFFFFL) % Printer.PRIME);
sb.append(" of ");
sb.append(wildcard);
return sb.toString();
}
}
public static abstract class DelegatedType extends Type {
public Type qtype;
public TypeTag tag;
public DelegatedType(TypeTag tag, Type qtype) {
this(tag, qtype, TypeMetadata.EMPTY);
}
public DelegatedType(TypeTag tag, Type qtype,
TypeMetadata metadata) {
super(qtype.tsym, metadata);
this.tag = tag;
this.qtype = qtype;
}
public TypeTag getTag() { return tag; }
@DefinedBy(Api.LANGUAGE_MODEL)
public String toString() { return qtype.toString(); }
public List<Type> getTypeArguments() { return qtype.getTypeArguments(); }
public Type getEnclosingType() { return qtype.getEnclosingType(); }
public List<Type> getParameterTypes() { return qtype.getParameterTypes(); }
public Type getReturnType() { return qtype.getReturnType(); }
public Type getReceiverType() { return qtype.getReceiverType(); }
public List<Type> getThrownTypes() { return qtype.getThrownTypes(); }
public List<Type> allparams() { return qtype.allparams(); }
public Type getUpperBound() { return qtype.getUpperBound(); }
public boolean isErroneous() { return qtype.isErroneous(); }
}
public static class ForAll extends DelegatedType implements ExecutableType {
public List<Type> tvars;
public ForAll(List<Type> tvars, Type qtype) {
super(FORALL, (MethodType)qtype);
this.tvars = tvars;
}
@Override
public ForAll cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to a forall type");
}
@Override
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitForAll(this, s);
}
@DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
StringBuilder sb = new StringBuilder();
appendAnnotationsString(sb);
sb.append('<');
sb.append(tvars);
sb.append('>');
sb.append(qtype);
return sb.toString();
}
public List<Type> getTypeArguments() { return tvars; }
public boolean isErroneous() {
return qtype.isErroneous();
}
public boolean contains(Type elem) {
return qtype.contains(elem);
}
public MethodType asMethodType() {
return (MethodType)qtype;
}
public void complete() {
for (List<Type> l = tvars; l.nonEmpty(); l = l.tail) {
((TypeVar)l.head).bound.complete();
}
qtype.complete();
}
@DefinedBy(Api.LANGUAGE_MODEL)
public List<TypeVar> getTypeVariables() {
return List.convert(TypeVar.class, getTypeArguments());
}
@DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.EXECUTABLE;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitExecutable(this, p);
}
}
public static class UndetVar extends DelegatedType {
enum Kind {
NORMAL,
CAPTURED,
THROWS;
}
public interface UndetVarListener {
void varBoundChanged(UndetVar uv, InferenceBound ib, Type bound, boolean update);
default void varInstantiated(UndetVar uv) { Assert.error(); }
}
public enum InferenceBound {
LOWER {
public InferenceBound complement() { return UPPER; }
},
EQ {
public InferenceBound complement() { return EQ; }
},
UPPER {
public InferenceBound complement() { return LOWER; }
};
public abstract InferenceBound complement();
public boolean lessThan(InferenceBound that) {
if (that == this) {
return false;
} else {
switch (that) {
case UPPER: return true;
case LOWER: return false;
case EQ: return (this != UPPER);
default:
Assert.error("Cannot get here!");
return false;
}
}
}
}
public ArrayDeque<IncorporationAction> incorporationActions = new ArrayDeque<>();
protected Map<InferenceBound, List<Type>> bounds;
private Type inst = null;
public int declaredCount;
public UndetVarListener listener = null;
Kind kind;
@Override
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitUndetVar(this, s);
}
public UndetVar(TypeVar origin, UndetVarListener listener, Types types) {
super(UNDETVAR, origin);
this.kind = origin.isCaptured() ?
Kind.CAPTURED :
Kind.NORMAL;
this.listener = listener;
bounds = new EnumMap<>(InferenceBound.class);
List<Type> declaredBounds = types.getBounds(origin);
declaredCount = declaredBounds.length();
bounds.put(InferenceBound.UPPER, List.nil());
bounds.put(InferenceBound.LOWER, List.nil());
bounds.put(InferenceBound.EQ, List.nil());
for (Type t : declaredBounds.reverse()) {
addBound(InferenceBound.UPPER, t, types, true);
}
if (origin.isCaptured() && !origin.lower.hasTag(BOT)) {
addBound(InferenceBound.LOWER, origin.lower, types, true);
}
}
@DefinedBy(Api.LANGUAGE_MODEL)
public String toString() {
StringBuilder sb = new StringBuilder();
appendAnnotationsString(sb);
if (inst == null) {
sb.append(qtype);
sb.append('?');
} else {
sb.append(inst);
}
return sb.toString();
}
public String debugString() {
String result = "inference var = " + qtype + "\n";
if (inst != null) {
result += "inst = " + inst + '\n';
}
for (InferenceBound bound: InferenceBound.values()) {
List<Type> aboundList = bounds.get(bound);
if (aboundList.size() > 0) {
result += bound + " = " + aboundList + '\n';
}
}
return result;
}
public void setThrow() {
if (this.kind == Kind.CAPTURED) {
throw new IllegalStateException();
}
this.kind = Kind.THROWS;
}
public UndetVar dup(Types types) {
UndetVar uv2 = new UndetVar((TypeVar)qtype, listener, types);
dupTo(uv2, types);
return uv2;
}
public void dupTo(UndetVar uv2, Types types) {
uv2.listener = null;
uv2.bounds.clear();
for (InferenceBound ib : InferenceBound.values()) {
uv2.bounds.put(ib, List.nil());
for (Type t : getBounds(ib)) {
uv2.addBound(ib, t, types, true);
}
}
uv2.inst = inst;
uv2.listener = listener;
uv2.incorporationActions = new ArrayDeque<>();
for (IncorporationAction action : incorporationActions) {
uv2.incorporationActions.add(action.dup(uv2));
}
}
@Override
public UndetVar cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to an UndetVar type");
}
@Override
public boolean isPartial() {
return true;
}
@Override
public Type baseType() {
return (inst == null) ? this : inst.baseType();
}
public Type getInst() {
return inst;
}
public void setInst(Type inst) {
this.inst = inst;
if (listener != null) {
listener.varInstantiated(this);
}
}
public List<Type> getBounds(InferenceBound... ibs) {
ListBuffer<Type> buf = new ListBuffer<>();
for (InferenceBound ib : ibs) {
buf.appendList(bounds.get(ib));
}
return buf.toList();
}
public List<Type> getDeclaredBounds() {
ListBuffer<Type> buf = new ListBuffer<>();
int count = 0;
for (Type b : getBounds(InferenceBound.UPPER)) {
if (count++ == declaredCount) break;
buf.append(b);
}
return buf.toList();
}
public void setBounds(InferenceBound ib, List<Type> newBounds) {
bounds.put(ib, newBounds);
}
public final void addBound(InferenceBound ib, Type bound, Types types) {
if (types.mapCapturesToBounds) {
switch (ib) {
case LOWER:
bound = types.cvarUpperBound(bound);
break;
case UPPER:
Type altBound = types.cvarLowerBound(bound);
if (!altBound.hasTag(TypeTag.BOT)) bound = altBound;
break;
}
}
addBound(ib, bound, types, false);
}
@SuppressWarnings("fallthrough")
private void addBound(InferenceBound ib, Type bound, Types types, boolean update) {
if (kind == Kind.CAPTURED && !update) {
if (bound.hasTag(UNDETVAR) && !((UndetVar)bound).isCaptured()) {
((UndetVar)bound).addBound(ib.complement(), this, types, false);
}
} else {
Type bound2 = bound.map(toTypeVarMap).baseType();
List<Type> prevBounds = bounds.get(ib);
if (bound == qtype) return;
for (Type b : prevBounds) {
if (types.isSameType(b, bound2, true)) return;
}
bounds.put(ib, prevBounds.prepend(bound2));
notifyBoundChange(ib, bound2, false);
}
}
TypeMapping<Void> toTypeVarMap = new StructuralTypeMapping<Void>() {
@Override
public Type visitUndetVar(UndetVar uv, Void _unused) {
return uv.inst != null ? uv.inst : uv.qtype;
}
};
public void substBounds(List<Type> from, List<Type> to, Types types) {
final ListBuffer<Pair<InferenceBound, Type>> boundsChanged = new ListBuffer<>();
UndetVarListener prevListener = listener;
try {
listener = (uv, ib, t, _ignored) -> {
Assert.check(uv == UndetVar.this);
boundsChanged.add(new Pair<>(ib, t));
};
for (Map.Entry<InferenceBound, List<Type>> _entry : bounds.entrySet()) {
InferenceBound ib = _entry.getKey();
List<Type> prevBounds = _entry.getValue();
ListBuffer<Type> newBounds = new ListBuffer<>();
ListBuffer<Type> deps = new ListBuffer<>();
for (Type t : prevBounds) {
if (!t.containsAny(from)) {
newBounds.append(t);
} else {
deps.append(t);
}
}
bounds.put(ib, newBounds.toList());
for (Type dep : deps) {
addBound(ib, types.subst(dep, from, to), types, true);
}
}
} finally {
listener = prevListener;
for (Pair<InferenceBound, Type> boundUpdate : boundsChanged) {
notifyBoundChange(boundUpdate.fst, boundUpdate.snd, true);
}
}
}
private void notifyBoundChange(InferenceBound ib, Type bound, boolean update) {
if (listener != null) {
listener.varBoundChanged(this, ib, bound, update);
}
}
public final boolean isCaptured() {
return kind == Kind.CAPTURED;
}
public final boolean isThrows() {
return kind == Kind.THROWS;
}
}
public static class JCNoType extends Type implements NoType {
public JCNoType() {
super(null, TypeMetadata.EMPTY);
}
@Override
public JCNoType cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to a JCNoType");
}
@Override
public TypeTag getTag() {
return NONE;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.NONE;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitNoType(this, p);
}
@Override
public boolean isCompound() { return false; }
}
public static class JCVoidType extends Type implements NoType {
public JCVoidType() {
super(null, TypeMetadata.EMPTY);
}
@Override
public JCVoidType cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to a void type");
}
@Override
public TypeTag getTag() {
return VOID;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.VOID;
}
@Override
public boolean isCompound() { return false; }
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitNoType(this, p);
}
@Override
public boolean isPrimitiveOrVoid() {
return true;
}
}
static class BottomType extends Type implements NullType {
public BottomType() {
super(null, TypeMetadata.EMPTY);
}
@Override
public BottomType cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to a bottom type");
}
@Override
public TypeTag getTag() {
return BOT;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.NULL;
}
@Override
public boolean isCompound() { return false; }
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitNull(this, p);
}
@Override
public Type constType(Object value) {
return this;
}
@Override
public String stringValue() {
return "null";
}
@Override
public boolean isNullOrReference() {
return true;
}
}
public static class ErrorType extends ClassType
implements javax.lang.model.type.ErrorType {
private Type originalType = null;
public ErrorType(ClassSymbol c, Type originalType) {
this(originalType, c);
c.type = this;
c.kind = ERR;
c.members_field = new Scope.ErrorScope(c);
}
public ErrorType(Type originalType, TypeSymbol tsym) {
super(noType, List.nil(), null);
this.tsym = tsym;
this.originalType = (originalType == null ? noType : originalType);
}
private ErrorType(Type originalType, TypeSymbol tsym,
TypeMetadata metadata) {
super(noType, List.nil(), null, metadata);
this.tsym = tsym;
this.originalType = (originalType == null ? noType : originalType);
}
@Override
public ErrorType cloneWithMetadata(TypeMetadata md) {
return new ErrorType(originalType, tsym, md) {
@Override
public Type baseType() { return ErrorType.this.baseType(); }
};
}
@Override
public TypeTag getTag() {
return ERROR;
}
@Override
public boolean isPartial() {
return true;
}
@Override
public boolean isReference() {
return true;
}
@Override
public boolean isNullOrReference() {
return true;
}
public ErrorType(Name name, TypeSymbol container, Type originalType) {
this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType);
}
@Override
public <R,S> R accept(Type.Visitor<R,S> v, S s) {
return v.visitErrorType(this, s);
}
public Type constType(Object constValue) { return this; }
@DefinedBy(Api.LANGUAGE_MODEL)
public Type getEnclosingType() { return this; }
public Type getReturnType() { return this; }
public Type asSub(Symbol sym) { return this; }
public boolean isGenType(Type t) { return true; }
public boolean isErroneous() { return true; }
public boolean isCompound() { return false; }
public boolean isInterface() { return false; }
public List<Type> allparams() { return List.nil(); }
@DefinedBy(Api.LANGUAGE_MODEL)
public List<Type> getTypeArguments() { return List.nil(); }
@DefinedBy(Api.LANGUAGE_MODEL)
public TypeKind getKind() {
return TypeKind.ERROR;
}
public Type getOriginalType() {
return originalType;
}
@DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitError(this, p);
}
}
public static class UnknownType extends Type {
public UnknownType() {
super(null, TypeMetadata.EMPTY);
}
@Override
public UnknownType cloneWithMetadata(TypeMetadata md) {
throw new AssertionError("Cannot add metadata to an unknown type");
}
@Override
public TypeTag getTag() {
return UNKNOWN;
}
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public <R, P> R accept(TypeVisitor<R, P> v, P p) {
return v.visitUnknown(this, p);
}
@Override
public boolean isPartial() {
return true;
}
}
public interface Visitor<R,S> {
R visitClassType(ClassType t, S s);
R visitWildcardType(WildcardType t, S s);
R visitArrayType(ArrayType t, S s);
R visitMethodType(MethodType t, S s);
R visitPackageType(PackageType t, S s);
R visitModuleType(ModuleType t, S s);
R visitTypeVar(TypeVar t, S s);
R visitCapturedType(CapturedType t, S s);
R visitForAll(ForAll t, S s);
R visitUndetVar(UndetVar t, S s);
R visitErrorType(ErrorType t, S s);
R visitType(Type t, S s);
}
}