boolean (@NotNull PsiMethod method) { PsiClass containingClass = method.getContainingClass(); if (!(containingClass instanceof PsiAnonymousClass)) { return false; } PsiElement parent = containingClass.getParent(); if (parent instanceof PsiNewExpression && PsiUtil.skipParenthesizedExprUp(parent.getParent()) instanceof PsiVariable && !method.getHierarchicalMethodSignature().getSuperSignatures().isEmpty()) { // references outside anonymous class can still resolve to this method, see com.intellij.psi.scope.util.PsiScopesUtil.setupAndRunProcessor() return false; } return MethodReferencesSearch.search(method, new LocalSearchScope(containingClass), false).findFirst() == null; }