Document (@NonNls @NotNull String fileName, @NonNls @NotNull String fileText, boolean checkCaret) { return WriteCommandAction.writeCommandAction(null).compute(() -> { Document fakeDocument = new DocumentImpl(fileText); EditorTestUtil.CaretAndSelectionState caretsState = EditorTestUtil.extractCaretAndSelectionMarkers(fakeDocument); if (checkCaret) { assertTrue("No caret specified in " + fileName, caretsState.hasExplicitCaret()); } String newFileText = fakeDocument.getText(); Document document; try { document = setupFileEditorAndDocument(fileName, newFileText); } catch (IOException e) { throw new RuntimeException(e); } EditorTestUtil.setCaretsAndSelection(getEditor(), caretsState); setupEditorForInjectedLanguage(); getIndexingMode().ensureIndexingStatus(getProject()); return document; }); }