void () { ApplicationManager.getApplication().runWriteAction(() -> { PsiClass aClass = myJavaFacade.findClass("AClass", GlobalSearchScope.allScope(getProject())); assertNotNull(aClass); PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject); Document document = documentManager.getDocument(aClass.getContainingFile()); document.insertString(0, "/******/"); SmartPointerEx pointer = createPointer(aClass.getNameIdentifier()); document.insertString(0, "/**/"); documentManager.commitAllDocuments(); PsiElement element = pointer.getElement(); assertNotNull(element); assertTrue(element.getParent() instanceof PsiClass); assertTrue(element.isValid()); }); }