/** * Method called to verify that types match; and if there are any placeholders, * replace them in <code>actualType</code>. * * @param sourceType Original base type used for specification/refinement * @param actualType Base type instance after re-resolving, possibly containing type placeholders */ private void _resolveTypePlaceholders(ResolvedType sourceType, ResolvedType actualType) throws IllegalArgumentException { List<ResolvedType> expectedTypes = sourceType.getTypeParameters(); List<ResolvedType> actualTypes = actualType.getTypeParameters(); for (int i = 0, len = expectedTypes.size(); i < len; ++i) { ResolvedType exp = expectedTypes.get(i); ResolvedType act = actualTypes.get(i); if (!_verifyAndResolve(exp, act)) { throw new IllegalArgumentException("Type parameter #"+(i+1)+"/"+len+" differs; expected " +exp.getBriefDescription()+", got "+act.getBriefDescription()); } } }
/** * Method called to verify that types match; and if there are any placeholders, * replace them in <code>actualType</code>. * * @param sourceType Original base type used for specification/refinement * @param actualType Base type instance after re-resolving, possibly containing type placeholders */ private void _resolveTypePlaceholders(ResolvedType sourceType, ResolvedType actualType) throws IllegalArgumentException { List<ResolvedType> expectedTypes = sourceType.getTypeParameters(); List<ResolvedType> actualTypes = actualType.getTypeParameters(); for (int i = 0, len = expectedTypes.size(); i < len; ++i) { ResolvedType exp = expectedTypes.get(i); ResolvedType act = actualTypes.get(i); if (!_verifyAndResolve(exp, act)) { throw new IllegalArgumentException("Type parameter #"+(i+1)+"/"+len+" differs; expected " +exp.getBriefDescription()+", got "+act.getBriefDescription()); } } }
private boolean _verifyAndResolve(ResolvedType exp, ResolvedType act) { // See if we have an actual type placeholder to resolve; if yes, replace if (act instanceof TypePlaceHolder) { ((TypePlaceHolder) act).actualType(exp); return true; } // if not, try to verify compatibility. But note that we can not // use simple equality as we need to resolve recursively if (exp.getErasedType() != act.getErasedType()) { return false; } // But we can check type parameters "blindly" List<ResolvedType> expectedTypes = exp.getTypeParameters(); List<ResolvedType> actualTypes = act.getTypeParameters(); for (int i = 0, len = expectedTypes.size(); i < len; ++i) { ResolvedType exp2 = expectedTypes.get(i); ResolvedType act2 = actualTypes.get(i); if (!_verifyAndResolve(exp2, act2)) { return false; } } return true; } }
private boolean _verifyAndResolve(ResolvedType exp, ResolvedType act) { // See if we have an actual type placeholder to resolve; if yes, replace if (act instanceof TypePlaceHolder) { ((TypePlaceHolder) act).actualType(exp); return true; } // if not, try to verify compatibility. But note that we can not // use simple equality as we need to resolve recursively if (exp.getErasedType() != act.getErasedType()) { return false; } // But we can check type parameters "blindly" List<ResolvedType> expectedTypes = exp.getTypeParameters(); List<ResolvedType> actualTypes = act.getTypeParameters(); for (int i = 0, len = expectedTypes.size(); i < len; ++i) { ResolvedType exp2 = expectedTypes.get(i); ResolvedType act2 = actualTypes.get(i); if (!_verifyAndResolve(exp2, act2)) { return false; } } return true; } }