com.intellij.util.indexing.IdFilter Java Examples

The following examples show how to use com.intellij.util.indexing.IdFilter. 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: FilenameIndex.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static Set<VirtualFile> getVirtualFilesByNameIgnoringCase(@Nonnull final String name, @Nonnull final GlobalSearchScope scope, @Nonnull Project project, @Nullable final IdFilter idFilter) {
  final Set<String> keys = new THashSet<>();
  FileNameIndexService fileNameIndexService = getService();
  fileNameIndexService.processAllFileNames(value -> {
    if (name.equalsIgnoreCase(value)) {
      keys.add(value);
    }
    return true;
  }, scope, idFilter);

  // values accessed outside of processAllKeys
  final Set<VirtualFile> files = new THashSet<>();
  for (String each : keys) {
    files.addAll(fileNameIndexService.getVirtualFilesByName(project, each, scope, idFilter));
  }
  return files;
}
 
Example #2
Source File: CSharpSymbolNameContributor.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Override
public void processElementsWithName(
		@Nonnull String name, @Nonnull Processor<NavigationItem> navigationItemProcessor, @Nonnull FindSymbolParameters findSymbolParameters)
{
	Project project = findSymbolParameters.getProject();
	IdFilter idFilter = findSymbolParameters.getIdFilter();
	GlobalSearchScope searchScope = findSymbolParameters.getSearchScope();

	StubIndex.getInstance().processElements(CSharpIndexKeys.METHOD_INDEX, name, project, searchScope, idFilter,
			DotNetLikeMethodDeclaration.class, (Processor) navigationItemProcessor);
	StubIndex.getInstance().processElements(CSharpIndexKeys.EVENT_INDEX, name, project, searchScope, idFilter,
			DotNetEventDeclaration.class,  (Processor) navigationItemProcessor);
	StubIndex.getInstance().processElements(CSharpIndexKeys.PROPERTY_INDEX, name, project, searchScope, idFilter,
			DotNetPropertyDeclaration.class, (Processor) navigationItemProcessor);
	StubIndex.getInstance().processElements(CSharpIndexKeys.FIELD_INDEX, name, project, searchScope, idFilter,
			DotNetFieldDeclaration.class, (Processor) navigationItemProcessor);
}
 
Example #3
Source File: FilenameIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean processFilesByName(@Nonnull final String name,
                                         boolean directories,
                                         @Nonnull Processor<? super PsiFileSystemItem> processor,
                                         @Nonnull GlobalSearchScope scope,
                                         @Nonnull Project project,
                                         @Nullable IdFilter idFilter) {
  return processFilesByName(name, directories, true, processor, scope, project, idFilter);
}
 
Example #4
Source File: DefaultFileNavigationContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void processNames(@Nonnull final Processor<String> processor, @Nonnull GlobalSearchScope scope, IdFilter filter) {
  long started = System.currentTimeMillis();
  FilenameIndex.processAllFileNames(processor, scope, filter);
  if (LOG.isDebugEnabled()) {
    LOG.debug("All names retrieved:" + (System.currentTimeMillis() - started));
  }
}
 
Example #5
Source File: DefaultChooseByNameItemProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static FindSymbolParameters createParameters(@Nonnull ChooseByNameViewModel base, @Nonnull String pattern, boolean everywhere) {
  ChooseByNameModel model = base.getModel();
  IdFilter idFilter = model instanceof ContributorsBasedGotoByModel ? ((ContributorsBasedGotoByModel)model).getIdFilter(everywhere) : null;
  GlobalSearchScope searchScope = FindSymbolParameters.searchScopeFor(base.getProject(), everywhere);
  return new FindSymbolParameters(pattern, getNamePattern(base, pattern), searchScope, idFilter);
}
 
Example #6
Source File: FileNameIndexServiceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Collection<VirtualFile> getVirtualFilesByName(Project project, @Nonnull String name, @Nonnull GlobalSearchScope scope, IdFilter filter) {
  Set<VirtualFile> files = new THashSet<>();
  myIndex.processValues(FilenameIndexImpl.NAME, name, null, (file, value) -> {
    files.add(file);
    return true;
  }, scope, filter);
  return files;
}
 
Example #7
Source File: StubIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <Key, Psi extends PsiElement> Collection<Psi> getElements(@Nonnull StubIndexKey<Key, Psi> indexKey,
                                                                        @Nonnull Key key,
                                                                        @Nonnull final Project project,
                                                                        @Nullable final GlobalSearchScope scope,
                                                                        @Nullable IdFilter idFilter,
                                                                        @Nonnull Class<Psi> requiredClass) {
  final List<Psi> result = new SmartList<>();
  Processor<Psi> processor = Processors.cancelableCollectProcessor(result);
  getInstance().processElements(indexKey, key, project, scope, idFilter, requiredClass, processor);
  return result;
}
 
Example #8
Source File: StubIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
public <Key, Psi extends PsiElement> boolean processElements(@Nonnull StubIndexKey<Key, Psi> indexKey,
                                                             @Nonnull Key key,
                                                             @Nonnull Project project,
                                                             @Nullable GlobalSearchScope scope,
                                                             @Nullable IdFilter idFilter,
                                                             @Nonnull Class<Psi> requiredClass,
                                                             @Nonnull Processor<? super Psi> processor) {
  return processElements(indexKey, key, project, scope, requiredClass, processor);
}
 
Example #9
Source File: FilenameIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean processFilesByName(@Nonnull final String name,
                                         boolean directories,
                                         boolean caseSensitively,
                                         @Nonnull Processor<? super PsiFileSystemItem> processor,
                                         @Nonnull final GlobalSearchScope scope,
                                         @Nonnull final Project project,
                                         @Nullable IdFilter idFilter) {
  final Collection<VirtualFile> files;

  if (caseSensitively) {
    files = getService().getVirtualFilesByName(project, name, scope, idFilter);
  }
  else {
    files = getVirtualFilesByNameIgnoringCase(name, scope, project, idFilter);
  }

  if (files.isEmpty()) return false;
  PsiManager psiManager = PsiManager.getInstance(project);
  int processedFiles = 0;

  for (VirtualFile file : files) {
    if (!file.isValid()) continue;
    if (!directories && !file.isDirectory()) {
      PsiFile psiFile = psiManager.findFile(file);
      if (psiFile != null) {
        if (!processor.process(psiFile)) return true;
        ++processedFiles;
      }
    }
    else if (directories && file.isDirectory()) {
      PsiDirectory dir = psiManager.findDirectory(file);
      if (dir != null) {
        if (!processor.process(dir)) return true;
        ++processedFiles;
      }
    }
  }
  return processedFiles > 0;
}
 
Example #10
Source File: LSPSymbolContributor.java    From lsp4intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void processNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope globalSearchScope, @Nullable IdFilter idFilter) {
    String queryString = Optional.ofNullable(globalSearchScope.getProject())
        .map(p -> p.getUserData(ChooseByNamePopup.CURRENT_SEARCH_PATTERN)).orElse("");

    workspaceSymbolProvider.workspaceSymbols(queryString, globalSearchScope.getProject()).stream()
        .filter(ni -> globalSearchScope.accept(ni.getFile()))
        .map(NavigationItem::getName)
        .forEach(processor::process);
}
 
Example #11
Source File: CSharpSymbolNameContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public void processNames(@Nonnull Processor<String> stringProcessor, @Nonnull GlobalSearchScope searchScope, @Nullable IdFilter idFilter)
{
	StubIndex.getInstance().processAllKeys(CSharpIndexKeys.METHOD_INDEX, stringProcessor, searchScope, idFilter);
	StubIndex.getInstance().processAllKeys(CSharpIndexKeys.EVENT_INDEX, stringProcessor, searchScope, idFilter);
	StubIndex.getInstance().processAllKeys(CSharpIndexKeys.PROPERTY_INDEX, stringProcessor, searchScope, idFilter);
	StubIndex.getInstance().processAllKeys(CSharpIndexKeys.FIELD_INDEX, stringProcessor, searchScope, idFilter);
}
 
Example #12
Source File: ORModuleContributor.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Override
public void processNames(@NotNull Processor<? super String> processor, @NotNull GlobalSearchScope scope, @Nullable IdFilter filter) {
    Project project = scope.getProject();
    if (project != null) {
        ModuleIndex.getInstance().processAllKeys(project, processor);
    }
}
 
Example #13
Source File: UnityScriptGotoClassContributor.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public String[] getNames(Project project, boolean includeNonProjectItems)
{
	CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(ContainerUtil.<String>newTroveSet());
	processNames(processor, GlobalSearchScope.allScope(project), IdFilter.getProjectIdFilter(project, includeNonProjectItems));
	return processor.toArray(ArrayUtil.STRING_ARRAY_FACTORY);
}
 
Example #14
Source File: CSharpTypeNameContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public NavigationItem[] getItemsByName(String name, final String pattern, Project project, boolean includeNonProjectItems)
{
	CommonProcessors.CollectProcessor<NavigationItem> processor = new CommonProcessors.CollectProcessor<NavigationItem>(ContainerUtil.<NavigationItem>newTroveSet());
	processElementsWithName(name, processor, new FindSymbolParameters(pattern, name, GlobalSearchScope.allScope(project), IdFilter.getProjectIdFilter(project, includeNonProjectItems)));
	return processor.toArray(NavigationItem.ARRAY_FACTORY);
}
 
Example #15
Source File: CSharpTypeNameContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public String[] getNames(Project project, boolean includeNonProjectItems)
{
	CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<String>(ContainerUtil.<String>newTroveSet());
	processNames(processor, GlobalSearchScope.allScope(project), IdFilter.getProjectIdFilter(project, includeNonProjectItems));
	return processor.toArray(ArrayUtil.STRING_ARRAY_FACTORY);
}
 
Example #16
Source File: CSharpShortNameSearcher.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public void collectTypes(@Nonnull String s, @Nonnull GlobalSearchScope searchScope, @Nullable IdFilter filter, @Nonnull final Processor<DotNetTypeDeclaration> processor)
{
	StubIndex.getInstance().processElements(CSharpIndexKeys.TYPE_INDEX, s, myProject, searchScope, filter, CSharpTypeDeclaration.class, processor);

	StubIndex.getInstance().processElements(CSharpIndexKeys.DELEGATE_METHOD_BY_NAME_INDEX, s, myProject, searchScope, filter, CSharpMethodDeclaration.class, methodDeclaration ->
	{
		ProgressManager.checkCanceled();

		CSharpTypeDeclaration typeFromDelegate = CSharpLambdaResolveResultUtil.createTypeFromDelegate(methodDeclaration, DotNetGenericExtractor.EMPTY);
		return processor.process(typeFromDelegate);
	});
}
 
Example #17
Source File: CSharpTypeNameContributor.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public void processElementsWithName(@Nonnull String name, @Nonnull final Processor<NavigationItem> navigationItemProcessor, @Nonnull FindSymbolParameters findSymbolParameters)
{
	Project project = findSymbolParameters.getProject();
	IdFilter idFilter = findSymbolParameters.getIdFilter();
	Processor temp = navigationItemProcessor;
	GlobalSearchScope searchScope = findSymbolParameters.getSearchScope();

	StubIndex.getInstance().processElements(CSharpIndexKeys.TYPE_INDEX, name, project, searchScope, idFilter, CSharpTypeDeclaration.class, temp);
	StubIndex.getInstance().processElements(CSharpIndexKeys.DELEGATE_METHOD_BY_NAME_INDEX, name, project, searchScope, idFilter, CSharpMethodDeclaration.class, temp);
}
 
Example #18
Source File: UnityScriptGotoClassContributor.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems)
{
	CommonProcessors.CollectProcessor<NavigationItem> processor = new CommonProcessors.CollectProcessor<NavigationItem>(ContainerUtil.<NavigationItem>newTroveSet());
	processElementsWithName(name, processor, new FindSymbolParameters(pattern, name, GlobalSearchScope.allScope(project), IdFilter.getProjectIdFilter(project, includeNonProjectItems)));
	return processor.toArray(NavigationItem.ARRAY_FACTORY);
}
 
Example #19
Source File: CSharpShortNameSearcher.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
public void collectTypeNames(@Nonnull Processor<String> processor, @Nonnull GlobalSearchScope searchScope, @Nullable IdFilter filter)
{
	StubIndex.getInstance().processAllKeys(CSharpIndexKeys.TYPE_INDEX, processor, searchScope, filter);
	StubIndex.getInstance().processAllKeys(CSharpIndexKeys.DELEGATE_METHOD_BY_NAME_INDEX, processor, searchScope, filter);
}
 
Example #20
Source File: ContributorsBasedGotoByModel.java    From consulo with Apache License 2.0 4 votes vote down vote up
IdFilter getIdFilter(boolean withLibraries) {
  return IdFilter.getProjectIdFilter(myProject, withLibraries);
}
 
Example #21
Source File: FileNameIndexServiceImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void processAllFileNames(@Nonnull Processor<? super String> processor, @Nonnull GlobalSearchScope scope, IdFilter filter) {
  myIndex.processAllKeys(FilenameIndexImpl.NAME, processor, scope, filter);
}
 
Example #22
Source File: UnityScriptGotoClassContributor.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Override
public void processNames(@Nonnull Processor<String> processor, @Nonnull GlobalSearchScope scope, @Nullable IdFilter filter)
{
	StubIndex.getInstance().processAllKeys(UnityScriptIndexKeys.FILE_BY_NAME_INDEX, processor, scope, filter);
}
 
Example #23
Source File: StubIndex.java    From consulo with Apache License 2.0 4 votes vote down vote up
public <K> boolean processAllKeys(@Nonnull StubIndexKey<K, ?> indexKey, @Nonnull Processor<? super K> processor, @Nonnull GlobalSearchScope scope, @Nullable IdFilter idFilter) {
  return processAllKeys(indexKey, ObjectUtils.assertNotNull(scope.getProject()), processor);
}
 
Example #24
Source File: FileNameIndexService.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
Collection<VirtualFile> getVirtualFilesByName(Project project, @Nonnull String name, @Nonnull GlobalSearchScope scope, @Nullable IdFilter idFilter);
 
Example #25
Source File: FilenameIndex.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void processAllFileNames(@Nonnull Processor<? super String> processor, @Nonnull GlobalSearchScope scope, @Nullable IdFilter filter) {
  getService().processAllFileNames(processor, scope, filter);
}
 
Example #26
Source File: CSharpTypeNameContributor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Override
public void processNames(@Nonnull Processor<String> stringProcessor, @Nonnull GlobalSearchScope searchScope, @Nullable IdFilter idFilter)
{
	StubIndex.getInstance().processAllKeys(CSharpIndexKeys.TYPE_INDEX, stringProcessor, searchScope, idFilter);
	StubIndex.getInstance().processAllKeys(CSharpIndexKeys.DELEGATE_METHOD_BY_NAME_INDEX, stringProcessor, searchScope, idFilter);
}
 
Example #27
Source File: ChooseByNameContributorEx.java    From consulo with Apache License 2.0 votes vote down vote up
void processNames(@Nonnull Processor<String> processor, @Nonnull GlobalSearchScope scope, @Nullable IdFilter filter); 
Example #28
Source File: FileNameIndexService.java    From consulo with Apache License 2.0 votes vote down vote up
void processAllFileNames(@Nonnull Processor<? super String> processor, @Nonnull GlobalSearchScope scope, @Nullable IdFilter filter);