void () { PsiFile file = configureByText(JavaFileType.INSTANCE, """ class A{ void bar() { int a = foo().goo(); Object r = new Object() { void foo() {} }; }}"""); PsiAnonymousClass anon = SyntaxTraverser.psiTraverser(file).filter(PsiAnonymousClass.class).first(); Arrays.stream(anon.getAllMethods()).forEach(PsiUtilCore::ensureValid); long javaCount = getJavaTracker().getModificationCount(); WriteCommandAction.runWriteCommandAction(getProject(), () -> { TextRange methodRange = anon.getMethods()[0].getTextRange(); getEditor().getDocument().deleteString(methodRange.getStartOffset(), methodRange.getEndOffset()); int gooIndex = file.getText().indexOf("goo"); getEditor().getDocument().deleteString(gooIndex, gooIndex + 3); PsiDocumentManager.getInstance(myProject).commitDocument(getEditor().getDocument()); }); Arrays.stream(anon.getAllMethods()).forEach(PsiUtilCore::ensureValid); assertFalse(javaCount == getJavaTracker().getModificationCount()); }