EA-20711
authorAlexey Kudravtsev <cdr@intellij.com>
Thu, 19 Aug 2010 13:15:50 +0000 (17:15 +0400)
committerAlexey Kudravtsev <cdr@intellij.com>
Fri, 20 Aug 2010 07:57:02 +0000 (11:57 +0400)
platform/lang-impl/src/com/intellij/psi/impl/smartPointers/InjectedSelfElementInfo.java
platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java
platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java

index eb2dc0f95d82227890e68042f1a5b6512a0a1949..6d98f3736a25245bbc0a70798fd346d5411b4863 100644 (file)
@@ -19,6 +19,7 @@ import com.intellij.injected.editor.DocumentWindow;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.util.TextRange;
 import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NotNull;
 
 /**
 * User: cdr
@@ -26,8 +27,8 @@ import com.intellij.psi.PsiElement;
 class InjectedSelfElementInfo extends SelfElementInfo {
   private DocumentWindow myDocument;
 
-  InjectedSelfElementInfo(PsiElement anchor) {
-    super(anchor);
+  InjectedSelfElementInfo(@NotNull PsiElement anchor, @NotNull Document document) {
+    super(anchor, document);
 
     assert myFile.getContext() != null;
   }
index c0b6324ef8309d6d14fffc588313c0678069da2f..03cb478976a2dcf0d332f992c7e3065752b68303 100644 (file)
@@ -41,7 +41,7 @@ class SelfElementInfo implements SmartPointerElementInfo {
   private Class myType;
   private final Project myProject;
 
-  public SelfElementInfo(PsiElement anchor) {
+  public SelfElementInfo(@NotNull PsiElement anchor, @NotNull Document document) {
     LOG.assertTrue(anchor.isPhysical());
     myFile = anchor.getContainingFile();
     TextRange range = anchor.getTextRange();
@@ -49,9 +49,7 @@ class SelfElementInfo implements SmartPointerElementInfo {
 
     myProject = myFile.getProject();
     final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject);
-    Document document = documentManager.getDocument(myFile);
 
-    LOG.assertTrue(document != null, myFile.getName());
     if (documentManager.isUncommited(document)) {
       mySyncMarkerIsValid = false;
       myMarker = document.createRangeMarker(0, 0, false);
index 4e125e2ba021fda5ac916ec0a386f3765e5db962..507b4fe0856f531b3f34997a91bea45c32e9c7d7 100644 (file)
@@ -125,8 +125,18 @@ class SmartPsiElementPointerImpl<E extends PsiElement> implements SmartPointerEx
       }
     }
 
-    return containingFile.getContext() != null ? new InjectedSelfElementInfo(myElement) :
-           myElement instanceof PsiFile ? new FileElementInfo((PsiFile)myElement) : new SelfElementInfo(myElement);
+    if (myElement instanceof PsiFile) {
+      return new FileElementInfo((PsiFile)myElement);
+    }
+    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
+    Document document = documentManager.getDocument(containingFile);
+    if (document == null) return null;   // must be non-text file
+
+    if (containingFile.getContext() != null) {
+      return new InjectedSelfElementInfo(myElement, document);
+    }
+
+    return new SelfElementInfo(myElement, document);
   }
 
   private static boolean areElementKindEqual(PsiElement element1, PsiElement element2) {