EA-56496 (diagnostic)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Tue, 3 Feb 2015 10:18:10 +0000 (13:18 +0300)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Tue, 3 Feb 2015 10:18:10 +0000 (13:18 +0300)
platform/core-impl/src/com/intellij/psi/impl/source/text/BlockSupportImpl.java

index 81369fcd59af717e9d10eb66afd34e9408f1c8d6..dfb818728975b2c4ba6d315815772786ccdb444f 100644 (file)
@@ -216,31 +216,39 @@ public class BlockSupportImpl extends BlockSupport {
   public static PsiFileImpl getFileCopy(PsiFileImpl originalFile, FileViewProvider providerCopy) {
     FileViewProvider viewProvider = originalFile.getViewProvider();
     Language language = originalFile.getLanguage();
-    PsiFileImpl newFile = (PsiFileImpl)providerCopy.getPsi(language);
+
+    PsiFile file = providerCopy.getPsi(language);
+    if (file != null && !(file instanceof PsiFileImpl)) {
+      throw new RuntimeException("View provider " + viewProvider + " refused to provide PsiFileImpl for " + language + details(providerCopy, viewProvider));
+    }
+
+    PsiFileImpl newFile = (PsiFileImpl)file;
 
     if (newFile == null && language == PlainTextLanguage.INSTANCE && originalFile == viewProvider.getPsi(viewProvider.getBaseLanguage())) {
       newFile = (PsiFileImpl)providerCopy.getPsi(providerCopy.getBaseLanguage());
     }
 
     if (newFile == null) {
-      throw new RuntimeException("View provider " + viewProvider + " refused to parse text with " + language +
-                                 "; languages: " + viewProvider.getLanguages() +
-                                 "; base: " + viewProvider.getBaseLanguage() +
-                                 "; copy: " + providerCopy +
-                                 "; copy.base: " + providerCopy.getBaseLanguage() +
-                                 "; vFile: " + viewProvider.getVirtualFile() +
-                                 "; copy.vFile: " + providerCopy.getVirtualFile() +
-                                 "; fileType: " + viewProvider.getVirtualFile().getFileType() +
-                                 "; copy.original(): " +
-                                 (providerCopy.getVirtualFile() instanceof LightVirtualFile ? ((LightVirtualFile)providerCopy.getVirtualFile()).getOriginalFile() : null));
+      throw new RuntimeException("View provider " + viewProvider + " refused to parse text with " + language + details(providerCopy, viewProvider));
     }
 
     return newFile;
   }
 
+  private static String details(FileViewProvider providerCopy, FileViewProvider viewProvider) {
+    return "; languages: " + viewProvider.getLanguages() +
+           "; base: " + viewProvider.getBaseLanguage() +
+           "; copy: " + providerCopy +
+           "; copy.base: " + providerCopy.getBaseLanguage() +
+           "; vFile: " + viewProvider.getVirtualFile() +
+           "; copy.vFile: " + providerCopy.getVirtualFile() +
+           "; fileType: " + viewProvider.getVirtualFile().getFileType() +
+           "; copy.original(): " +
+           (providerCopy.getVirtualFile() instanceof LightVirtualFile ? ((LightVirtualFile)providerCopy.getVirtualFile()).getOriginalFile() : null);
+  }
+
   @NotNull
-  private static DiffLog replaceElementWithEvents(@NotNull CompositeElement oldRoot,
-                                                  @NotNull CompositeElement newRoot) {
+  private static DiffLog replaceElementWithEvents(@NotNull CompositeElement oldRoot, @NotNull CompositeElement newRoot) {
     DiffLog diffLog = new DiffLog();
     diffLog.appendReplaceElementWithEvents(oldRoot, newRoot);
     return diffLog;