PsiFile (@NotNull PsiFile file) { LightVirtualFile copy = new LightVirtualFile(file.getName(), file.getText()); copy.setOriginalFile(file.getViewProvider().getVirtualFile()); PsiFile dummyCopy = Objects.requireNonNull(file.getManager().findFile(copy)); if (dummyCopy instanceof PsiFileImpl) { ((PsiFileImpl)dummyCopy).setOriginalFile(file); } return dummyCopy; }