PsiType (final PsiType migrationTtype, final PsiType originalType, final boolean isContraVariantPosition) { if ( originalType instanceof PsiClassType && migrationTtype instanceof PsiClassType) { final PsiClass originalClass = ((PsiClassType)originalType).resolve(); if (originalClass != null) { if (isContraVariantPosition && TypeConversionUtil.erasure(originalType).isAssignableFrom(TypeConversionUtil.erasure(migrationTtype))) { final PsiClass psiClass = ((PsiClassType)migrationTtype).resolve(); final PsiSubstitutor substitutor = psiClass != null ? TypeConversionUtil.getClassSubstitutor(originalClass, psiClass, PsiSubstitutor.EMPTY) : null; if (substitutor != null) { final PsiType psiType = substituteType(migrationTtype, originalType, false, psiClass, JavaPsiFacade.getElementFactory(psiClass.getProject()).createType(originalClass, substitutor)); if (psiType != null) { return psiType; } } } else if (!isContraVariantPosition && TypeConversionUtil.erasure(migrationTtype).isAssignableFrom(TypeConversionUtil.erasure(originalType))) { final PsiType psiType = substituteType(migrationTtype, originalType, false, originalClass, JavaPsiFacade.getElementFactory(originalClass.getProject()).createType(originalClass, PsiSubstitutor.EMPTY)); if (psiType != null) { return psiType; } } } } return migrationTtype; }