import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
+import org.jetbrains.annotations.NotNull;
/**
* User: cdr
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;
}
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();
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);
}
}
- 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) {