类com.intellij.psi.search.DelegatingGlobalSearchScope源码实例Demo

下面列出了怎么用com.intellij.psi.search.DelegatingGlobalSearchScope的API类实例代码及写法,或者点击链接到github查看源代码。

@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);
    }
  };
}
 
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;
}
 
源代码3 项目: consulo   文件: ResolveScopeManagerImpl.java
@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;
  }
}
 
 类所在包
 类方法
 同包方法