com.intellij.psi.search.DelegatingGlobalSearchScope Java Examples

The following examples show how to use com.intellij.psi.search.DelegatingGlobalSearchScope. 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: BlazeJavascriptResolveScopeProvider.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public GlobalSearchScope getElementResolveScope(PsiElement element) {
  Project project = element.getProject();
  if (!Blaze.isBlazeProject(project)) {
    return null;
  }
  ExternalLibraryManager manager = ExternalLibraryManager.getInstance(project);
  SyntheticLibrary library =
      element.getLanguage() instanceof TypeScriptLanguageDialect
          ? manager.getLibrary(BlazeTypeScriptAdditionalLibraryRootsProvider.class)
          : manager.getLibrary(BlazeJavascriptAdditionalLibraryRootsProvider.class);
  if (library == null) {
    return null;
  }
  GlobalSearchScope baseScope = getBaseScope(element);
  if (baseScope == null) {
    return null;
  }
  return new DelegatingGlobalSearchScope(baseScope) {
    @Override
    public boolean contains(VirtualFile file) {
      return super.contains(file) || library.contains(file);
    }
  };
}
 
Example #2
Source File: ExternalModuleBuildGlobalSearchScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ExternalModuleBuildGlobalSearchScope(@Nonnull final Project project, @Nonnull GlobalSearchScope baseScope, @Nonnull String externalModulePath) {
  super(new DelegatingGlobalSearchScope(baseScope) {
    @javax.annotation.Nullable
    @Override
    public Project getProject() {
      return project;
    }
  });
  this.externalModulePath = externalModulePath;
}
 
Example #3
Source File: ResolveScopeManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private GlobalSearchScope getInherentResolveScope(VirtualFile vFile) {
  ProjectFileIndex projectFileIndex = myProjectRootManager.getFileIndex();
  Module module = projectFileIndex.getModuleForFile(vFile);
  if (module != null) {
    boolean includeTests = TestSourcesFilter.isTestSources(vFile, myProject);
    return GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, includeTests);
  }
  else {
    // resolve references in libraries in context of all modules which contain it
    List<Module> modulesLibraryUsedIn = new ArrayList<>();
    List<OrderEntry> orderEntries = projectFileIndex.getOrderEntriesForFile(vFile);

    LibraryOrderEntry lib = null;
    for (OrderEntry entry : orderEntries) {
      if (entry instanceof ModuleExtensionWithSdkOrderEntry) {
        modulesLibraryUsedIn.add(entry.getOwnerModule());
      }
      else if (entry instanceof LibraryOrderEntry) {
        lib = (LibraryOrderEntry)entry;
        modulesLibraryUsedIn.add(entry.getOwnerModule());
      }
      else if (entry instanceof ModuleOrderEntry) {
        modulesLibraryUsedIn.add(entry.getOwnerModule());
      }
      else if (entry instanceof OrderEntryWithTracking) {
        modulesLibraryUsedIn.add(entry.getOwnerModule());
      }
    }

    GlobalSearchScope allCandidates = LibraryScopeCache.getInstance(myProject).getScopeForLibraryUsedIn(modulesLibraryUsedIn);
    if (lib != null) {
      final LibraryRuntimeClasspathScope preferred = new LibraryRuntimeClasspathScope(myProject, lib);
      // prefer current library
      return new DelegatingGlobalSearchScope(allCandidates, preferred) {
        @Override
        public int compare(@Nonnull VirtualFile file1, @Nonnull VirtualFile file2) {
          boolean c1 = preferred.contains(file1);
          boolean c2 = preferred.contains(file2);
          if (c1 && !c2) return 1;
          if (c2 && !c1) return -1;

          return super.compare(file1, file2);
        }
      };
    }
    return allCandidates;
  }
}