void (PsiClass innerClass) { for (PsiReference reference : ReferencesSearch.search(innerClass, new LocalSearchScope(myTargetClass)).findAll()) { if (reference.getElement() instanceof PsiJavaCodeReferenceElement refElement && refElement.isValid()) { PsiElement parent = refElement.getParent(); if (parent instanceof PsiAnonymousClass anonymousClass) { parent = anonymousClass.getParent(); } if (parent instanceof PsiNewExpression newExpression) { PsiJavaCodeReferenceElement ref = newExpression.getClassOrAnonymousClassReference(); if (ref != null && PsiDiamondTypeUtil.canCollapseToDiamond(newExpression, newExpression, newExpression.getType())) { RemoveRedundantTypeArgumentsUtil.replaceExplicitWithDiamond(ref.getParameterList()); } } } } }