Search in sources :

Example 66 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.

the class CodeFragmentFactoryContextWrapper method prepareResolveScope.

private static JavaCodeFragment prepareResolveScope(JavaCodeFragment codeFragment) {
    GlobalSearchScope originalResolveScope = codeFragment.getResolveScope();
    codeFragment.forceResolveScope(new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(codeFragment.getProject())) {

        final Comparator<VirtualFile> myScopeComparator = Comparator.comparing(originalResolveScope::contains).thenComparing(super::compare);

        @Override
        public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
            // prefer files from the original resolve scope
            return myScopeComparator.compare(file1, file2);
        }
    });
    return codeFragment;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DelegatingGlobalSearchScope(com.intellij.psi.search.DelegatingGlobalSearchScope) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) DelegatingGlobalSearchScope(com.intellij.psi.search.DelegatingGlobalSearchScope)

Example 67 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.

the class CompilerReferenceReader method getDirectInheritors.

/**
   * @return two maps of classes grouped per file
   *
   * 1st map: inheritors. Can be used without explicit inheritance verification
   * 2nd map: candidates. One need to check that these classes are really direct inheritors
   */
@NotNull
Map<VirtualFile, Object[]> getDirectInheritors(@NotNull LightRef searchElement, @NotNull GlobalSearchScope searchScope, @NotNull GlobalSearchScope dirtyScope, @NotNull FileType fileType, @NotNull CompilerHierarchySearchType searchType) throws StorageException {
    GlobalSearchScope effectiveSearchScope = GlobalSearchScope.notScope(dirtyScope).intersectWith(searchScope);
    LanguageLightRefAdapter adapter = CompilerReferenceServiceImpl.findAdapterForFileType(fileType);
    LOG.assertTrue(adapter != null, "adapter is null for file type: " + fileType);
    Class<? extends LightRef> requiredLightRefClass = searchType.getRequiredClass(adapter);
    Map<VirtualFile, Object[]> candidatesPerFile = new HashMap<>();
    myIndex.get(CompilerIndices.BACK_HIERARCHY).getData(searchElement).forEach((fileId, defs) -> {
        final List<LightRef> requiredCandidates = defs.stream().filter(requiredLightRefClass::isInstance).collect(toList());
        if (requiredCandidates.isEmpty())
            return true;
        final VirtualFile file = findFile(fileId);
        if (file != null && effectiveSearchScope.contains(file)) {
            candidatesPerFile.put(file, searchType.convertToIds(requiredCandidates, myIndex.getByteSeqEum()));
        }
        return true;
    });
    return candidatesPerFile.isEmpty() ? Collections.emptyMap() : candidatesPerFile;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) LightRef(org.jetbrains.jps.backwardRefs.LightRef) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-community by JetBrains.

the class CompilerReferenceServiceImpl method getHierarchyInfo.

@Nullable
private CompilerHierarchyInfoImpl getHierarchyInfo(@NotNull PsiNamedElement aClass, @NotNull GlobalSearchScope useScope, @NotNull GlobalSearchScope searchScope, @NotNull FileType searchFileType, @NotNull CompilerHierarchySearchType searchType) {
    if (!isServiceEnabledFor(aClass) || searchScope == LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope())
        return null;
    try {
        Map<VirtualFile, Object[]> candidatesPerFile = ReadAction.compute(() -> {
            if (myProject.isDisposed())
                throw new ProcessCanceledException();
            return CachedValuesManager.getCachedValue(aClass, () -> CachedValueProvider.Result.create(new ConcurrentFactoryMap<HierarchySearchKey, Map<VirtualFile, Object[]>>() {

                @Nullable
                @Override
                protected Map<VirtualFile, Object[]> create(HierarchySearchKey key) {
                    return calculateDirectInheritors(aClass, useScope, key.mySearchFileType, key.mySearchType);
                }
            }, PsiModificationTracker.MODIFICATION_COUNT, this)).get(new HierarchySearchKey(searchType, searchFileType));
        });
        if (candidatesPerFile == null)
            return null;
        GlobalSearchScope dirtyScope = myDirtyScopeHolder.getDirtyScope();
        if (ElementPlace.LIB == ReadAction.compute(() -> ElementPlace.get(aClass.getContainingFile().getVirtualFile(), myProjectFileIndex))) {
            dirtyScope = dirtyScope.union(LibraryScopeCache.getInstance(myProject).getLibrariesOnlyScope());
        }
        return new CompilerHierarchyInfoImpl(candidatesPerFile, aClass, dirtyScope, searchScope, myProject, searchFileType, searchType);
    } catch (ProcessCanceledException e) {
        throw e;
    } catch (RuntimeException e) {
        return onException(e, "hierarchy");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ConcurrentFactoryMap(com.intellij.util.containers.ConcurrentFactoryMap) Nullable(org.jetbrains.annotations.Nullable) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Nullable(org.jetbrains.annotations.Nullable)

Example 69 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.

the class Variants method executeOnAliasedName.

/*
     * Protected Instance Methods
     */
/**
     * Decides whether {@code match} matches the criteria being searched for.  All other {@link #execute} methods
     * eventually end here.
     *
     * @param match
     * @param aliasedName
     * @param state
     * @return {@code true} to keep processing; {@code false} to stop processing.
     */
@Override
protected boolean executeOnAliasedName(@NotNull PsiNamedElement match, @NotNull final String aliasedName, @NotNull ResolveState state) {
    if (lookupElementList == null) {
        lookupElementList = new ArrayList<LookupElement>();
    }
    lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedName, match));
    String unaliasedName = UnaliasedName.unaliasedName(match);
    if (unaliasedName != null) {
        Project project = match.getProject();
        Collection<String> indexedNameCollection = StubIndex.getInstance().getAllKeys(AllName.KEY, project);
        List<String> unaliasedNestedNames = ContainerUtil.findAll(indexedNameCollection, new org.elixir_lang.Module.IsNestedUnder(unaliasedName));
        if (unaliasedNestedNames.size() > 0) {
            GlobalSearchScope scope = GlobalSearchScope.allScope(project);
            for (String unaliasedNestedName : unaliasedNestedNames) {
                Collection<NamedElement> unaliasedNestedNamedElementCollection = StubIndex.getElements(AllName.KEY, unaliasedNestedName, project, scope, NamedElement.class);
                if (unaliasedNestedNamedElementCollection.size() > 0) {
                    List<String> unaliasedNestedNamePartList = split(unaliasedNestedName);
                    List<String> unaliasedNamePartList = split(unaliasedName);
                    List<String> aliasedNamePartList = split(aliasedName);
                    List<String> aliasedNestedNamePartList = new ArrayList<String>();
                    aliasedNestedNamePartList.addAll(aliasedNamePartList);
                    for (int i = unaliasedNamePartList.size(); i < unaliasedNestedNamePartList.size(); i++) {
                        aliasedNestedNamePartList.add(unaliasedNestedNamePartList.get(i));
                    }
                    String aliasedNestedName = concat(aliasedNestedNamePartList);
                    for (NamedElement unaliasedNestedNamedElement : unaliasedNestedNamedElementCollection) {
                        lookupElementList.add(LookupElementBuilder.createWithSmartPointer(aliasedNestedName, unaliasedNestedNamedElement));
                    }
                }
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) LookupElement(com.intellij.codeInsight.lookup.LookupElement) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(org.elixir_lang.psi.scope.Module) PsiNamedElement(com.intellij.psi.PsiNamedElement)

Example 70 with GlobalSearchScope

use of com.intellij.psi.search.GlobalSearchScope in project intellij-elixir by KronicDeth.

the class Variants method addProjectNameElementsTo.

/*
     * Private Instance Methods
     */
private void addProjectNameElementsTo(List<LookupElement> lookupElementList, 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> aliasNameCollection = filterIndexedNameCollection(indexedNameCollection);
    String prefix = indexedNamePrefix(multipleAliases);
    Collection<String> prefixedNameCollection = filterIndexedNameCollection(aliasNameCollection, prefix);
    for (String prefixedName : prefixedNameCollection) {
        Collection<NamedElement> prefixedNameNamedElementCollection = StubIndex.getElements(AllName.KEY, prefixedName, project, scope, NamedElement.class);
        String lookupName = lookupName(prefixedName, prefix);
        for (NamedElement prefixedNameNamedElement : prefixedNameNamedElementCollection) {
            /* Generalizes over whether the prefixedNameNamedElement is a source element or a compiled element as
                   the navigation element is defined to be always be a source element */
            PsiElement navigationElement = prefixedNameNamedElement.getNavigationElement();
            lookupElementList.add(LookupElementBuilder.createWithSmartPointer(lookupName, navigationElement));
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiNamedElement(com.intellij.psi.PsiNamedElement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)485 Project (com.intellij.openapi.project.Project)145 NotNull (org.jetbrains.annotations.NotNull)134 VirtualFile (com.intellij.openapi.vfs.VirtualFile)106 Module (com.intellij.openapi.module.Module)101 Nullable (org.jetbrains.annotations.Nullable)78 PsiClass (com.intellij.psi.PsiClass)53 ArrayList (java.util.ArrayList)37 PsiFile (com.intellij.psi.PsiFile)32 PsiElement (com.intellij.psi.PsiElement)31 THashSet (gnu.trove.THashSet)22 SearchScope (com.intellij.psi.search.SearchScope)19 PsiDirectory (com.intellij.psi.PsiDirectory)18 ContainerUtil (com.intellij.util.containers.ContainerUtil)18 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)17 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)17 com.intellij.psi (com.intellij.psi)17 List (java.util.List)17 StringUtil (com.intellij.openapi.util.text.StringUtil)15 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)15