PsiSubstitutor (PsiSubstitutor actual, PsiSubstitutor required) { if (actual == PsiSubstitutor.EMPTY) { return required; } if (required == PsiSubstitutor.EMPTY) { return actual; } PsiSubstitutor result = PsiSubstitutor.createSubstitutor(actual.getSubstitutionMap()); for (Map.Entry<PsiTypeParameter, PsiType> e : required.getSubstitutionMap().entrySet()) { final PsiTypeParameter typeParameter = e.getKey(); final PsiType requiredType = e.getValue(); final PsiType actualType = result.getSubstitutionMap().get(typeParameter); if (requiredType != null && (actualType == null || !TypeConversionUtil.isAssignable(actualType, requiredType))) { result = result.put(typeParameter, requiredType); } } return result; }