PsiFile (Project project, PsiFile origFile) { var manager = InjectedLanguageManager.getInstance(project); boolean injectedFragment = manager.isInjectedFragment(origFile); if (!injectedFragment) { PsiElement navigationElement = origFile.getNavigationElement(); if (navigationElement != origFile && navigationElement instanceof PsiFile) { return (PsiFile)navigationElement.copy(); } return (PsiFile)origFile.copy(); } else { return PsiFileFactory.getInstance(project).createFileFromText( origFile.getName(), origFile.getLanguage(), manager.getUnescapedText(origFile), false, true, true, origFile.getVirtualFile()); } }