void () { @Language("JAVA") String text = "class C1{}\nclass C2 {}"; PsiJavaFile file = (PsiJavaFile)configureByText(JavaFileType.INSTANCE, text); DocumentEx document = (DocumentEx)file.getViewProvider().getDocument(); SmartPsiElementPointer<PsiClass> pointer1 = createPointer(file.getClasses()[0]); SmartPsiElementPointer<PsiClass> pointer2 = createPointer(file.getClasses()[1]); assertEquals("C1", pointer1.getElement().getName()); assertEquals("C2", pointer2.getElement().getName()); gcPointerCache(pointer1, pointer2); TextRange range = file.getClasses()[1].getTextRange(); ApplicationManager.getApplication().runWriteAction(() -> document.moveText(range.getStartOffset(), range.getEndOffset(), 0)); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); assertEquals("C1", pointer1.getElement().getName()); assertEquals("C2", pointer2.getElement().getName()); }