void (@NotNull Project project, PsiDirectory directory, PsiFile newFile, String text) { FileEditorManager editorManager = FileEditorManager.getInstance(directory.getProject()); FileEditor[] fileEditors = editorManager.openFile(newFile.getVirtualFile(), true); if (text != null) { for (FileEditor fileEditor : fileEditors) { if (fileEditor instanceof TextEditor textEditor) { // JSP is not safe to edit via Psi Document document = textEditor.getEditor().getDocument(); document.setText(text); if (ApplicationManager.getApplication().isUnitTestMode()) { FileDocumentManager.getInstance().saveDocument(document); } PsiDocumentManager.getInstance(project).commitDocument(document); break; } } } }