boolean (@NotNull PsiMethod method, @NotNull Collection<? extends PsiReference> references, @NotNull Collection<? extends PsiElement> deleted, PsiElement @NotNull [] allElementsToDelete) { PsiClass containingClass = method.getContainingClass(); if(containingClass == null) { return false; } PsiManager manager = method.getManager(); JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject()); PsiElementFactory factory = facade.getElementFactory(); PsiModifierList privateModifierList; try { PsiMethod newMethod = factory.createMethod("x3", PsiTypes.voidType()); privateModifierList = newMethod.getModifierList(); privateModifierList.setModifierProperty(PsiModifier.PRIVATE, true); } catch (IncorrectOperationException e) { LOG.error(e); return false; } for (PsiReference reference : references) { PsiElement element = reference.getElement(); if (!isInside(element, allElementsToDelete) && !isInside(element, deleted) && !facade.getResolveHelper().isAccessible(method, privateModifierList, element, null, null)) { return false; } } return true; }