From 22fc79a5725fd78fbce7bd54837f725fc225a59c Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 19 Aug 2010 17:15:50 +0400 Subject: [PATCH] EA-20711 --- .../smartPointers/InjectedSelfElementInfo.java | 5 +++-- .../psi/impl/smartPointers/SelfElementInfo.java | 4 +--- .../smartPointers/SmartPsiElementPointerImpl.java | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/InjectedSelfElementInfo.java b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/InjectedSelfElementInfo.java index eb2dc0f95d82..6d98f3736a25 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/InjectedSelfElementInfo.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/InjectedSelfElementInfo.java @@ -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; } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java index c0b6324ef830..03cb478976a2 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SelfElementInfo.java @@ -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); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java index 4e125e2ba021..507b4fe0856f 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/smartPointers/SmartPsiElementPointerImpl.java @@ -125,8 +125,18 @@ class SmartPsiElementPointerImpl 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) {