@NotNull @Override public SearchScope getUseScope() { return GlobalSearchScope.allScope(getProject()); }
private PsiClass getPsiClassByName(Project project, String cls) { GlobalSearchScope searchScope = GlobalSearchScope.allScope(project); JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project); return javaPsiFacade.findClass(cls, searchScope); }
@Nullable private VirtualFile findSingleFile(@NotNull String fileName) { if (PathUtil.isValidFileName(fileName)) { Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(myProject, fileName, GlobalSearchScope.allScope(myProject)); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } } return null; }
@Override public ResolveResult[] resolve(@NotNull Project project) { GlobalSearchScope scope = GlobalSearchScope.allScope(project); return indexedNameStream(project) .filter(predicate) .flatMap(name -> namedElementCollection(project, scope, name) .stream() .map(PsiElement::getNavigationElement) .map(navigationElement -> (ResolveResult) new PsiElementResolveResult(navigationElement, false) ) ).toArray(ResolveResult[]::new); } }
public static Collection<NamedElement> namedElementCollection(@NotNull Project project, @NotNull GlobalSearchScope scope, @NotNull String name) { Collection<NamedElement> namedElementCollection; if (DumbService.isDumb(project)) { namedElementCollection = Collections.emptyList(); } else { namedElementCollection = StubIndex.getElements( AllName.KEY, name, project, scope, NamedElement.class ); } return namedElementCollection; } }
@Nullable private VirtualFile findSingleFile(@NotNull String fileName) { if (PathUtil.isValidFileName(fileName)) { Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(myProject, fileName, GlobalSearchScope.allScope(myProject)); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } if (!files.isEmpty()) { GlobalSearchScope goPathScope = GoPathResolveScope.create(myProject, myModule, null); files = ContainerUtil.filter(files, goPathScope::accept); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } } if (!files.isEmpty()) { GlobalSearchScope smallerScope = GoUtil.moduleScopeWithoutLibraries(myProject, myModule); files = ContainerUtil.filter(files, smallerScope::accept); if (files.size() == 1) { return ContainerUtil.getFirstItem(files); } } } return null; }
@Override public void annotate(@NotNull PsiElement psiElement, @NotNull com.intellij.lang.annotation.AnnotationHolder annotationHolder) { if (psiElement instanceof ErlangAtom) { ErlangAtom erlangAtom = (ErlangAtom) psiElement; String name = erlangAtom.getName(); if (name.startsWith(ELIXIR_ALIAS_PREFIX)) { Project project = psiElement.getProject(); Collection<NamedElement> namedElementCollection = StubIndex.getElements( ModularName.KEY, name, project, GlobalSearchScope.allScope(project), NamedElement.class ); if (namedElementCollection.size() > 0) { TextRange textRange = psiElement.getTextRange(); String unprefixedName = name.substring(ELIXIR_ALIAS_PREFIX.length(), name.length()); Annotation annotation = annotationHolder.createInfoAnnotation(textRange, "Resolves to Elixir Module " + unprefixedName); annotation.setTextAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT); } else { TextRange textRange = psiElement.getTextRange(); annotationHolder.createErrorAnnotation(textRange, "Unresolved Elixir Module"); } } } } }
private List<LookupElement> projectLookupElementStream(@NotNull PsiElement entrance) { Project project = entrance.getProject(); /* getAllKeys is not the actual keys in the actual project. They need to be checked. See https://intellij-support.jetbrains.com/hc/en-us/community/posts/207930789-StubIndex-persisting-between-test-runs-leading-to-incorrect-completions */ Collection<String> indexedNameCollection = StubIndex.getInstance().getAllKeys(AllName.KEY, project); GlobalSearchScope scope = GlobalSearchScope.allScope(project); Collection<String> atomNameCollection = atomNameCollection(indexedNameCollection); String prefix = prefix(entrance); Collection<String> prefixedNameCollection = prefixedNameCollection(atomNameCollection, prefix); List<LookupElement> lookupElementList = new ArrayList<>(); for (String atomName : prefixedNameCollection) { Collection<NamedElement> atomNamedElementCollection = StubIndex.getElements( AllName.KEY, atomName, project, scope, NamedElement.class ); for (NamedElement atomNamedElement : atomNamedElementCollection) { PsiElement navigationElement = atomNamedElement.getNavigationElement(); lookupElementList.add( LookupElementBuilder.createWithSmartPointer(atomName, navigationElement) ); } } return lookupElementList; }
@Override public void computeTypeSourcePosition(@NotNull XNavigatable navigatable) { readActionInPooledThread(() -> { boolean isStructure = myVariable.isStructure(); boolean isPtr = myVariable.isPtr(); if (!isStructure && !isPtr) return; Project project = getProject(); if (project == null) return; String dlvType = myVariable.type; String fqn = dlvType.replaceFirst(isPtr ? "\\*struct " : "struct ", ""); List<String> split = StringUtil.split(fqn, "."); boolean noFqn = split.size() == 1; if (split.size() == 2 || noFqn) { String name = ContainerUtil.getLastItem(split); assert name != null; Collection<GoTypeSpec> types = GoTypesIndex.find(name, project, GlobalSearchScope.allScope(project), null); for (GoTypeSpec type : types) { if (noFqn || Comparing.equal(fqn, type.getQualifiedName())) { navigatable.setSourcePosition(XDebuggerUtil.getInstance().createPositionByOffset( type.getContainingFile().getVirtualFile(), type.getTextOffset())); return; } } } }); } }
public static GlobalSearchScope create(@NotNull PsiElement declarationContext, boolean filterByImportList) { if (declarationContext instanceof GoNamedElement && ((GoNamedElement)declarationContext).isBlank()) { return GlobalSearchScope.EMPTY_SCOPE; } PsiFile declarationPsiFile = declarationContext.getContainingFile(); if (!(declarationPsiFile instanceof GoFile)) { return GlobalSearchScope.fileScope(declarationPsiFile); } if (GoPsiImplUtil.isBuiltinFile(declarationPsiFile)) { return GlobalSearchScope.allScope(declarationContext.getProject()); } VirtualFile declarationFile = declarationPsiFile.getVirtualFile(); if (declarationFile == null || declarationFile.getParent() == null) { return GlobalSearchScope.fileScope(declarationPsiFile); } return new GoPathUseScope(declarationPsiFile.getProject(), declarationFile, filterByImportList); }
@NotNull public Set<String> getResult() { return stringSet.stream() .filter( s -> FileBasedIndex.getInstance().getContainingFiles(id, s, GlobalSearchScope.allScope(project)).size() > 0 ) .collect(Collectors.toSet() ); } }
private Set<String> getPartialOpenApiFilesWithTypeInfo(final Project project) { final FileBasedIndex index = FileBasedIndex.getInstance(); return index .getValues( OpenApiFileIndex.OPEN_API_INDEX_ID, OpenApiFileIndex.PARTIAL_OPEN_API_FILES, GlobalSearchScope.allScope(project)) .stream() .flatMap(Set::stream) .collect(Collectors.toSet()); }
private Set<String> getPartialSwaggerFilesWithTypeInfo(final Project project) { final FileBasedIndex index = FileBasedIndex.getInstance(); return index .getValues( SwaggerFileIndex.SWAGGER_INDEX_ID, SwaggerFileIndex.PARTIAL_SWAGGER_FILES, GlobalSearchScope.allScope(project)) .stream() .flatMap(Set::stream) .collect(Collectors.toSet()); }
private static VirtualFile[] findServiceDefinitionFiles(@NotNull Project project, @NotNull String serviceName) { final List<VirtualFile> virtualFiles = new ArrayList<>(); FileBasedIndex.getInstance().getFilesWithKey(ServicesDefinitionStubIndex.KEY, new HashSet<>(Collections.singletonList(serviceName.toLowerCase())), virtualFile -> { virtualFiles.add(virtualFile); return true; }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), XmlFileType.INSTANCE, YAMLFileType.YML)); return virtualFiles.toArray(new VirtualFile[virtualFiles.size()]); }
public boolean isMainOpenApiFile(final VirtualFile virtualFile, final Project project) { final FileBasedIndex index = FileBasedIndex.getInstance(); final Collection<VirtualFile> openApiFiles = index.getContainingFiles( OpenApiFileIndex.OPEN_API_INDEX_ID, OpenApiFileIndex.MAIN_OPEN_API_FILE, GlobalSearchScope.allScope(project)); return openApiFiles.contains(virtualFile); }
private Collection<VirtualFile> getImplements(TwigFile twigFile) { final Set<VirtualFile> targets = new HashSet<>(); for(String templateName: TwigUtil.getTemplateNamesForFile(twigFile)) { FileBasedIndex.getInstance().getFilesWithKey(TwigIncludeStubIndex.KEY, new HashSet<>(Collections.singletonList(templateName)), virtualFile -> { targets.add(virtualFile); return true; }, GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(twigFile.getProject()), TwigFileType.INSTANCE)); } return targets; }
@NotNull private Set<String> getDomainKeys(@NotNull String domain) { Set<String> uniqueKeySet = new ArrayListSet<String>(); for(Set<String> splits: FileBasedIndex.getInstance().getValues(TranslationStubIndex.KEY, domain, GlobalSearchScope.allScope(getProject()))) { ContainerUtil.addAll(uniqueKeySet, splits); } return uniqueKeySet; } }
public void testIndexValue() { FileResource item = ContainerUtil.getFirstItem(FileBasedIndex.getInstance().getValues(FileResourcesIndex.KEY, "@AppBundle/Controller", GlobalSearchScope.allScope(getProject()))); assertEquals("/foo", item.getPrefix()); item = ContainerUtil.getFirstItem(FileBasedIndex.getInstance().getValues(FileResourcesIndex.KEY, "@AcmeOtherBundle/Resources/config/routing.xml", GlobalSearchScope.allScope(getProject()))); assertEquals("/foo2", item.getPrefix()); } }
public void testInstanceExtractionOfDocComment() { assertIndexContains(EventAnnotationStubIndex.KEY, "form.pre_bind"); DispatcherEvent event = ContainerUtil.getFirstItem(FileBasedIndex.getInstance().getValues( EventAnnotationStubIndex.KEY, "form.pre_bind", GlobalSearchScope.allScope(getProject())) ); assertEquals("Symfony\\Component\\Form\\FormEvents.PRE_SUBMIT", event.getFqn()); assertEquals("Symfony\\Component\\Form\\FormEvent", event.getInstance()); }
public void testInstanceExtractionOfDocTag() { assertIndexContains(EventAnnotationStubIndex.KEY, "form.post_bind"); DispatcherEvent event = ContainerUtil.getFirstItem(FileBasedIndex.getInstance().getValues( EventAnnotationStubIndex.KEY, "form.post_bind", GlobalSearchScope.allScope(getProject())) ); assertEquals("Symfony\\Component\\Form\\FormEvents.POST_SUBMIT", event.getFqn()); assertEquals("Foo\\Bar", event.getInstance()); } }