PsiFile (@NotNull VirtualFile copy, @NotNull SelectionAndCaretMarkupLoader loader) { assertInitialized(); ApplicationManager.getApplication().invokeAndWait(() -> { if (!copy.getFileType().isBinary()) { switch (mySelectionAndCaretMarkupApplyPolicy) { case UPDATE_FILE_AND_KEEP_DOCUMENT_CLEAN -> { try { ApplicationManager.getApplication().runWriteAction((ThrowableComputable<Void, IOException>)() -> { copy.setBinaryContent(loader.newFileText.getBytes(copy.getCharset())); return null; }); } catch (IOException e) { throw new RuntimeException(e); } } case UPDATE_DOCUMENT_AND_LEAVE_IT_DIRTY -> { Document document = FileDocumentManager.getInstance().getDocument(copy); if (document == null) { throw new IllegalStateException("Document not found: " + copy); } WriteAction.runAndWait(() -> document.setText(loader.newFileText)); } default -> throw new IllegalArgumentException(String.valueOf(mySelectionAndCaretMarkupApplyPolicy)); } } setFileAndEditor(copy, createEditor(copy)); if (editor == null) { fail("editor couldn't be created for: " + copy.getPath() + ", use copyFileToProject() instead of configureByFile()"); } EditorTestUtil.setCaretsAndSelection(editor, loader.caretState); Module module = getModule(); if (module != null) { FacetManager facetManager = FacetManager.getInstance(module); for (Facet<?> facet : facetManager.getAllFacets()) { facetManager.facetConfigurationChanged(facet); } } PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); if (caresAboutInjection) { setupEditorForInjectedLanguage(); } IdeaTestExecutionPolicy policy = IdeaTestExecutionPolicy.current(); if (policy != null) { policy.testFileConfigured(getFile()); } }); return getFile(); }