This commit is contained in:
Alexey Kudravtsev
2010-08-20 11:57:02 +04:00
parent 685d5cde65
commit 22fc79a572
3 changed files with 16 additions and 7 deletions
@@ -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;
}
@@ -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);
@@ -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) {