void () { final JavaPsiFacade facade = JavaPsiFacade.getInstance(myProject); final PsiElementFactory elementFactory = facade.getElementFactory(); final PsiResolveHelper resolveHelper = facade.getResolveHelper(); final Map<UsageInfo, PsiElement> replacementMap = new HashMap<>(); for (final PsiClass targetClass : myTargetClasses) { if (skipTargetClass(targetClass)) continue; final PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(mySuperClass, targetClass, PsiSubstitutor.EMPTY); final PsiClassType targetClassType = elementFactory.createType(targetClass, superClassSubstitutor); targetClass.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitTypeElement(final @NotNull PsiTypeElement typeElement) { super.visitTypeElement(typeElement); final PsiType superClassType = typeElement.getType(); if (PsiUtil.resolveClassInClassTypeOnly(superClassType) == mySuperClass) { PsiSubstitutor subst = getSuperClassSubstitutor(superClassType, targetClassType, resolveHelper, targetClass); replacementMap.put(new UsageInfo(typeElement), elementFactory.createTypeElement(elementFactory.createType(targetClass, subst))); } } @Override public void visitNewExpression(final @NotNull PsiNewExpression expression) { super.visitNewExpression(expression); final PsiType superClassType = expression.getType(); if (PsiUtil.resolveClassInType(superClassType) == mySuperClass) { PsiSubstitutor subst = getSuperClassSubstitutor(superClassType, targetClassType, resolveHelper, targetClass); try { final String typeCanonicalText = elementFactory.createType(targetClass, subst).getCanonicalText(); final PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference(); if (classReference != null) { replacementMap.put(new UsageInfo(classReference), elementFactory.createReferenceFromText(typeCanonicalText, expression)); } } catch (IncorrectOperationException e) { LOG.error(e); } } } @Override public void visitReferenceElement(@NotNull PsiJavaCodeReferenceElement reference) { super.visitReferenceElement(reference); if (reference.resolve() == mySuperClass && PsiTreeUtil.getParentOfType(reference, PsiComment.class) != null) { replacementMap.put(new UsageInfo(reference), elementFactory.createClassReferenceElement(targetClass)); } } }); } try { for (Map.Entry<UsageInfo,PsiElement> elementEntry : replacementMap.entrySet()) { final PsiElement element = elementEntry.getKey().getElement(); if (element != null) { element.replace(elementEntry.getValue()); } } } catch (IncorrectOperationException e) { LOG.error(e); } }