Preserve original file when performing copy for postfix template
authorDenis Zharkov <denis.zharkov@jetbrains.com>
Mon, 23 May 2016 15:07:43 +0000 (18:07 +0300)
committerDenis Zharkov <denis.zharkov@jetbrains.com>
Mon, 23 May 2016 15:07:43 +0000 (18:07 +0300)
platform/lang-impl/src/com/intellij/codeInsight/template/postfix/templates/PostfixLiveTemplate.java

index d0d9c3b4a2cb4c13bc04468a0d9a40908612edd5..08ba6c04aa0bc91de62d66a2d8d67ed5283a6545 100644 (file)
@@ -39,6 +39,7 @@ import com.intellij.psi.PsiDocumentManager;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.PsiFileFactory;
+import com.intellij.psi.impl.source.PsiFileImpl;
 import com.intellij.psi.util.PsiUtilCore;
 import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
@@ -278,6 +279,11 @@ public class PostfixLiveTemplate extends CustomLiveTemplateBase {
   public static PsiFile copyFile(@NotNull PsiFile file, @NotNull StringBuilder fileContentWithoutKey) {
     final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(file.getProject());
     PsiFile copy = psiFileFactory.createFileFromText(file.getName(), file.getFileType(), fileContentWithoutKey);
+
+    if (copy instanceof PsiFileImpl) {
+      ((PsiFileImpl) copy).setOriginalFile(file);
+    }
+
     VirtualFile vFile = copy.getVirtualFile();
     if (vFile != null) {
       vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);