use of com.intellij.psi.impl.PsiDocumentManagerBase in project intellij-community by JetBrains.
the class InjectedSelfElementInfo method getInjectedFileIn.
private PsiFile getInjectedFileIn(@NotNull final PsiElement hostContext, @NotNull final PsiFile hostFile, @NotNull final TextRange rangeInHostFile) {
final PsiDocumentManagerBase docManager = (PsiDocumentManagerBase) PsiDocumentManager.getInstance(getProject());
final PsiFile[] result = { null };
final PsiLanguageInjectionHost.InjectedPsiVisitor visitor = new PsiLanguageInjectionHost.InjectedPsiVisitor() {
@Override
public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
Document document = docManager.getDocument(injectedPsi);
if (document instanceof DocumentWindow) {
DocumentWindow window = (DocumentWindow) docManager.getLastCommittedDocument(document);
TextRange hostRange = window.injectedToHost(new TextRange(0, injectedPsi.getTextLength()));
if (hostRange.contains(rangeInHostFile)) {
result[0] = injectedPsi;
}
}
}
};
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getProject());
Document document = documentManager.getDocument(hostFile);
if (document != null && documentManager.isUncommited(document)) {
for (DocumentWindow documentWindow : InjectedLanguageManager.getInstance(getProject()).getCachedInjectedDocuments(hostFile)) {
PsiFile injected = documentManager.getPsiFile(documentWindow);
if (injected != null) {
visitor.visit(injected, Collections.<PsiLanguageInjectionHost.Shred>emptyList());
}
}
} else {
List<Pair<PsiElement, TextRange>> injected = InjectedLanguageManager.getInstance(getProject()).getInjectedPsiFiles(hostContext);
if (injected != null) {
for (Pair<PsiElement, TextRange> pair : injected) {
PsiFile injectedFile = pair.first.getContainingFile();
visitor.visit(injectedFile, ContainerUtil.<PsiLanguageInjectionHost.Shred>emptyList());
}
}
}
return result[0];
}
Aggregations