private static void adaptSelf( final Type t, final ListBuffer<Type<?>> from, final ListBuffer<Type<?>> to) { try { //if (t.getGenericTypeDefinition() != t) adapt(t.getGenericTypeDefinition(), t, from, to); } catch (AdaptFailure ex) { // Adapt should never fail calculating a mapping from // t.getGenericTypeDefinition() to t as there can be no merge problem. throw new AssertionError(ex); } }
@Override public MemberInfo visitWildcardType(final Type<?> type, final MemberInfo member) { return asMemberOf(upperBound(type), member); }
public static boolean overrides(final MethodInfo method, final MethodInfo other, final boolean checkResult) { if (method == other) { return true; } if (!isOverridableIn(other, method.getDeclaringType())) { return false; } // Check for a direct implementation if (asSuper(method.getDeclaringType(), other.getDeclaringType()) != null) { if (isSubSignature(method, other)) { if (!checkResult) { return true; } if (returnTypeSubstitutable(method, other)) { return true; } } } // Check for an inherited implementation //noinspection SimplifiableIfStatement if (method.isAbstract() || !other.isAbstract()) { return false; } return isSubSignature(method, other) && (!checkResult || resultSubtype(method, other)); }
private static boolean containsTypeEquivalent(final Type t, final Type p) { return isSameType(t, p) || // shortcut containsType(t, p) && containsType(p, t); }
public static boolean returnTypeSubstitutable(final MethodInfo r1, final MethodInfo r2) { if (hasSameArgs(r1, r2)) { return resultSubtype(r1, r2); } return covariantReturnType( r1.getReturnType(), erasure(r2.getReturnType()) ); }
public static ImmutableList<Type<?>> closure(final Type<?> t) { ImmutableList<Type<?>> cl = closureCache.get(t); if (cl == null) { final Type st = superType(t); if (!t.isCompoundType()) { if (st != null && st.getKind() == TypeKind.DECLARED) { cl = insert(closure(st), t); } else if (st != null && st.getKind() == TypeKind.TYPEVAR) { cl = closure(st).prepend(t); } else { cl = ImmutableList.<Type<?>>of(t); } } else { cl = closure(superType(t)); } for (ImmutableList<Type<?>> l = interfaces(t); l.nonEmpty(); l = l.tail) { cl = union(cl, closure(l.head)); } closureCache.put(t, cl); } return cl; }
public static boolean isSubtypeUnchecked(final Type t, final Type s) { if (t.isArray() && s.isArray()) { if (t.getElementType().isPrimitive()) { return isSameType(elementType(t), elementType(s)); } return isSubtypeUnchecked(elementType(t), elementType(s)); } else if (isSubtype(t, s)) { return true; } else if (t.isGenericParameter()) { return isSubtypeUnchecked(t.getExtendsBound(), s); } else if (s.isGenericParameter()) { return isSubtypeUnchecked(t, s.getExtendsBound()); } else if (s.isGenericType() && !s.isGenericTypeDefinition()) { final Type t2 = asSuper(t, s); if (t2 != null) { return true; } } return false; }
final Type capturedDeclaringType = capture(declaringType); t = substitute(memberType, memberType.getGenericTypeParameters(), t.getTypeArguments()); final TypeList A = G.getTypeArguments(); final TypeList T = t.getTypeArguments(); final TypeList S = freshTypeVariables(T); currentS.head = Si = new CapturedType( Si.getDeclaringType(), substitute(Ui, A, S), Type.Bottom, Si.getWildcard() currentS.head = Si = new CapturedType( Si.getDeclaringType(), glb(Ti.getExtendsBound(), substitute(Ui, A, S)), Type.Bottom, Si.getWildcard() currentS.head = Si = new CapturedType( Si.getDeclaringType(), substitute(Ui, A, S), Ti.getSuperBound(), Si.getWildcard() return erasure(t); // some "rare" type involved
return null; else if (isSubtypeNoCapture(t, p)) { return t; else if (isSubtypeNoCapture(p, t)) { return p; final ImmutableList<Type<?>> closure = union(closure(t), closure(p)); final ImmutableList<Type<?>> bounds = closureMin(closure);
public static boolean isSubSignature(final MethodInfo t, final MethodInfo p) { return hasSameArgs(t, p) || containsTypeEquivalent(t.getParameters().getParameterTypes(), erasure(p.getParameters().getParameterTypes())); }
public static boolean isSubtype(final Type t, final Type p, final boolean capture) { if (t == p) { return true; } if (p == null) { return false; } if (p == Types.Object) { return true; } if (p.isCompoundType()) { final Type baseType = p.getBaseType(); if (baseType != null && !isSubtype(t, baseType, capture)) { return false; } final TypeList interfaces = p.getExplicitInterfaces(); for (int i = 0, n = interfaces.size(); i < n; i++) { final Type type = interfaces.get(i); if (!isSubtype(t, type, capture)) { return false; } } return true; } final Type lower = lowerBound(p); if (p != lower) { return isSubtype(capture ? capture(t) : t, lower, false); } return IsSubtypeRelation.visit(capture ? capture(t) : t, p); }
Type base = asOuterSuper(type, owner); base = base.isCompoundType() ? capture(base) : base; TypeBindings.create( ownerBindings.getGenericParameters(), erasure(ownerBindings.getBoundTypes())
if (ap.hasSuperBound() && isSuperType(at, ap.getSuperBound())) { continue; final Type superType = superType(t); final Type ancestor = asSuper(superType, p); if (ancestor != null) { return ancestor; final Type ancestor = asSuper(interfaces.get(i), p); if (ancestor != null) { return ancestor;
public static boolean hasSameArgs(final TypeList t, final TypeList p) { return containsTypeEquivalent(t, p); }
public static boolean resultSubtype(final MethodInfo t, final MethodInfo s) { final TypeList tVars = t.getTypeArguments(); final TypeList sVars = s.getTypeArguments(); final Type tReturn = t.getReturnType(); final Type sReturn = substitute(s.getReturnType(), sVars, tVars); return covariantReturnType(tReturn, sReturn); }
public static Type asOuterSuper(Type t, final Type type) { switch (t.getKind()) { case DECLARED: do { final Type s = asSuper(t, type); if (s != null) { return s; } t = t.getDeclaringType(); } while (t.getKind() == TypeKind.DECLARED); return null; case ARRAY: return isSubtype(t, type) ? type : null; case TYPEVAR: return asSuper(t, type); case ERROR: return t; default: return null; } }
isSubtypeNoCapture(superDeclaringType, sDeclaringType); final Type asSuper = asSuper(t, s); return asSuper != null //&& asSuper == s && isSubtypeNoCapture(asSuper.getDeclaringType(), s.getDeclaringType());
private boolean containsTypeRecursive(final Type t, final Type s) { final TypePair pair = new TypePair(t, s); if (cache.add(pair)) { try { return containsType( t.getTypeArguments(), s.getTypeArguments() ); } finally { cache.remove(pair); } } else { return containsType( t.getTypeArguments(), rewriteSupers(s).getTypeArguments() ); } }
@Override public Type visitTypeParameter(final Type t, final Type p) { if (t == p) { return t; } return asSuper(t.getExtendsBound(), p); }
@Override public MemberInfo visitTypeParameter(final Type<?> type, final MemberInfo member) { return asMemberOf(type.getExtendsBound(), member); }