Search in sources :

Example 11 with IdFilter

use of com.intellij.util.indexing.IdFilter in project intellij-plugins by JetBrains.

the class AngularModulesProvider method getDependencies.

@Override
public List<Link> getDependencies(@NotNull PsiFile file) {
    final Project project = file.getProject();
    if (!AngularIndexUtil.hasAngularJS(project))
        return null;
    if (!(file instanceof JSFile))
        return null;
    final SmartPointerManager spm = SmartPointerManager.getInstance(project);
    final List<Link> result = new ArrayList<>();
    final CommonProcessors.CollectProcessor<String> processor = new CommonProcessors.CollectProcessor<>();
    final GlobalSearchScope fileScope = GlobalSearchScope.fileScope(file);
    final int fileId = FileBasedIndex.getFileId(file.getVirtualFile());
    StubIndex.getInstance().processAllKeys(AngularModuleIndex.KEY, processor, fileScope, new IdFilter() {

        @Override
        public boolean containsFileId(int id) {
            return id == fileId;
        }
    });
    for (String key : processor.getResults()) {
        AngularIndexUtil.multiResolve(project, AngularModuleIndex.KEY, key, element -> {
            if (!file.equals(element.getContainingFile()))
                return true;
            final JSCallExpression expression = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
            if (expression != null) {
                final List<String> dependencies = AngularModuleIndex.findDependenciesInModuleDeclaration(expression);
                if (dependencies != null) {
                    for (String dependency : dependencies) {
                        final JSImplicitElement resolve = AngularIndexUtil.resolve(project, AngularModuleIndex.KEY, dependency);
                        if (resolve != null) {
                            result.add(new Link(spm.createSmartPsiElementPointer(element.getNavigationElement()), spm.createSmartPsiElementPointer(resolve.getNavigationElement()), key, resolve.getName(), AngularJSIcons.AngularJS));
                        }
                    }
                }
            }
            return true;
        });
    }
    return result;
}
Also used : IdFilter(com.intellij.util.indexing.IdFilter) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) SmartPointerManager(com.intellij.psi.SmartPointerManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JSFile(com.intellij.lang.javascript.psi.JSFile) CommonProcessors(com.intellij.util.CommonProcessors) JSImplicitElement(com.intellij.lang.javascript.psi.stubs.JSImplicitElement)

Example 12 with IdFilter

use of com.intellij.util.indexing.IdFilter in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoTestLocator method getLocation.

@NotNull
@Override
public List<Location> getLocation(@NotNull String protocolId, @NotNull String path, @NotNull Project project, @NotNull GlobalSearchScope scope) {
    if (PROTOCOL.equals(protocolId)) {
        IdFilter idFilter = GoIdFilter.getTestsFilter(project);
        List<String> locationDataItems = StringUtil.split(path, ".");
        // Location is a function name, e.g. `TestCheckItOut`
        if (locationDataItems.size() == 1) {
            return ContainerUtil.mapNotNull(GoFunctionIndex.find(path, project, scope, idFilter), function -> PsiLocation.fromPsiElement(project, function));
        }
        // Location is a method name, e.g. `FooSuite.TestCheckItOut`
        if (locationDataItems.size() == 2) {
            List<Location> locations = ContainerUtil.newArrayList();
            for (GoTypeSpec typeSpec : GoTypesIndex.find(locationDataItems.get(0), project, scope, idFilter)) {
                for (GoMethodDeclaration method : typeSpec.getMethods()) {
                    if (locationDataItems.get(1).equals(method.getName())) {
                        ContainerUtil.addIfNotNull(locations, PsiLocation.fromPsiElement(method));
                    }
                }
            }
            return locations;
        }
    } else if (SUITE_PROTOCOL.equals(protocolId)) {
        IdFilter idFilter = GoIdFilter.getTestsFilter(project);
        return ContainerUtil.mapNotNull(GoTypesIndex.find(path, project, scope, idFilter), spec -> PsiLocation.fromPsiElement(project, spec));
    } else {
        return Collections.emptyList();
    }
    throw new RuntimeException("Unsupported location: " + path);
}
Also used : GoFunctionIndex(com.goide.stubs.index.GoFunctionIndex) GoTypeSpec(com.goide.psi.GoTypeSpec) GoTypesIndex(com.goide.stubs.index.GoTypesIndex) StringUtil(com.intellij.openapi.util.text.StringUtil) GoMethodDeclaration(com.goide.psi.GoMethodDeclaration) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IdFilter(com.intellij.util.indexing.IdFilter) ContainerUtil(com.intellij.util.containers.ContainerUtil) PsiLocation(com.intellij.execution.PsiLocation) SMTestLocator(com.intellij.execution.testframework.sm.runner.SMTestLocator) GoIdFilter(com.goide.stubs.index.GoIdFilter) List(java.util.List) Project(com.intellij.openapi.project.Project) Location(com.intellij.execution.Location) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) IdFilter(com.intellij.util.indexing.IdFilter) GoIdFilter(com.goide.stubs.index.GoIdFilter) GoMethodDeclaration(com.goide.psi.GoMethodDeclaration) GoTypeSpec(com.goide.psi.GoTypeSpec) PsiLocation(com.intellij.execution.PsiLocation) Location(com.intellij.execution.Location) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with IdFilter

use of com.intellij.util.indexing.IdFilter in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoIdFilter method createIdFilter.

private static IdFilter createIdFilter(@NotNull Project project, @NotNull Key<CachedValue<IdFilter>> cacheKey, @NotNull Condition<VirtualFile> filterCondition) {
    return CachedValuesManager.getManager(project).getCachedValue(project, cacheKey, () -> {
        BitSet bitSet = new BitSet();
        ContentIterator iterator = fileOrDir -> {
            if (filterCondition.value(fileOrDir)) {
                addToBitSet(bitSet, fileOrDir);
            }
            ProgressManager.checkCanceled();
            return true;
        };
        FileBasedIndex.getInstance().iterateIndexableFiles(iterator, project, null);
        return CachedValueProvider.Result.create(new GoIdFilter(bitSet), ProjectRootManager.getInstance(project), VirtualFileManager.VFS_STRUCTURE_MODIFICATIONS);
    }, false);
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) GoTestFinder(com.goide.runconfig.testing.GoTestFinder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) Key(com.intellij.openapi.util.Key) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) IdFilter(com.intellij.util.indexing.IdFilter) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) CachedValueProvider(com.intellij.psi.util.CachedValueProvider) Nullable(org.jetbrains.annotations.Nullable) CachedValue(com.intellij.psi.util.CachedValue) Project(com.intellij.openapi.project.Project) BitSet(java.util.BitSet) Logger(com.intellij.openapi.diagnostic.Logger) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) NotNull(org.jetbrains.annotations.NotNull) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) Condition(com.intellij.openapi.util.Condition) ContentIterator(com.intellij.openapi.roots.ContentIterator) BitSet(java.util.BitSet)

Example 14 with IdFilter

use of com.intellij.util.indexing.IdFilter in project intellij-community by JetBrains.

the class DomNamespaceKeyIndex method hasStubElementsWithNamespaceKey.

public boolean hasStubElementsWithNamespaceKey(final DomFileElement domFileElement, final String namespaceKey) {
    final VirtualFile file = domFileElement.getFile().getVirtualFile();
    if (!(file instanceof VirtualFileWithId))
        return false;
    final int virtualFileId = ((VirtualFileWithId) file).getId();
    CommonProcessors.FindFirstProcessor<PsiFile> processor = new CommonProcessors.FindFirstProcessor<>();
    StubIndex.getInstance().processElements(KEY, namespaceKey, domFileElement.getFile().getProject(), GlobalSearchScope.fileScope(domFileElement.getFile()), new IdFilter() {

        @Override
        public boolean containsFileId(int id) {
            return id == virtualFileId;
        }
    }, PsiFile.class, processor);
    return processor.isFound();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdFilter(com.intellij.util.indexing.IdFilter) PsiFile(com.intellij.psi.PsiFile) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) CommonProcessors(com.intellij.util.CommonProcessors)

Aggregations

IdFilter (com.intellij.util.indexing.IdFilter)14 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)10 NotNull (org.jetbrains.annotations.NotNull)8 GoIdFilter (com.goide.stubs.index.GoIdFilter)6 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 StringUtil (com.intellij.openapi.util.text.StringUtil)3 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)3 CommonProcessors (com.intellij.util.CommonProcessors)3 GoFunctionIndex (com.goide.stubs.index.GoFunctionIndex)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Module (com.intellij.openapi.module.Module)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 Condition (com.intellij.openapi.util.Condition)2 PsiElement (com.intellij.psi.PsiElement)2 MinusculeMatcher (com.intellij.psi.codeStyle.MinusculeMatcher)2 Processor (com.intellij.util.Processor)2 FindSymbolParameters (com.intellij.util.indexing.FindSymbolParameters)2 THashSet (gnu.trove.THashSet)2 GoConstants (com.goide.GoConstants)1