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;
}
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);
}
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);
}
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();
}
Aggregations