PsiType (PsiType type, PsiType returnType, PsiClass containingClass, PsiMethod method) { if (containingClass != null && containingClass.getTypeParameters().length == 1) { final PsiSubstitutor substitutor = PsiResolveHelper.getInstance(method.getProject()) .inferTypeArguments(containingClass.getTypeParameters(), new PsiType[]{type}, new PsiType[]{returnType}, PsiUtil.getLanguageLevel( method)); final PsiTypeParameter typeParameter = containingClass.getTypeParameters()[0]; final PsiType substituted = substitutor.substitute(typeParameter); if (substituted != null && !typeParameter.equals(PsiUtil.resolveClassInClassTypeOnly(substituted))) { return substituted; } } return null; }