void () { @Language("JAVA") String fileText = """ public class X{ void foo() { bar(); bar(); } void bar() {} }"""; PsiFile psiFile = myFixture.addFileToProject("X.java", fileText); PsiElement[] members = psiFile.getChildren()[psiFile.getChildren().length - 1].getChildren(); PsiNamedElement bar = (PsiNamedElement)members[members.length - 3]; assertEquals("bar", bar.getName()); FindUsagesManager usagesManager = ((FindManagerImpl)FindManager.getInstance(getProject())).getFindUsagesManager(); FindUsagesHandler handler = usagesManager.getNewFindUsagesHandler(bar, false); UsageViewImpl usageView = (UsageViewImpl)usagesManager .doFindUsages(new PsiElement[]{bar}, PsiElement.EMPTY_ARRAY, handler, handler.getFindUsagesOptions(), false); waitForUsages(usageView); Disposer.register(myFixture.getTestRootDisposable(), usageView); assertTrue(usageView.canPerformReRun()); PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject()); Document document = documentManager.getDocument(psiFile); String barDef = "void bar() {}\n"; String commentedBarDef = "//" + barDef; WriteCommandAction.runWriteCommandAction(getProject(), () -> { String text = document.getText(); document.replaceString(text.indexOf(barDef), text.indexOf(barDef) + barDef.length(), commentedBarDef); }); documentManager.commitAllDocuments(); assertFalse(usageView.canPerformReRun()); // target invalidated WriteCommandAction.runWriteCommandAction(getProject(), () -> { String text = document.getText(); document.replaceString(text.indexOf(commentedBarDef), text.indexOf(commentedBarDef) + commentedBarDef.length(), barDef); }); documentManager.commitAllDocuments(); assertTrue(usageView.canPerformReRun()); UsageView newView = usageView.doReRun(); Disposer.register(myFixture.getTestRootDisposable(), newView); Set<Usage> usages = newView.getUsages(); assertEquals(2, usages.size()); }