2716 }
2717
2718 @Override
2719 public Type visitTypeVar(TypeVar t, Void ignored) {
2720 return classBound(supertype(t));
2721 }
2722
2723 @Override
2724 public Type visitErrorType(ErrorType t, Void ignored) {
2725 return t;
2726 }
2727 };
2728 // </editor-fold>
2729
2730 // <editor-fold defaultstate="collapsed" desc="sub signature / override equivalence">
2731 /**
2732 * Returns true iff the first signature is a <em>sub
2733 * signature</em> of the other. This is <b>not</b> an equivalence
2734 * relation.
2735 *
2736 * @jls section 8.4.2.
2737 * @see #overrideEquivalent(Type t, Type s)
2738 * @param t first signature (possibly raw).
2739 * @param s second signature (could be subjected to erasure).
2740 * @return true if t is a sub signature of s.
2741 */
2742 public boolean isSubSignature(Type t, Type s) {
2743 return isSubSignature(t, s, true);
2744 }
2745
2746 public boolean isSubSignature(Type t, Type s, boolean strict) {
2747 return hasSameArgs(t, s, strict) || hasSameArgs(t, erasure(s), strict);
2748 }
2749
2750 /**
2751 * Returns true iff these signatures are related by <em>override
2752 * equivalence</em>. This is the natural extension of
2753 * isSubSignature to an equivalence relation.
2754 *
2755 * @jls section 8.4.2.
2756 * @see #isSubSignature(Type t, Type s)
2757 * @param t a signature (possible raw, could be subjected to
2758 * erasure).
2759 * @param s a signature (possible raw, could be subjected to
2760 * erasure).
2761 * @return true if either argument is a sub signature of the other.
2762 */
2763 public boolean overrideEquivalent(Type t, Type s) {
2764 return hasSameArgs(t, s) ||
2765 hasSameArgs(t, erasure(s)) || hasSameArgs(erasure(t), s);
2766 }
2767
2768 public boolean overridesObjectMethod(TypeSymbol origin, Symbol msym) {
2769 for (Symbol sym : syms.objectType.tsym.members().getSymbolsByName(msym.name)) {
2770 if (msym.overrides(sym, origin, Types.this, true)) {
2771 return true;
2772 }
2773 }
2774 return false;
2775 }
4197
4198 // <editor-fold defaultstate="collapsed" desc="Return-Type-Substitutable">
4199 /**
4200 * Does t have a result that is a subtype of the result type of s,
4201 * suitable for covariant returns? It is assumed that both types
4202 * are (possibly polymorphic) method types. Monomorphic method
4203 * types are handled in the obvious way. Polymorphic method types
4204 * require renaming all type variables of one to corresponding
4205 * type variables in the other, where correspondence is by
4206 * position in the type parameter list. */
4207 public boolean resultSubtype(Type t, Type s, Warner warner) {
4208 List<Type> tvars = t.getTypeArguments();
4209 List<Type> svars = s.getTypeArguments();
4210 Type tres = t.getReturnType();
4211 Type sres = subst(s.getReturnType(), svars, tvars);
4212 return covariantReturnType(tres, sres, warner);
4213 }
4214
4215 /**
4216 * Return-Type-Substitutable.
4217 * @jls section 8.4.5
4218 */
4219 public boolean returnTypeSubstitutable(Type r1, Type r2) {
4220 if (hasSameArgs(r1, r2))
4221 return resultSubtype(r1, r2, noWarnings);
4222 else
4223 return covariantReturnType(r1.getReturnType(),
4224 erasure(r2.getReturnType()),
4225 noWarnings);
4226 }
4227
4228 public boolean returnTypeSubstitutable(Type r1,
4229 Type r2, Type r2res,
4230 Warner warner) {
4231 if (isSameType(r1.getReturnType(), r2res))
4232 return true;
4233 if (r1.getReturnType().isPrimitive() || r2res.isPrimitive())
4234 return false;
4235
4236 if (hasSameArgs(r1, r2))
4237 return covariantReturnType(r1.getReturnType(), r2res, warner);
|
2716 }
2717
2718 @Override
2719 public Type visitTypeVar(TypeVar t, Void ignored) {
2720 return classBound(supertype(t));
2721 }
2722
2723 @Override
2724 public Type visitErrorType(ErrorType t, Void ignored) {
2725 return t;
2726 }
2727 };
2728 // </editor-fold>
2729
2730 // <editor-fold defaultstate="collapsed" desc="sub signature / override equivalence">
2731 /**
2732 * Returns true iff the first signature is a <em>sub
2733 * signature</em> of the other. This is <b>not</b> an equivalence
2734 * relation.
2735 *
2736 * @jls 8.4.2 Method Signature
2737 * @see #overrideEquivalent(Type t, Type s)
2738 * @param t first signature (possibly raw).
2739 * @param s second signature (could be subjected to erasure).
2740 * @return true if t is a sub signature of s.
2741 */
2742 public boolean isSubSignature(Type t, Type s) {
2743 return isSubSignature(t, s, true);
2744 }
2745
2746 public boolean isSubSignature(Type t, Type s, boolean strict) {
2747 return hasSameArgs(t, s, strict) || hasSameArgs(t, erasure(s), strict);
2748 }
2749
2750 /**
2751 * Returns true iff these signatures are related by <em>override
2752 * equivalence</em>. This is the natural extension of
2753 * isSubSignature to an equivalence relation.
2754 *
2755 * @jls 8.4.2 Method Signature
2756 * @see #isSubSignature(Type t, Type s)
2757 * @param t a signature (possible raw, could be subjected to
2758 * erasure).
2759 * @param s a signature (possible raw, could be subjected to
2760 * erasure).
2761 * @return true if either argument is a sub signature of the other.
2762 */
2763 public boolean overrideEquivalent(Type t, Type s) {
2764 return hasSameArgs(t, s) ||
2765 hasSameArgs(t, erasure(s)) || hasSameArgs(erasure(t), s);
2766 }
2767
2768 public boolean overridesObjectMethod(TypeSymbol origin, Symbol msym) {
2769 for (Symbol sym : syms.objectType.tsym.members().getSymbolsByName(msym.name)) {
2770 if (msym.overrides(sym, origin, Types.this, true)) {
2771 return true;
2772 }
2773 }
2774 return false;
2775 }
4197
4198 // <editor-fold defaultstate="collapsed" desc="Return-Type-Substitutable">
4199 /**
4200 * Does t have a result that is a subtype of the result type of s,
4201 * suitable for covariant returns? It is assumed that both types
4202 * are (possibly polymorphic) method types. Monomorphic method
4203 * types are handled in the obvious way. Polymorphic method types
4204 * require renaming all type variables of one to corresponding
4205 * type variables in the other, where correspondence is by
4206 * position in the type parameter list. */
4207 public boolean resultSubtype(Type t, Type s, Warner warner) {
4208 List<Type> tvars = t.getTypeArguments();
4209 List<Type> svars = s.getTypeArguments();
4210 Type tres = t.getReturnType();
4211 Type sres = subst(s.getReturnType(), svars, tvars);
4212 return covariantReturnType(tres, sres, warner);
4213 }
4214
4215 /**
4216 * Return-Type-Substitutable.
4217 * @jls 8.4.5 Method Result
4218 */
4219 public boolean returnTypeSubstitutable(Type r1, Type r2) {
4220 if (hasSameArgs(r1, r2))
4221 return resultSubtype(r1, r2, noWarnings);
4222 else
4223 return covariantReturnType(r1.getReturnType(),
4224 erasure(r2.getReturnType()),
4225 noWarnings);
4226 }
4227
4228 public boolean returnTypeSubstitutable(Type r1,
4229 Type r2, Type r2res,
4230 Warner warner) {
4231 if (isSameType(r1.getReturnType(), r2res))
4232 return true;
4233 if (r1.getReturnType().isPrimitive() || r2res.isPrimitive())
4234 return false;
4235
4236 if (hasSameArgs(r1, r2))
4237 return covariantReturnType(r1.getReturnType(), r2res, warner);
|