Search in sources :

Example 16 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 17 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)

Example 18 with GlobalSearchScope

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

the class GotoSymbolContributor method getItemsByName.

/*
     * Instance Methods
     */
/**
     * Returns the list of navigation items matching the specified name.
     *
     * @param name                   the name selected from the list.
     * @param pattern                the original pattern entered in the dialog
     * @param project                the project in which the navigation is performed.
     * @param includeNonProjectItems if true, the navigation items for non-project items (for example,
     *                               library classes) should be included in the returned array.
     * @return the array of navigation items.
     */
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
    GlobalSearchScope scope = globalSearchScope(project, includeNonProjectItems);
    Collection<NamedElement> result = StubIndex.getElements(AllName.KEY, name, project, scope, NamedElement.class);
    List<NavigationItem> items = ContainerUtil.newArrayListWithCapacity(result.size());
    EnclosingModularByCall enclosingModularByCall = new EnclosingModularByCall();
    Map<CallDefinition.Tuple, CallDefinition> callDefinitionByTuple = new HashMap<CallDefinition.Tuple, CallDefinition>();
    for (final NamedElement element : result) {
        // Use navigation element so that source element is used for compiled elements
        PsiElement sourceElement = element.getNavigationElement();
        if (sourceElement instanceof Call) {
            getItemsByNameFromCall(name, items, enclosingModularByCall, callDefinitionByTuple, (Call) sourceElement);
        }
    }
    return items.toArray(new NavigationItem[items.size()]);
}
Also used : Call(org.elixir_lang.psi.call.Call) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) NavigationItem(com.intellij.navigation.NavigationItem) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HashMap(java.util.HashMap) NamedElement(org.elixir_lang.psi.NamedElement) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with GlobalSearchScope

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

the class ElixirPsiImplUtil method moduleWithDependentsScope.

private static GlobalSearchScope moduleWithDependentsScope(PsiElement element) {
    VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
    Project project = element.getProject();
    com.intellij.openapi.module.Module module = ModuleUtilCore.findModuleForFile(virtualFile, project);
    GlobalSearchScope globalSearchScope;
    // module can be null for scratch files
    if (module != null) {
        globalSearchScope = GlobalSearchScope.moduleWithDependentsScope(module);
    } else {
        globalSearchScope = GlobalSearchScope.allScope(project);
    }
    return globalSearchScope;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Example 20 with GlobalSearchScope

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

the class FileReferenceFilter method resolveAbsolutePath.

@Nullable
private VirtualFile resolveAbsolutePath(@NotNull String path) {
    VirtualFile asIsFile = pathToVirtualFile(path);
    if (asIsFile != null) {
        return asIsFile;
    }
    String projectBasedPath = path.startsWith(myProject.getBasePath()) ? path : new File(myProject.getBasePath(), path).getAbsolutePath();
    VirtualFile projectBasedFile = pathToVirtualFile(projectBasedPath);
    if (projectBasedFile != null) {
        return projectBasedFile;
    }
    Matcher filenameMatcher = PATTERN_FILENAME.matcher(path);
    if (filenameMatcher.find()) {
        String filename = filenameMatcher.group(1);
        GlobalSearchScope projectScope = ProjectScope.getProjectScope(myProject);
        PsiFile[] projectFiles = FilenameIndex.getFilesByName(myProject, filename, projectScope);
        if (projectFiles.length > 0) {
            return projectFiles[0].getVirtualFile();
        }
        GlobalSearchScope libraryScope = ProjectScope.getLibrariesScope(myProject);
        PsiFile[] libraryFiles = FilenameIndex.getFilesByName(myProject, filename, libraryScope);
        if (libraryFiles.length > 0) {
            return libraryFiles[0].getVirtualFile();
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Matcher(java.util.regex.Matcher) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiFile(com.intellij.psi.PsiFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

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