void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { final PsiElement parent = element.getParent(); final PsiTypeElement typeElement; if (parent instanceof PsiVariable variable) { typeElement = variable.getTypeElement(); } else if (parent instanceof PsiMethod method) { typeElement = method.getReturnTypeElement(); } else { return; } if (typeElement == null) { return; } final PsiJavaCodeReferenceElement componentReferenceElement = typeElement.getInnermostComponentReferenceElement(); boolean isInferredType = typeElement.isInferredType(); if (componentReferenceElement == null && !isInferredType) { return; } final PsiType oldType = typeElement.getType(); if (!(oldType instanceof PsiClassType oldClassType)) { return; } final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); final PsiElementFactory factory = facade.getElementFactory(); final PsiType type = factory.createTypeFromText(fqClassName, element); if (!(type instanceof PsiClassType classType)) { return; } final PsiClass aClass = classType.resolve(); if (aClass != null) { final PsiTypeParameter[] typeParameters = aClass.getTypeParameters(); if (typeParameters.length != 0) { PsiClass newClass = classType.resolve(); if (newClass == null) return; final Map<PsiTypeParameter, PsiType> typeParameterMap = new HashMap<>(); for (int i = 0; i < typeParameters.length; i++) { final PsiTypeParameter typeParameter = typeParameters[i]; final PsiType parameterType = PsiUtil.substituteTypeParameter(oldClassType, newClass, i, false); typeParameterMap.put(typeParameter, parameterType); } final PsiSubstitutor substitutor = factory.createSubstitutor(typeParameterMap); classType = factory.createType(aClass, substitutor); } } final PsiElement replacement; if (isInferredType) { PsiTypeElement newTypeElement = factory.createTypeElement(classType); replacement = new CommentTracker().replaceAndRestoreComments(typeElement, newTypeElement); } else { final PsiJavaCodeReferenceElement referenceElement = factory.createReferenceElementByType(classType); replacement = new CommentTracker().replaceAndRestoreComments(componentReferenceElement, referenceElement); } final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(project); javaCodeStyleManager.shortenClassReferences(replacement); }