void () { final VirtualFile vfile = createChildData(myRoot, "X.txt"); String xxx = "xxx"; String text = xxx + " " + xxx + " " + xxx; setFileText(vfile, text); PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(vfile); assertTrue(String.valueOf(psiFile), psiFile instanceof PsiPlainTextFile); SmartPointerManagerImpl manager = getPointerManager(); TextRange range1 = TextRange.from(0, xxx.length()); SmartPsiFileRange pointer1 = manager.createSmartPsiFileRangePointer(psiFile, range1); TextRange range2 = TextRange.from(text.lastIndexOf(xxx), xxx.length()); SmartPsiFileRange pointer2 = manager.createSmartPsiFileRangePointer(psiFile, range2); assertNotNull(FileDocumentManager.getInstance().getCachedDocument(vfile)); GCWatcher watcher = GCWatcher.tracking(psiFile, FileDocumentManager.getInstance().getDocument(vfile)); //noinspection UnusedAssignment psiFile = null; watcher.ensureCollected(); assertNull(FileDocumentManager.getInstance().getCachedDocument(vfile)); assertEquals(pointer1.getRange(), range1); WriteCommandAction.runWriteCommandAction(getProject(), () -> insertString(FileDocumentManager.getInstance().getDocument(vfile), 0, " ")); assertEquals(range1.shiftRight(1), pointer1.getRange()); assertEquals(range2.shiftRight(1), pointer2.getRange()); }