PsiFile (final @NotNull FileType fileType, @NotNull String text, @Nullable String _extension) { try { final String extension = _extension == null ? fileType.getDefaultExtension() : _extension; File dir = createTempDirectory(); final File tempFile = FileUtil.createTempFile(dir, "tempFile", "." + extension, true); CodeInsightTestFixtureImpl.associateExtensionTemporarily(fileType, extension, getTestRootDisposable()); final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempFile); assert vFile != null; WriteAction.runAndWait(() -> { vFile.setCharset(StandardCharsets.UTF_8); VfsUtil.saveText(vFile, text); }); final VirtualFile vdir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir); PsiTestUtil.addSourceRoot(myModule, vdir); configureByExistingFile(vFile); assertEquals(fileType, myFile.getVirtualFile().getFileType()); return myFile; } catch (IOException e) { throw new RuntimeException(e); } }