Java Code Examples for com.intellij.psi.PsiLanguageInjectionHost#InjectedPsiVisitor

The following examples show how to use com.intellij.psi.PsiLanguageInjectionHost#InjectedPsiVisitor . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InjectedGeneralHighlightingPass.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private Set<PsiFile> getInjectedPsiFiles(@Nonnull final List<? extends PsiElement> elements1, @Nonnull final List<? extends PsiElement> elements2, @Nonnull final ProgressIndicator progress) {
  ApplicationManager.getApplication().assertReadAccessAllowed();

  List<DocumentWindow> injected = InjectedLanguageManager.getInstance(myProject).getCachedInjectedDocumentsInRange(myFile, myFile.getTextRange());
  final Collection<PsiElement> hosts = new THashSet<>(elements1.size() + elements2.size() + injected.size());

  //rehighlight all injected PSI regardless the range,
  //since change in one place can lead to invalidation of injected PSI in (completely) other place.
  for (DocumentWindow documentRange : injected) {
    ProgressManager.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 = (injectedPsi, places) -> {
    synchronized (outInjected) {
      outInjected.add(injectedPsi);
    }
  };
  if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(hosts), progress, element -> {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    ProgressManager.checkCanceled();
    InjectedLanguageManager.getInstance(myFile.getProject()).enumerateEx(element, myFile, false, visitor);
    return true;
  })) {
    throw new ProcessCanceledException();
  }
  synchronized (outInjected) {
    return outInjected;
  }
}
 
Example 2
Source File: InjectedLanguageManager.java    From consulo with Apache License 2.0 votes vote down vote up
public abstract void enumerate(@Nonnull PsiElement host, @Nonnull PsiLanguageInjectionHost.InjectedPsiVisitor visitor); 
Example 3
Source File: InjectedLanguageManager.java    From consulo with Apache License 2.0 votes vote down vote up
public abstract void enumerateEx(@Nonnull PsiElement host, @Nonnull PsiFile containingFile, boolean probeUp, @Nonnull PsiLanguageInjectionHost.InjectedPsiVisitor visitor);