use of com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl in project intellij-community by JetBrains.
the class InjectedGeneralHighlightingPass method getInjectedPsiFiles.
@NotNull
private Set<PsiFile> getInjectedPsiFiles(@NotNull final List<PsiElement> elements1, @NotNull final List<PsiElement> elements2, @NotNull final ProgressIndicator progress) {
ApplicationManager.getApplication().assertReadAccessAllowed();
List<DocumentWindow> injected = InjectedLanguageUtil.getCachedInjectedDocuments(myFile);
final Collection<PsiElement> hosts = new THashSet<>(elements1.size() + elements2.size() + injected.size());
//since change in one place can lead to invalidation of injected PSI in (completely) other place.
for (DocumentWindow documentRange : injected) {
progress.checkCanceled();
if (!documentRange.isValid())
continue;
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(documentRange);
if (file == null)
continue;
PsiElement context = InjectedLanguageManager.getInstance(file.getProject()).getInjectionHost(file);
if (context != null && context.isValid() && !file.getProject().isDisposed() && (myUpdateAll || myRestrictRange.intersects(context.getTextRange()))) {
hosts.add(context);
}
}
InjectedLanguageManagerImpl injectedLanguageManager = InjectedLanguageManagerImpl.getInstanceImpl(myProject);
Processor<PsiElement> collectInjectableProcessor = Processors.cancelableCollectProcessor(hosts);
injectedLanguageManager.processInjectableElements(elements1, collectInjectableProcessor);
injectedLanguageManager.processInjectableElements(elements2, collectInjectableProcessor);
final Set<PsiFile> outInjected = new THashSet<>();
final PsiLanguageInjectionHost.InjectedPsiVisitor visitor = new PsiLanguageInjectionHost.InjectedPsiVisitor() {
@Override
public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
synchronized (outInjected) {
outInjected.add(injectedPsi);
}
}
};
if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(hosts), progress, true, element -> {
ApplicationManager.getApplication().assertReadAccessAllowed();
progress.checkCanceled();
InjectedLanguageUtil.enumerate(element, myFile, false, visitor);
return true;
})) {
throw new ProcessCanceledException();
}
synchronized (outInjected) {
return outInjected;
}
}
Aggregations